답안 #495987

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
495987 2021-12-20T09:58:39 Z mansur Birthday gift (IZhO18_treearray) C++14
100 / 100
1102 ms 88488 KB
#include<bits/stdc++.h>	
 
#pragma optimize ("g",on)
#pragma GCC optimize ("inline")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("03")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx2,mmx,fma,avx,tune=native")
#pragma comment(linker, "/stack:200000000")

//01001101 01100001 01101011 01101000 01100001  01100111 01100001 01111001 

using namespace std;

#define all(a) a.begin(), a.end()                                                   
#define rall(a) a.rbegin(), a.rend()
#define ll long long
#define pb push_back
#define sz(a) a.size()
#define nl '\n'
#define popb pop_back()                                                                   
#define ld double
#define ull unsigned long long
#define ff first                                         
#define ss second  
#define fix fixed << setprecision
#define pii pair<int, int>                          
#define E exit (0)
 
const int inf = 1e9, N = 1e6 + 1, mod = 998244353;                    

vector<pii> dir = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

int tin[N], tout[N], timer;

int up[N][18];

vector<int> adj[N];

void dfs(int u, int p) {
	tin[u] = timer++;
	up[u][0] = p;
	for (int i = 1; i < 18; i++) up[u][i] = up[up[u][i - 1]][i - 1];
	for (auto e: adj[u]) {
		if (e != p) dfs(e, u);
	}
	tout[u] = timer;
}

bool is(int a, int b) {
	return tin[a] <= tin[b] && tout[a] >= tout[b];
}

int lca(int u, int v) {
	if (is(u, v)) return u;
	if (is(v, u)) return v;
	for (int i = 17; i >= 0; i--) {
		int x = up[u][i];
		if (is(x, v)) continue;
		u = x;
	}
	return up[u][0];
}

main() {                                                         
	//freopen("cowrect.in", "r", stdin);                                                                                     
	//freopen("cowrect.out", "w", stdout);                                                                                     
	ios_base::sync_with_stdio(NULL);                                                                                        
	cin.tie(NULL);
	int n, m, q;
	cin >> n >> m >> q;
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	dfs(1, 1);
	int a[m + 1];
	vector<set<pii>> s(n + 1);
	for (int i = 1; i <= m; i++) {
		cin >> a[i];
		s[a[i]].insert({i, i});
		if (i > 1) {
			int lc = lca(a[i], a[i - 1]);
			s[lc].insert({i - 1, i});
		}
	}
	while (q--) {
	 	int t;
	 	cin >> t;
	 	if (t == 1) {
	 	 	int pos, v;
	 	 	cin >> pos >> v;
	 	 	s[a[pos]].erase({pos, pos});
	 	 	s[v].insert({pos, pos});
	 	 	if (pos > 1) {
	 	 		int lc = lca(a[pos], a[pos - 1]);
	 	 		s[lc].erase({pos - 1, pos});
	 	 		lc = lca(v, a[pos - 1]);
	 	 		s[lc].insert({pos - 1, pos});
	 	 	}
	 	 	if (pos < m) {
	 	 		int lc = lca(a[pos], a[pos + 1]);
	 	 		s[lc].erase({pos, pos + 1});
	 	 		lc = lca(v, a[pos + 1]);
	 	 		s[lc].insert({pos, pos + 1});	
	 	 	}
	 	 	a[pos] = v;
	 	}else {
	 	 	int l, r, v;
	 	 	cin >> l >> r >> v;
	 	 	auto it = s[v].lower_bound({l, l});
	 	 	if (it == s[v].end() || (*it).ss > r) cout << -1 << ' ' << -1 << nl;
	 	 	else cout << (*it).ff << ' ' << (*it).ss << nl;
	 	}
	}
}

Compilation message

treearray.cpp:3: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    3 | #pragma optimize ("g",on)
      | 
treearray.cpp:9: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
    9 | #pragma comment(linker, "/stack:200000000")
      | 
treearray.cpp:65:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   65 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23756 KB n=5
2 Correct 14 ms 23756 KB n=100
3 Correct 13 ms 23756 KB n=100
4 Correct 14 ms 23716 KB n=100
5 Correct 15 ms 23780 KB n=100
6 Correct 16 ms 23756 KB n=100
7 Correct 15 ms 23804 KB n=100
8 Correct 12 ms 23756 KB n=100
9 Correct 16 ms 23804 KB n=100
10 Correct 14 ms 23756 KB n=100
11 Correct 13 ms 23756 KB n=100
12 Correct 14 ms 23756 KB n=100
13 Correct 12 ms 23844 KB n=100
14 Correct 12 ms 23756 KB n=100
15 Correct 14 ms 23824 KB n=100
16 Correct 15 ms 23756 KB n=100
17 Correct 16 ms 23756 KB n=100
18 Correct 12 ms 23756 KB n=100
19 Correct 13 ms 23836 KB n=100
20 Correct 13 ms 23756 KB n=100
21 Correct 14 ms 23716 KB n=100
22 Correct 12 ms 23756 KB n=100
23 Correct 16 ms 23756 KB n=100
24 Correct 13 ms 23756 KB n=100
25 Correct 14 ms 23716 KB n=100
26 Correct 13 ms 23748 KB n=12
27 Correct 16 ms 23756 KB n=100
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23756 KB n=5
2 Correct 14 ms 23756 KB n=100
3 Correct 13 ms 23756 KB n=100
4 Correct 14 ms 23716 KB n=100
5 Correct 15 ms 23780 KB n=100
6 Correct 16 ms 23756 KB n=100
7 Correct 15 ms 23804 KB n=100
8 Correct 12 ms 23756 KB n=100
9 Correct 16 ms 23804 KB n=100
10 Correct 14 ms 23756 KB n=100
11 Correct 13 ms 23756 KB n=100
12 Correct 14 ms 23756 KB n=100
13 Correct 12 ms 23844 KB n=100
14 Correct 12 ms 23756 KB n=100
15 Correct 14 ms 23824 KB n=100
16 Correct 15 ms 23756 KB n=100
17 Correct 16 ms 23756 KB n=100
18 Correct 12 ms 23756 KB n=100
19 Correct 13 ms 23836 KB n=100
20 Correct 13 ms 23756 KB n=100
21 Correct 14 ms 23716 KB n=100
22 Correct 12 ms 23756 KB n=100
23 Correct 16 ms 23756 KB n=100
24 Correct 13 ms 23756 KB n=100
25 Correct 14 ms 23716 KB n=100
26 Correct 13 ms 23748 KB n=12
27 Correct 16 ms 23756 KB n=100
28 Correct 18 ms 23956 KB n=500
29 Correct 13 ms 23976 KB n=500
30 Correct 13 ms 23956 KB n=500
31 Correct 15 ms 23864 KB n=500
32 Correct 14 ms 23904 KB n=500
33 Correct 14 ms 23884 KB n=500
34 Correct 15 ms 23948 KB n=500
35 Correct 13 ms 23884 KB n=500
36 Correct 15 ms 23952 KB n=500
37 Correct 14 ms 23868 KB n=500
38 Correct 13 ms 23884 KB n=500
39 Correct 14 ms 23920 KB n=500
40 Correct 13 ms 23884 KB n=500
41 Correct 14 ms 24016 KB n=500
42 Correct 16 ms 23840 KB n=500
43 Correct 15 ms 23928 KB n=500
44 Correct 15 ms 23944 KB n=500
45 Correct 19 ms 23884 KB n=500
46 Correct 13 ms 23968 KB n=500
47 Correct 13 ms 23876 KB n=500
48 Correct 14 ms 23884 KB n=500
49 Correct 13 ms 23960 KB n=500
50 Correct 14 ms 23884 KB n=500
51 Correct 13 ms 23884 KB n=500
52 Correct 16 ms 23940 KB n=500
53 Correct 13 ms 23940 KB n=500
54 Correct 14 ms 23884 KB n=500
55 Correct 12 ms 23908 KB n=278
56 Correct 14 ms 23884 KB n=500
57 Correct 14 ms 23884 KB n=500
58 Correct 14 ms 23956 KB n=500
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23756 KB n=5
2 Correct 14 ms 23756 KB n=100
3 Correct 13 ms 23756 KB n=100
4 Correct 14 ms 23716 KB n=100
5 Correct 15 ms 23780 KB n=100
6 Correct 16 ms 23756 KB n=100
7 Correct 15 ms 23804 KB n=100
8 Correct 12 ms 23756 KB n=100
9 Correct 16 ms 23804 KB n=100
10 Correct 14 ms 23756 KB n=100
11 Correct 13 ms 23756 KB n=100
12 Correct 14 ms 23756 KB n=100
13 Correct 12 ms 23844 KB n=100
14 Correct 12 ms 23756 KB n=100
15 Correct 14 ms 23824 KB n=100
16 Correct 15 ms 23756 KB n=100
17 Correct 16 ms 23756 KB n=100
18 Correct 12 ms 23756 KB n=100
19 Correct 13 ms 23836 KB n=100
20 Correct 13 ms 23756 KB n=100
21 Correct 14 ms 23716 KB n=100
22 Correct 12 ms 23756 KB n=100
23 Correct 16 ms 23756 KB n=100
24 Correct 13 ms 23756 KB n=100
25 Correct 14 ms 23716 KB n=100
26 Correct 13 ms 23748 KB n=12
27 Correct 16 ms 23756 KB n=100
28 Correct 18 ms 23956 KB n=500
29 Correct 13 ms 23976 KB n=500
30 Correct 13 ms 23956 KB n=500
31 Correct 15 ms 23864 KB n=500
32 Correct 14 ms 23904 KB n=500
33 Correct 14 ms 23884 KB n=500
34 Correct 15 ms 23948 KB n=500
35 Correct 13 ms 23884 KB n=500
36 Correct 15 ms 23952 KB n=500
37 Correct 14 ms 23868 KB n=500
38 Correct 13 ms 23884 KB n=500
39 Correct 14 ms 23920 KB n=500
40 Correct 13 ms 23884 KB n=500
41 Correct 14 ms 24016 KB n=500
42 Correct 16 ms 23840 KB n=500
43 Correct 15 ms 23928 KB n=500
44 Correct 15 ms 23944 KB n=500
45 Correct 19 ms 23884 KB n=500
46 Correct 13 ms 23968 KB n=500
47 Correct 13 ms 23876 KB n=500
48 Correct 14 ms 23884 KB n=500
49 Correct 13 ms 23960 KB n=500
50 Correct 14 ms 23884 KB n=500
51 Correct 13 ms 23884 KB n=500
52 Correct 16 ms 23940 KB n=500
53 Correct 13 ms 23940 KB n=500
54 Correct 14 ms 23884 KB n=500
55 Correct 12 ms 23908 KB n=278
56 Correct 14 ms 23884 KB n=500
57 Correct 14 ms 23884 KB n=500
58 Correct 14 ms 23956 KB n=500
59 Correct 20 ms 24268 KB n=2000
60 Correct 20 ms 24396 KB n=2000
61 Correct 15 ms 24324 KB n=2000
62 Correct 15 ms 24264 KB n=2000
63 Correct 16 ms 24268 KB n=2000
64 Correct 15 ms 24268 KB n=2000
65 Correct 17 ms 24268 KB n=2000
66 Correct 16 ms 24396 KB n=2000
67 Correct 17 ms 24328 KB n=2000
68 Correct 19 ms 24268 KB n=2000
69 Correct 19 ms 24484 KB n=2000
70 Correct 15 ms 24300 KB n=2000
71 Correct 16 ms 24268 KB n=2000
72 Correct 20 ms 24268 KB n=2000
73 Correct 16 ms 24236 KB n=2000
74 Correct 17 ms 24280 KB n=1844
75 Correct 16 ms 24256 KB n=2000
76 Correct 17 ms 24268 KB n=2000
77 Correct 17 ms 24288 KB n=2000
78 Correct 18 ms 24320 KB n=2000
79 Correct 18 ms 24332 KB n=2000
80 Correct 15 ms 24396 KB n=2000
81 Correct 20 ms 24268 KB n=2000
82 Correct 16 ms 24268 KB n=2000
83 Correct 18 ms 24412 KB n=2000
84 Correct 20 ms 24268 KB n=2000
85 Correct 16 ms 24364 KB n=2000
86 Correct 15 ms 24268 KB n=2000
87 Correct 18 ms 24336 KB n=2000
88 Correct 15 ms 24348 KB n=2000
89 Correct 15 ms 24444 KB n=2000
90 Correct 17 ms 24448 KB n=2000
91 Correct 16 ms 24268 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23756 KB n=5
2 Correct 14 ms 23756 KB n=100
3 Correct 13 ms 23756 KB n=100
4 Correct 14 ms 23716 KB n=100
5 Correct 15 ms 23780 KB n=100
6 Correct 16 ms 23756 KB n=100
7 Correct 15 ms 23804 KB n=100
8 Correct 12 ms 23756 KB n=100
9 Correct 16 ms 23804 KB n=100
10 Correct 14 ms 23756 KB n=100
11 Correct 13 ms 23756 KB n=100
12 Correct 14 ms 23756 KB n=100
13 Correct 12 ms 23844 KB n=100
14 Correct 12 ms 23756 KB n=100
15 Correct 14 ms 23824 KB n=100
16 Correct 15 ms 23756 KB n=100
17 Correct 16 ms 23756 KB n=100
18 Correct 12 ms 23756 KB n=100
19 Correct 13 ms 23836 KB n=100
20 Correct 13 ms 23756 KB n=100
21 Correct 14 ms 23716 KB n=100
22 Correct 12 ms 23756 KB n=100
23 Correct 16 ms 23756 KB n=100
24 Correct 13 ms 23756 KB n=100
25 Correct 14 ms 23716 KB n=100
26 Correct 13 ms 23748 KB n=12
27 Correct 16 ms 23756 KB n=100
28 Correct 18 ms 23956 KB n=500
29 Correct 13 ms 23976 KB n=500
30 Correct 13 ms 23956 KB n=500
31 Correct 15 ms 23864 KB n=500
32 Correct 14 ms 23904 KB n=500
33 Correct 14 ms 23884 KB n=500
34 Correct 15 ms 23948 KB n=500
35 Correct 13 ms 23884 KB n=500
36 Correct 15 ms 23952 KB n=500
37 Correct 14 ms 23868 KB n=500
38 Correct 13 ms 23884 KB n=500
39 Correct 14 ms 23920 KB n=500
40 Correct 13 ms 23884 KB n=500
41 Correct 14 ms 24016 KB n=500
42 Correct 16 ms 23840 KB n=500
43 Correct 15 ms 23928 KB n=500
44 Correct 15 ms 23944 KB n=500
45 Correct 19 ms 23884 KB n=500
46 Correct 13 ms 23968 KB n=500
47 Correct 13 ms 23876 KB n=500
48 Correct 14 ms 23884 KB n=500
49 Correct 13 ms 23960 KB n=500
50 Correct 14 ms 23884 KB n=500
51 Correct 13 ms 23884 KB n=500
52 Correct 16 ms 23940 KB n=500
53 Correct 13 ms 23940 KB n=500
54 Correct 14 ms 23884 KB n=500
55 Correct 12 ms 23908 KB n=278
56 Correct 14 ms 23884 KB n=500
57 Correct 14 ms 23884 KB n=500
58 Correct 14 ms 23956 KB n=500
59 Correct 20 ms 24268 KB n=2000
60 Correct 20 ms 24396 KB n=2000
61 Correct 15 ms 24324 KB n=2000
62 Correct 15 ms 24264 KB n=2000
63 Correct 16 ms 24268 KB n=2000
64 Correct 15 ms 24268 KB n=2000
65 Correct 17 ms 24268 KB n=2000
66 Correct 16 ms 24396 KB n=2000
67 Correct 17 ms 24328 KB n=2000
68 Correct 19 ms 24268 KB n=2000
69 Correct 19 ms 24484 KB n=2000
70 Correct 15 ms 24300 KB n=2000
71 Correct 16 ms 24268 KB n=2000
72 Correct 20 ms 24268 KB n=2000
73 Correct 16 ms 24236 KB n=2000
74 Correct 17 ms 24280 KB n=1844
75 Correct 16 ms 24256 KB n=2000
76 Correct 17 ms 24268 KB n=2000
77 Correct 17 ms 24288 KB n=2000
78 Correct 18 ms 24320 KB n=2000
79 Correct 18 ms 24332 KB n=2000
80 Correct 15 ms 24396 KB n=2000
81 Correct 20 ms 24268 KB n=2000
82 Correct 16 ms 24268 KB n=2000
83 Correct 18 ms 24412 KB n=2000
84 Correct 20 ms 24268 KB n=2000
85 Correct 16 ms 24364 KB n=2000
86 Correct 15 ms 24268 KB n=2000
87 Correct 18 ms 24336 KB n=2000
88 Correct 15 ms 24348 KB n=2000
89 Correct 15 ms 24444 KB n=2000
90 Correct 17 ms 24448 KB n=2000
91 Correct 16 ms 24268 KB n=2000
92 Correct 742 ms 76600 KB n=200000
93 Correct 841 ms 83652 KB n=200000
94 Correct 561 ms 86828 KB n=200000
95 Correct 732 ms 77752 KB n=200000
96 Correct 740 ms 77724 KB n=200000
97 Correct 817 ms 81220 KB n=200000
98 Correct 752 ms 77856 KB n=200000
99 Correct 864 ms 77136 KB n=200000
100 Correct 764 ms 77828 KB n=200000
101 Correct 514 ms 88488 KB n=200000
102 Correct 429 ms 78932 KB n=200000
103 Correct 429 ms 78832 KB n=200000
104 Correct 415 ms 78744 KB n=200000
105 Correct 431 ms 78520 KB n=200000
106 Correct 431 ms 78472 KB n=200000
107 Correct 424 ms 78532 KB n=200000
108 Correct 735 ms 77500 KB n=200000
109 Correct 810 ms 77456 KB n=200000
110 Correct 720 ms 77492 KB n=200000
111 Correct 703 ms 77700 KB n=200000
112 Correct 569 ms 87192 KB n=200000
113 Correct 917 ms 80816 KB n=200000
114 Correct 773 ms 77604 KB n=200000
115 Correct 1102 ms 78068 KB n=200000
116 Correct 665 ms 77224 KB n=200000
117 Correct 463 ms 86656 KB n=200000
118 Correct 903 ms 78408 KB n=200000
119 Correct 712 ms 76308 KB n=200000
120 Correct 466 ms 87048 KB n=200000
121 Correct 470 ms 87136 KB n=200000
122 Correct 467 ms 87464 KB n=200000
123 Correct 488 ms 76900 KB n=200000
124 Correct 212 ms 37828 KB n=25264