Submission #167663

# Submission time Handle Problem Language Result Execution time Memory
167663 2019-12-09T10:29:43 Z shuvi_dola Birthday gift (IZhO18_treearray) C++14
100 / 100
2305 ms 85752 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
vector <int> g[N];
int a[N], dep[N], par[N][23];
set <int> posver[N], poslca[N];
int n, m, q;
void dfs(int s, int p) {
	par[s][0] = p;
	for(int i = 1; i <= 20; i++) {
		par[s][i] = par[par[s][i - 1]][i - 1];
	}
	for(auto u : g[s]) {
		if(u == p) continue;
		dep[u] = dep[s] + 1;
		dfs(u, s);
	}
}

int lca(int u, int v) {
	if(dep[u] < dep[v]) swap(u, v);
	for(int i = 20; i >= 0; i--) if(dep[u] - dep[v] >= (1 << i)) u = par[u][i];
	if(u == v) return u;
	for(int i = 20; i >= 0; i--)  if(par[u][i] != par[v][i]) u = par[u][i], v = par[v][i]; 
	return par[u][0];
}

int main() {
	cin >> n >> m >> q;

	for(int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}

	dfs(1, 0);
	for(int i = 1; i <= m; i++) {
		cin >> a[i];
		posver[a[i]].insert(i);
		if(i > 1) poslca[lca(a[i], a[i - 1])].insert(i);
	}

	while(q--) {
		int typ, x, y ,ver;
		cin >> typ >> x >> y;
		if(typ == 1) {
			posver[a[x]].erase(x);
			if(x > 1) poslca[lca(a[x], a[x - 1])].erase(x);
			if(x < m) poslca[lca(a[x], a[x + 1])].erase(x + 1);
			a[x] = y;
			posver[a[x]].insert(x);
			if(x > 1) poslca[lca(a[x], a[x - 1])].insert(x);
			if(x < m) poslca[lca(a[x], a[x + 1])].insert(x + 1);
		}

		else {
			cin >> ver;
			if(posver[ver].size() > 0) {
				auto L = posver[ver].lower_bound(x);
				if(L != posver[ver].end() && *L <= y) {
					cout << *L << ' ' << *L << '\n';
					continue; 
				}
			}
			if(poslca[ver].size() > 0) {
				auto L = poslca[ver].lower_bound(x + 1);
				if(L != poslca[ver].end() && *L <= y) {
					cout << (*L) - 1 << ' ' << *L << '\n';
					continue;
				}
			}
			cout << "-1 -1 \n";
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23800 KB n=5
2 Correct 24 ms 23800 KB n=100
3 Correct 23 ms 23800 KB n=100
4 Correct 23 ms 23928 KB n=100
5 Correct 24 ms 23800 KB n=100
6 Correct 23 ms 23800 KB n=100
7 Correct 23 ms 23800 KB n=100
8 Correct 24 ms 23800 KB n=100
9 Correct 23 ms 23800 KB n=100
10 Correct 24 ms 23800 KB n=100
11 Correct 24 ms 23800 KB n=100
12 Correct 24 ms 23800 KB n=100
13 Correct 23 ms 23800 KB n=100
14 Correct 23 ms 23800 KB n=100
15 Correct 23 ms 23800 KB n=100
16 Correct 23 ms 23800 KB n=100
17 Correct 24 ms 23800 KB n=100
18 Correct 23 ms 23800 KB n=100
19 Correct 23 ms 23800 KB n=100
20 Correct 23 ms 23824 KB n=100
21 Correct 23 ms 23800 KB n=100
22 Correct 23 ms 23928 KB n=100
23 Correct 24 ms 23772 KB n=100
24 Correct 23 ms 23800 KB n=100
25 Correct 24 ms 23800 KB n=100
26 Correct 24 ms 23800 KB n=12
27 Correct 24 ms 23800 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23800 KB n=5
2 Correct 24 ms 23800 KB n=100
3 Correct 23 ms 23800 KB n=100
4 Correct 23 ms 23928 KB n=100
5 Correct 24 ms 23800 KB n=100
6 Correct 23 ms 23800 KB n=100
7 Correct 23 ms 23800 KB n=100
8 Correct 24 ms 23800 KB n=100
9 Correct 23 ms 23800 KB n=100
10 Correct 24 ms 23800 KB n=100
11 Correct 24 ms 23800 KB n=100
12 Correct 24 ms 23800 KB n=100
13 Correct 23 ms 23800 KB n=100
14 Correct 23 ms 23800 KB n=100
15 Correct 23 ms 23800 KB n=100
16 Correct 23 ms 23800 KB n=100
17 Correct 24 ms 23800 KB n=100
18 Correct 23 ms 23800 KB n=100
19 Correct 23 ms 23800 KB n=100
20 Correct 23 ms 23824 KB n=100
21 Correct 23 ms 23800 KB n=100
22 Correct 23 ms 23928 KB n=100
23 Correct 24 ms 23772 KB n=100
24 Correct 23 ms 23800 KB n=100
25 Correct 24 ms 23800 KB n=100
26 Correct 24 ms 23800 KB n=12
27 Correct 24 ms 23800 KB n=100
28 Correct 25 ms 23900 KB n=500
29 Correct 25 ms 23900 KB n=500
30 Correct 25 ms 23928 KB n=500
31 Correct 25 ms 23928 KB n=500
32 Correct 26 ms 23928 KB n=500
33 Correct 26 ms 23928 KB n=500
34 Correct 26 ms 23928 KB n=500
35 Correct 25 ms 23928 KB n=500
36 Correct 26 ms 23928 KB n=500
37 Correct 26 ms 24028 KB n=500
38 Correct 26 ms 23928 KB n=500
39 Correct 26 ms 23928 KB n=500
40 Correct 31 ms 23928 KB n=500
41 Correct 26 ms 23928 KB n=500
42 Correct 26 ms 23928 KB n=500
43 Correct 30 ms 23928 KB n=500
44 Correct 26 ms 23928 KB n=500
45 Correct 26 ms 23928 KB n=500
46 Correct 27 ms 24056 KB n=500
47 Correct 26 ms 23928 KB n=500
48 Correct 26 ms 23928 KB n=500
49 Correct 27 ms 23928 KB n=500
50 Correct 26 ms 23928 KB n=500
51 Correct 26 ms 23928 KB n=500
52 Correct 25 ms 23928 KB n=500
53 Correct 26 ms 23928 KB n=500
54 Correct 26 ms 23932 KB n=500
55 Correct 24 ms 23928 KB n=278
56 Correct 25 ms 23928 KB n=500
57 Correct 26 ms 23928 KB n=500
58 Correct 31 ms 23928 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23800 KB n=5
2 Correct 24 ms 23800 KB n=100
3 Correct 23 ms 23800 KB n=100
4 Correct 23 ms 23928 KB n=100
5 Correct 24 ms 23800 KB n=100
6 Correct 23 ms 23800 KB n=100
7 Correct 23 ms 23800 KB n=100
8 Correct 24 ms 23800 KB n=100
9 Correct 23 ms 23800 KB n=100
10 Correct 24 ms 23800 KB n=100
11 Correct 24 ms 23800 KB n=100
12 Correct 24 ms 23800 KB n=100
13 Correct 23 ms 23800 KB n=100
14 Correct 23 ms 23800 KB n=100
15 Correct 23 ms 23800 KB n=100
16 Correct 23 ms 23800 KB n=100
17 Correct 24 ms 23800 KB n=100
18 Correct 23 ms 23800 KB n=100
19 Correct 23 ms 23800 KB n=100
20 Correct 23 ms 23824 KB n=100
21 Correct 23 ms 23800 KB n=100
22 Correct 23 ms 23928 KB n=100
23 Correct 24 ms 23772 KB n=100
24 Correct 23 ms 23800 KB n=100
25 Correct 24 ms 23800 KB n=100
26 Correct 24 ms 23800 KB n=12
27 Correct 24 ms 23800 KB n=100
28 Correct 25 ms 23900 KB n=500
29 Correct 25 ms 23900 KB n=500
30 Correct 25 ms 23928 KB n=500
31 Correct 25 ms 23928 KB n=500
32 Correct 26 ms 23928 KB n=500
33 Correct 26 ms 23928 KB n=500
34 Correct 26 ms 23928 KB n=500
35 Correct 25 ms 23928 KB n=500
36 Correct 26 ms 23928 KB n=500
37 Correct 26 ms 24028 KB n=500
38 Correct 26 ms 23928 KB n=500
39 Correct 26 ms 23928 KB n=500
40 Correct 31 ms 23928 KB n=500
41 Correct 26 ms 23928 KB n=500
42 Correct 26 ms 23928 KB n=500
43 Correct 30 ms 23928 KB n=500
44 Correct 26 ms 23928 KB n=500
45 Correct 26 ms 23928 KB n=500
46 Correct 27 ms 24056 KB n=500
47 Correct 26 ms 23928 KB n=500
48 Correct 26 ms 23928 KB n=500
49 Correct 27 ms 23928 KB n=500
50 Correct 26 ms 23928 KB n=500
51 Correct 26 ms 23928 KB n=500
52 Correct 25 ms 23928 KB n=500
53 Correct 26 ms 23928 KB n=500
54 Correct 26 ms 23932 KB n=500
55 Correct 24 ms 23928 KB n=278
56 Correct 25 ms 23928 KB n=500
57 Correct 26 ms 23928 KB n=500
58 Correct 31 ms 23928 KB n=500
59 Correct 34 ms 24312 KB n=2000
60 Correct 35 ms 24440 KB n=2000
61 Correct 34 ms 24312 KB n=2000
62 Correct 39 ms 24312 KB n=2000
63 Correct 39 ms 24340 KB n=2000
64 Correct 40 ms 24312 KB n=2000
65 Correct 39 ms 24312 KB n=2000
66 Correct 35 ms 24440 KB n=2000
67 Correct 35 ms 24440 KB n=2000
68 Correct 35 ms 24360 KB n=2000
69 Correct 35 ms 24440 KB n=2000
70 Correct 36 ms 24312 KB n=2000
71 Correct 35 ms 24312 KB n=2000
72 Correct 36 ms 24312 KB n=2000
73 Correct 36 ms 24440 KB n=2000
74 Correct 32 ms 24312 KB n=1844
75 Correct 35 ms 24388 KB n=2000
76 Correct 34 ms 24312 KB n=2000
77 Correct 34 ms 24312 KB n=2000
78 Correct 35 ms 24312 KB n=2000
79 Correct 34 ms 24312 KB n=2000
80 Correct 34 ms 24440 KB n=2000
81 Correct 34 ms 24312 KB n=2000
82 Correct 34 ms 24312 KB n=2000
83 Correct 38 ms 24440 KB n=2000
84 Correct 34 ms 24312 KB n=2000
85 Correct 34 ms 24280 KB n=2000
86 Correct 35 ms 24312 KB n=2000
87 Correct 35 ms 24312 KB n=2000
88 Correct 34 ms 24444 KB n=2000
89 Correct 35 ms 24440 KB n=2000
90 Correct 35 ms 24412 KB n=2000
91 Correct 36 ms 24284 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23800 KB n=5
2 Correct 24 ms 23800 KB n=100
3 Correct 23 ms 23800 KB n=100
4 Correct 23 ms 23928 KB n=100
5 Correct 24 ms 23800 KB n=100
6 Correct 23 ms 23800 KB n=100
7 Correct 23 ms 23800 KB n=100
8 Correct 24 ms 23800 KB n=100
9 Correct 23 ms 23800 KB n=100
10 Correct 24 ms 23800 KB n=100
11 Correct 24 ms 23800 KB n=100
12 Correct 24 ms 23800 KB n=100
13 Correct 23 ms 23800 KB n=100
14 Correct 23 ms 23800 KB n=100
15 Correct 23 ms 23800 KB n=100
16 Correct 23 ms 23800 KB n=100
17 Correct 24 ms 23800 KB n=100
18 Correct 23 ms 23800 KB n=100
19 Correct 23 ms 23800 KB n=100
20 Correct 23 ms 23824 KB n=100
21 Correct 23 ms 23800 KB n=100
22 Correct 23 ms 23928 KB n=100
23 Correct 24 ms 23772 KB n=100
24 Correct 23 ms 23800 KB n=100
25 Correct 24 ms 23800 KB n=100
26 Correct 24 ms 23800 KB n=12
27 Correct 24 ms 23800 KB n=100
28 Correct 25 ms 23900 KB n=500
29 Correct 25 ms 23900 KB n=500
30 Correct 25 ms 23928 KB n=500
31 Correct 25 ms 23928 KB n=500
32 Correct 26 ms 23928 KB n=500
33 Correct 26 ms 23928 KB n=500
34 Correct 26 ms 23928 KB n=500
35 Correct 25 ms 23928 KB n=500
36 Correct 26 ms 23928 KB n=500
37 Correct 26 ms 24028 KB n=500
38 Correct 26 ms 23928 KB n=500
39 Correct 26 ms 23928 KB n=500
40 Correct 31 ms 23928 KB n=500
41 Correct 26 ms 23928 KB n=500
42 Correct 26 ms 23928 KB n=500
43 Correct 30 ms 23928 KB n=500
44 Correct 26 ms 23928 KB n=500
45 Correct 26 ms 23928 KB n=500
46 Correct 27 ms 24056 KB n=500
47 Correct 26 ms 23928 KB n=500
48 Correct 26 ms 23928 KB n=500
49 Correct 27 ms 23928 KB n=500
50 Correct 26 ms 23928 KB n=500
51 Correct 26 ms 23928 KB n=500
52 Correct 25 ms 23928 KB n=500
53 Correct 26 ms 23928 KB n=500
54 Correct 26 ms 23932 KB n=500
55 Correct 24 ms 23928 KB n=278
56 Correct 25 ms 23928 KB n=500
57 Correct 26 ms 23928 KB n=500
58 Correct 31 ms 23928 KB n=500
59 Correct 34 ms 24312 KB n=2000
60 Correct 35 ms 24440 KB n=2000
61 Correct 34 ms 24312 KB n=2000
62 Correct 39 ms 24312 KB n=2000
63 Correct 39 ms 24340 KB n=2000
64 Correct 40 ms 24312 KB n=2000
65 Correct 39 ms 24312 KB n=2000
66 Correct 35 ms 24440 KB n=2000
67 Correct 35 ms 24440 KB n=2000
68 Correct 35 ms 24360 KB n=2000
69 Correct 35 ms 24440 KB n=2000
70 Correct 36 ms 24312 KB n=2000
71 Correct 35 ms 24312 KB n=2000
72 Correct 36 ms 24312 KB n=2000
73 Correct 36 ms 24440 KB n=2000
74 Correct 32 ms 24312 KB n=1844
75 Correct 35 ms 24388 KB n=2000
76 Correct 34 ms 24312 KB n=2000
77 Correct 34 ms 24312 KB n=2000
78 Correct 35 ms 24312 KB n=2000
79 Correct 34 ms 24312 KB n=2000
80 Correct 34 ms 24440 KB n=2000
81 Correct 34 ms 24312 KB n=2000
82 Correct 34 ms 24312 KB n=2000
83 Correct 38 ms 24440 KB n=2000
84 Correct 34 ms 24312 KB n=2000
85 Correct 34 ms 24280 KB n=2000
86 Correct 35 ms 24312 KB n=2000
87 Correct 35 ms 24312 KB n=2000
88 Correct 34 ms 24444 KB n=2000
89 Correct 35 ms 24440 KB n=2000
90 Correct 35 ms 24412 KB n=2000
91 Correct 36 ms 24284 KB n=2000
92 Correct 1658 ms 74248 KB n=200000
93 Correct 2162 ms 80888 KB n=200000
94 Correct 2086 ms 84504 KB n=200000
95 Correct 1644 ms 74820 KB n=200000
96 Correct 1629 ms 75060 KB n=200000
97 Correct 2305 ms 79880 KB n=200000
98 Correct 1637 ms 75280 KB n=200000
99 Correct 1887 ms 76272 KB n=200000
100 Correct 1677 ms 74024 KB n=200000
101 Correct 2068 ms 84912 KB n=200000
102 Correct 1579 ms 78192 KB n=200000
103 Correct 1548 ms 77860 KB n=200000
104 Correct 1545 ms 78116 KB n=200000
105 Correct 1629 ms 77316 KB n=200000
106 Correct 1592 ms 77636 KB n=200000
107 Correct 1610 ms 77292 KB n=200000
108 Correct 1906 ms 76728 KB n=200000
109 Correct 1750 ms 76984 KB n=200000
110 Correct 1797 ms 76844 KB n=200000
111 Correct 1711 ms 75000 KB n=200000
112 Correct 2019 ms 83700 KB n=200000
113 Correct 2104 ms 78764 KB n=200000
114 Correct 1620 ms 74876 KB n=200000
115 Correct 2290 ms 77260 KB n=200000
116 Correct 1660 ms 75072 KB n=200000
117 Correct 2045 ms 84664 KB n=200000
118 Correct 2057 ms 78396 KB n=200000
119 Correct 1602 ms 76884 KB n=200000
120 Correct 1956 ms 85348 KB n=200000
121 Correct 1961 ms 85532 KB n=200000
122 Correct 1980 ms 85752 KB n=200000
123 Correct 1622 ms 78260 KB n=200000
124 Correct 609 ms 39100 KB n=25264