Submission #861212

# Submission time Handle Problem Language Result Execution time Memory
861212 2023-10-15T16:36:06 Z Trisanu_Das Birthday gift (IZhO18_treearray) C++17
56 / 100
4000 ms 22356 KB
#include <bits/stdc++.h>
using namespace std;
 
int n, m, q, par[200005], g[200005] = {-1}, a[200005];
vector<int> adj[200005];
 
void dfs(int u, int p) {
	g[u] = g[p] + 1;
	par[u] = p;
	for(auto v : adj[u]) if(v != p) dfs(v, u);
}
 
int lca(int v, int u) {
	if(g[v] > g[u]) return lca(par[v], u);
	if(g[v] < g[u]) return lca(v, par[u]);
	if(v != u) return lca(par[v], u);
	return v;
}
 
int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n >> m >> q;
	for (int i = 1; i < n; i++){
		int u, v; cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	for (int i = 1; i < m + 1; i++) cin >> a[i];
	dfs(1, 0);
	while(q--){
		int op; cin >> op;
		if(op == 1){
			int idx, val; cin >> idx >> val;
          a[idx] = val;
		}
		else {
			int l, r, v, ptr_l = -1, ptr_r = -1; cin >> l >> r >> v;
			for (int u = l; u <= r; u++){
				if(u != r && lca(a[u], a[u + 1]) == v){
					ptr_l = u; ptr_r = u + 1;
					break;
                } else if(a[u] == v){
                    ptr_l = u; ptr_r = u;
					break;
				}
			}
			cout << ptr_l << ' ' << ptr_r << '\n';
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5980 KB n=5
2 Correct 2 ms 5980 KB n=100
3 Correct 2 ms 5980 KB n=100
4 Correct 2 ms 5980 KB n=100
5 Correct 2 ms 5980 KB n=100
6 Correct 2 ms 5980 KB n=100
7 Correct 2 ms 5980 KB n=100
8 Correct 2 ms 5980 KB n=100
9 Correct 2 ms 5980 KB n=100
10 Correct 2 ms 6388 KB n=100
11 Correct 2 ms 6232 KB n=100
12 Correct 2 ms 6028 KB n=100
13 Correct 2 ms 5980 KB n=100
14 Correct 2 ms 6232 KB n=100
15 Correct 2 ms 6232 KB n=100
16 Correct 2 ms 6028 KB n=100
17 Correct 2 ms 5976 KB n=100
18 Correct 2 ms 5980 KB n=100
19 Correct 2 ms 5976 KB n=100
20 Correct 2 ms 5980 KB n=100
21 Correct 2 ms 5980 KB n=100
22 Correct 2 ms 6488 KB n=100
23 Correct 2 ms 5980 KB n=100
24 Correct 2 ms 5980 KB n=100
25 Correct 2 ms 5980 KB n=100
26 Correct 2 ms 5980 KB n=12
27 Correct 2 ms 5980 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5980 KB n=5
2 Correct 2 ms 5980 KB n=100
3 Correct 2 ms 5980 KB n=100
4 Correct 2 ms 5980 KB n=100
5 Correct 2 ms 5980 KB n=100
6 Correct 2 ms 5980 KB n=100
7 Correct 2 ms 5980 KB n=100
8 Correct 2 ms 5980 KB n=100
9 Correct 2 ms 5980 KB n=100
10 Correct 2 ms 6388 KB n=100
11 Correct 2 ms 6232 KB n=100
12 Correct 2 ms 6028 KB n=100
13 Correct 2 ms 5980 KB n=100
14 Correct 2 ms 6232 KB n=100
15 Correct 2 ms 6232 KB n=100
16 Correct 2 ms 6028 KB n=100
17 Correct 2 ms 5976 KB n=100
18 Correct 2 ms 5980 KB n=100
19 Correct 2 ms 5976 KB n=100
20 Correct 2 ms 5980 KB n=100
21 Correct 2 ms 5980 KB n=100
22 Correct 2 ms 6488 KB n=100
23 Correct 2 ms 5980 KB n=100
24 Correct 2 ms 5980 KB n=100
25 Correct 2 ms 5980 KB n=100
26 Correct 2 ms 5980 KB n=12
27 Correct 2 ms 5980 KB n=100
28 Correct 2 ms 5980 KB n=500
29 Correct 10 ms 6076 KB n=500
30 Correct 5 ms 5976 KB n=500
31 Correct 7 ms 5980 KB n=500
32 Correct 3 ms 5980 KB n=500
33 Correct 4 ms 5980 KB n=500
34 Correct 2 ms 5976 KB n=500
35 Correct 9 ms 5980 KB n=500
36 Correct 4 ms 5980 KB n=500
37 Correct 4 ms 5980 KB n=500
38 Correct 4 ms 5976 KB n=500
39 Correct 3 ms 5976 KB n=500
40 Correct 3 ms 5980 KB n=500
41 Correct 4 ms 6260 KB n=500
42 Correct 3 ms 5976 KB n=500
43 Correct 3 ms 6032 KB n=500
44 Correct 3 ms 5980 KB n=500
45 Correct 2 ms 5976 KB n=500
46 Correct 9 ms 5980 KB n=500
47 Correct 7 ms 6064 KB n=500
48 Correct 2 ms 5980 KB n=500
49 Correct 7 ms 5980 KB n=500
50 Correct 2 ms 5980 KB n=500
51 Correct 8 ms 5976 KB n=500
52 Correct 16 ms 5976 KB n=500
53 Correct 6 ms 6232 KB n=500
54 Correct 24 ms 5980 KB n=500
55 Correct 2 ms 5980 KB n=278
56 Correct 40 ms 6068 KB n=500
57 Correct 42 ms 5980 KB n=500
58 Correct 3 ms 5980 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5980 KB n=5
2 Correct 2 ms 5980 KB n=100
3 Correct 2 ms 5980 KB n=100
4 Correct 2 ms 5980 KB n=100
5 Correct 2 ms 5980 KB n=100
6 Correct 2 ms 5980 KB n=100
7 Correct 2 ms 5980 KB n=100
8 Correct 2 ms 5980 KB n=100
9 Correct 2 ms 5980 KB n=100
10 Correct 2 ms 6388 KB n=100
11 Correct 2 ms 6232 KB n=100
12 Correct 2 ms 6028 KB n=100
13 Correct 2 ms 5980 KB n=100
14 Correct 2 ms 6232 KB n=100
15 Correct 2 ms 6232 KB n=100
16 Correct 2 ms 6028 KB n=100
17 Correct 2 ms 5976 KB n=100
18 Correct 2 ms 5980 KB n=100
19 Correct 2 ms 5976 KB n=100
20 Correct 2 ms 5980 KB n=100
21 Correct 2 ms 5980 KB n=100
22 Correct 2 ms 6488 KB n=100
23 Correct 2 ms 5980 KB n=100
24 Correct 2 ms 5980 KB n=100
25 Correct 2 ms 5980 KB n=100
26 Correct 2 ms 5980 KB n=12
27 Correct 2 ms 5980 KB n=100
28 Correct 2 ms 5980 KB n=500
29 Correct 10 ms 6076 KB n=500
30 Correct 5 ms 5976 KB n=500
31 Correct 7 ms 5980 KB n=500
32 Correct 3 ms 5980 KB n=500
33 Correct 4 ms 5980 KB n=500
34 Correct 2 ms 5976 KB n=500
35 Correct 9 ms 5980 KB n=500
36 Correct 4 ms 5980 KB n=500
37 Correct 4 ms 5980 KB n=500
38 Correct 4 ms 5976 KB n=500
39 Correct 3 ms 5976 KB n=500
40 Correct 3 ms 5980 KB n=500
41 Correct 4 ms 6260 KB n=500
42 Correct 3 ms 5976 KB n=500
43 Correct 3 ms 6032 KB n=500
44 Correct 3 ms 5980 KB n=500
45 Correct 2 ms 5976 KB n=500
46 Correct 9 ms 5980 KB n=500
47 Correct 7 ms 6064 KB n=500
48 Correct 2 ms 5980 KB n=500
49 Correct 7 ms 5980 KB n=500
50 Correct 2 ms 5980 KB n=500
51 Correct 8 ms 5976 KB n=500
52 Correct 16 ms 5976 KB n=500
53 Correct 6 ms 6232 KB n=500
54 Correct 24 ms 5980 KB n=500
55 Correct 2 ms 5980 KB n=278
56 Correct 40 ms 6068 KB n=500
57 Correct 42 ms 5980 KB n=500
58 Correct 3 ms 5980 KB n=500
59 Correct 2 ms 5976 KB n=2000
60 Correct 464 ms 6236 KB n=2000
61 Correct 243 ms 5980 KB n=2000
62 Correct 74 ms 5976 KB n=2000
63 Correct 3 ms 5980 KB n=2000
64 Correct 143 ms 5980 KB n=2000
65 Correct 2 ms 5980 KB n=2000
66 Correct 358 ms 6220 KB n=2000
67 Correct 3 ms 5976 KB n=2000
68 Correct 188 ms 5980 KB n=2000
69 Correct 64 ms 6140 KB n=2000
70 Correct 62 ms 5980 KB n=2000
71 Correct 62 ms 5976 KB n=2000
72 Correct 32 ms 5980 KB n=2000
73 Correct 32 ms 5976 KB n=2000
74 Correct 2 ms 5976 KB n=1844
75 Correct 33 ms 6236 KB n=2000
76 Correct 31 ms 5980 KB n=2000
77 Correct 30 ms 5976 KB n=2000
78 Correct 32 ms 5980 KB n=2000
79 Correct 3 ms 5980 KB n=2000
80 Correct 326 ms 6452 KB n=2000
81 Correct 130 ms 5976 KB n=2000
82 Correct 2 ms 5980 KB n=2000
83 Correct 271 ms 6184 KB n=2000
84 Correct 6 ms 5980 KB n=2000
85 Correct 240 ms 5976 KB n=2000
86 Correct 199 ms 5976 KB n=2000
87 Correct 7 ms 5976 KB n=2000
88 Correct 2567 ms 6236 KB n=2000
89 Correct 2557 ms 6236 KB n=2000
90 Correct 1275 ms 6232 KB n=2000
91 Correct 39 ms 5976 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5980 KB n=5
2 Correct 2 ms 5980 KB n=100
3 Correct 2 ms 5980 KB n=100
4 Correct 2 ms 5980 KB n=100
5 Correct 2 ms 5980 KB n=100
6 Correct 2 ms 5980 KB n=100
7 Correct 2 ms 5980 KB n=100
8 Correct 2 ms 5980 KB n=100
9 Correct 2 ms 5980 KB n=100
10 Correct 2 ms 6388 KB n=100
11 Correct 2 ms 6232 KB n=100
12 Correct 2 ms 6028 KB n=100
13 Correct 2 ms 5980 KB n=100
14 Correct 2 ms 6232 KB n=100
15 Correct 2 ms 6232 KB n=100
16 Correct 2 ms 6028 KB n=100
17 Correct 2 ms 5976 KB n=100
18 Correct 2 ms 5980 KB n=100
19 Correct 2 ms 5976 KB n=100
20 Correct 2 ms 5980 KB n=100
21 Correct 2 ms 5980 KB n=100
22 Correct 2 ms 6488 KB n=100
23 Correct 2 ms 5980 KB n=100
24 Correct 2 ms 5980 KB n=100
25 Correct 2 ms 5980 KB n=100
26 Correct 2 ms 5980 KB n=12
27 Correct 2 ms 5980 KB n=100
28 Correct 2 ms 5980 KB n=500
29 Correct 10 ms 6076 KB n=500
30 Correct 5 ms 5976 KB n=500
31 Correct 7 ms 5980 KB n=500
32 Correct 3 ms 5980 KB n=500
33 Correct 4 ms 5980 KB n=500
34 Correct 2 ms 5976 KB n=500
35 Correct 9 ms 5980 KB n=500
36 Correct 4 ms 5980 KB n=500
37 Correct 4 ms 5980 KB n=500
38 Correct 4 ms 5976 KB n=500
39 Correct 3 ms 5976 KB n=500
40 Correct 3 ms 5980 KB n=500
41 Correct 4 ms 6260 KB n=500
42 Correct 3 ms 5976 KB n=500
43 Correct 3 ms 6032 KB n=500
44 Correct 3 ms 5980 KB n=500
45 Correct 2 ms 5976 KB n=500
46 Correct 9 ms 5980 KB n=500
47 Correct 7 ms 6064 KB n=500
48 Correct 2 ms 5980 KB n=500
49 Correct 7 ms 5980 KB n=500
50 Correct 2 ms 5980 KB n=500
51 Correct 8 ms 5976 KB n=500
52 Correct 16 ms 5976 KB n=500
53 Correct 6 ms 6232 KB n=500
54 Correct 24 ms 5980 KB n=500
55 Correct 2 ms 5980 KB n=278
56 Correct 40 ms 6068 KB n=500
57 Correct 42 ms 5980 KB n=500
58 Correct 3 ms 5980 KB n=500
59 Correct 2 ms 5976 KB n=2000
60 Correct 464 ms 6236 KB n=2000
61 Correct 243 ms 5980 KB n=2000
62 Correct 74 ms 5976 KB n=2000
63 Correct 3 ms 5980 KB n=2000
64 Correct 143 ms 5980 KB n=2000
65 Correct 2 ms 5980 KB n=2000
66 Correct 358 ms 6220 KB n=2000
67 Correct 3 ms 5976 KB n=2000
68 Correct 188 ms 5980 KB n=2000
69 Correct 64 ms 6140 KB n=2000
70 Correct 62 ms 5980 KB n=2000
71 Correct 62 ms 5976 KB n=2000
72 Correct 32 ms 5980 KB n=2000
73 Correct 32 ms 5976 KB n=2000
74 Correct 2 ms 5976 KB n=1844
75 Correct 33 ms 6236 KB n=2000
76 Correct 31 ms 5980 KB n=2000
77 Correct 30 ms 5976 KB n=2000
78 Correct 32 ms 5980 KB n=2000
79 Correct 3 ms 5980 KB n=2000
80 Correct 326 ms 6452 KB n=2000
81 Correct 130 ms 5976 KB n=2000
82 Correct 2 ms 5980 KB n=2000
83 Correct 271 ms 6184 KB n=2000
84 Correct 6 ms 5980 KB n=2000
85 Correct 240 ms 5976 KB n=2000
86 Correct 199 ms 5976 KB n=2000
87 Correct 7 ms 5976 KB n=2000
88 Correct 2567 ms 6236 KB n=2000
89 Correct 2557 ms 6236 KB n=2000
90 Correct 1275 ms 6232 KB n=2000
91 Correct 39 ms 5976 KB n=2000
92 Correct 140 ms 22152 KB n=200000
93 Execution timed out 4030 ms 22356 KB Time limit exceeded
94 Halted 0 ms 0 KB -