#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, m, q;
int a[N];
int high[N];
int p[20][N];
vector<int> G[N];
set<int> s[2][N];
int lca(int u, int v) {
if (high[u] > high[v]) swap(u, v);
for (int i = 18; i >= 0; --i) {
if (high[p[i][v]] >= high[u]) v = p[i][v];
}
for (int i = 18; i >= 0; --i) {
if (p[i][v] != p[i][u]) v = p[i][v], u = p[i][u];
}
return (u == v) ? u : p[0][u];
}
void dfs(int u) {
for (auto v : G[u]) {
if (p[0][u] == v) continue;
p[0][v] = u, high[v] = high[u] + 1, dfs(v);
}
}
int main() {
ios::sync_with_stdio(false);
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);
}
p[0][1] = 1, dfs(1);
for (int i = 1; i <= 18; ++i) {
for (int j = 1; j <= n; ++j) {
p[i][j] = p[i - 1][p[i - 1][j]];
}
}
for (int i = 1; i <= m; ++i) cin >> a[i];
for (int i = 1; i <= m; ++i) s[0][a[i]].insert(i);
for (int i = 1; i < m; ++i) s[1][lca(a[i], a[i + 1])].insert(i);
while (q--) {
int type; cin >> type;
if (type == 1) {
int pos, v; cin >> pos >> v;
s[0][a[pos]].erase(pos);
s[0][v].insert(pos);
if (pos > 1) {
s[1][lca(a[pos - 1], a[pos])].erase(pos - 1);
s[1][lca(a[pos - 1], v)].insert(pos - 1);
}
if (pos < m) {
s[1][lca(a[pos], a[pos + 1])].erase(pos);
s[1][lca(v, a[pos + 1])].insert(pos);
}
a[pos] = v;
}
else {
int l, r, v; cin >> l >> r >> v;
set<int> :: iterator it;
it = s[0][v].lower_bound(l);
if (it == s[0][v].end() || *it > r) {
it = s[1][v].lower_bound(l);
if (it != s[1][v].end() && *it < r) {
cout << *it << ' ' << *it + 1 << '\n'; continue;
}
}
else {
cout << *it << ' ' << *it << '\n'; continue;
}
cout << "-1 -1\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
23928 KB |
n=5 |
2 |
Correct |
21 ms |
24124 KB |
n=100 |
3 |
Correct |
21 ms |
24124 KB |
n=100 |
4 |
Correct |
21 ms |
24124 KB |
n=100 |
5 |
Correct |
22 ms |
24124 KB |
n=100 |
6 |
Correct |
21 ms |
24124 KB |
n=100 |
7 |
Correct |
21 ms |
24124 KB |
n=100 |
8 |
Correct |
20 ms |
24268 KB |
n=100 |
9 |
Correct |
20 ms |
24268 KB |
n=100 |
10 |
Correct |
21 ms |
24268 KB |
n=100 |
11 |
Correct |
21 ms |
24268 KB |
n=100 |
12 |
Correct |
21 ms |
24268 KB |
n=100 |
13 |
Correct |
22 ms |
24268 KB |
n=100 |
14 |
Correct |
22 ms |
24268 KB |
n=100 |
15 |
Correct |
22 ms |
24268 KB |
n=100 |
16 |
Correct |
20 ms |
24268 KB |
n=100 |
17 |
Correct |
21 ms |
24268 KB |
n=100 |
18 |
Correct |
22 ms |
24268 KB |
n=100 |
19 |
Correct |
21 ms |
24268 KB |
n=100 |
20 |
Correct |
21 ms |
24268 KB |
n=100 |
21 |
Correct |
21 ms |
24268 KB |
n=100 |
22 |
Correct |
21 ms |
24268 KB |
n=100 |
23 |
Correct |
21 ms |
24268 KB |
n=100 |
24 |
Correct |
21 ms |
24268 KB |
n=100 |
25 |
Correct |
22 ms |
24268 KB |
n=100 |
26 |
Correct |
21 ms |
24268 KB |
n=12 |
27 |
Correct |
23 ms |
24268 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
23928 KB |
n=5 |
2 |
Correct |
21 ms |
24124 KB |
n=100 |
3 |
Correct |
21 ms |
24124 KB |
n=100 |
4 |
Correct |
21 ms |
24124 KB |
n=100 |
5 |
Correct |
22 ms |
24124 KB |
n=100 |
6 |
Correct |
21 ms |
24124 KB |
n=100 |
7 |
Correct |
21 ms |
24124 KB |
n=100 |
8 |
Correct |
20 ms |
24268 KB |
n=100 |
9 |
Correct |
20 ms |
24268 KB |
n=100 |
10 |
Correct |
21 ms |
24268 KB |
n=100 |
11 |
Correct |
21 ms |
24268 KB |
n=100 |
12 |
Correct |
21 ms |
24268 KB |
n=100 |
13 |
Correct |
22 ms |
24268 KB |
n=100 |
14 |
Correct |
22 ms |
24268 KB |
n=100 |
15 |
Correct |
22 ms |
24268 KB |
n=100 |
16 |
Correct |
20 ms |
24268 KB |
n=100 |
17 |
Correct |
21 ms |
24268 KB |
n=100 |
18 |
Correct |
22 ms |
24268 KB |
n=100 |
19 |
Correct |
21 ms |
24268 KB |
n=100 |
20 |
Correct |
21 ms |
24268 KB |
n=100 |
21 |
Correct |
21 ms |
24268 KB |
n=100 |
22 |
Correct |
21 ms |
24268 KB |
n=100 |
23 |
Correct |
21 ms |
24268 KB |
n=100 |
24 |
Correct |
21 ms |
24268 KB |
n=100 |
25 |
Correct |
22 ms |
24268 KB |
n=100 |
26 |
Correct |
21 ms |
24268 KB |
n=12 |
27 |
Correct |
23 ms |
24268 KB |
n=100 |
28 |
Correct |
23 ms |
24312 KB |
n=500 |
29 |
Correct |
22 ms |
24324 KB |
n=500 |
30 |
Correct |
22 ms |
24340 KB |
n=500 |
31 |
Correct |
23 ms |
24356 KB |
n=500 |
32 |
Correct |
23 ms |
24372 KB |
n=500 |
33 |
Correct |
24 ms |
24384 KB |
n=500 |
34 |
Correct |
24 ms |
24400 KB |
n=500 |
35 |
Correct |
22 ms |
24412 KB |
n=500 |
36 |
Correct |
25 ms |
24428 KB |
n=500 |
37 |
Correct |
23 ms |
24440 KB |
n=500 |
38 |
Correct |
23 ms |
24452 KB |
n=500 |
39 |
Correct |
22 ms |
24464 KB |
n=500 |
40 |
Correct |
22 ms |
24484 KB |
n=500 |
41 |
Correct |
24 ms |
24496 KB |
n=500 |
42 |
Correct |
22 ms |
24516 KB |
n=500 |
43 |
Correct |
24 ms |
24524 KB |
n=500 |
44 |
Correct |
24 ms |
24536 KB |
n=500 |
45 |
Correct |
23 ms |
24548 KB |
n=500 |
46 |
Correct |
22 ms |
24560 KB |
n=500 |
47 |
Correct |
23 ms |
24704 KB |
n=500 |
48 |
Correct |
24 ms |
24704 KB |
n=500 |
49 |
Correct |
24 ms |
24704 KB |
n=500 |
50 |
Correct |
24 ms |
24704 KB |
n=500 |
51 |
Correct |
23 ms |
24704 KB |
n=500 |
52 |
Correct |
23 ms |
24776 KB |
n=500 |
53 |
Correct |
23 ms |
24776 KB |
n=500 |
54 |
Correct |
24 ms |
24776 KB |
n=500 |
55 |
Correct |
25 ms |
24816 KB |
n=278 |
56 |
Correct |
26 ms |
24824 KB |
n=500 |
57 |
Correct |
26 ms |
24824 KB |
n=500 |
58 |
Correct |
23 ms |
24824 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
23928 KB |
n=5 |
2 |
Correct |
21 ms |
24124 KB |
n=100 |
3 |
Correct |
21 ms |
24124 KB |
n=100 |
4 |
Correct |
21 ms |
24124 KB |
n=100 |
5 |
Correct |
22 ms |
24124 KB |
n=100 |
6 |
Correct |
21 ms |
24124 KB |
n=100 |
7 |
Correct |
21 ms |
24124 KB |
n=100 |
8 |
Correct |
20 ms |
24268 KB |
n=100 |
9 |
Correct |
20 ms |
24268 KB |
n=100 |
10 |
Correct |
21 ms |
24268 KB |
n=100 |
11 |
Correct |
21 ms |
24268 KB |
n=100 |
12 |
Correct |
21 ms |
24268 KB |
n=100 |
13 |
Correct |
22 ms |
24268 KB |
n=100 |
14 |
Correct |
22 ms |
24268 KB |
n=100 |
15 |
Correct |
22 ms |
24268 KB |
n=100 |
16 |
Correct |
20 ms |
24268 KB |
n=100 |
17 |
Correct |
21 ms |
24268 KB |
n=100 |
18 |
Correct |
22 ms |
24268 KB |
n=100 |
19 |
Correct |
21 ms |
24268 KB |
n=100 |
20 |
Correct |
21 ms |
24268 KB |
n=100 |
21 |
Correct |
21 ms |
24268 KB |
n=100 |
22 |
Correct |
21 ms |
24268 KB |
n=100 |
23 |
Correct |
21 ms |
24268 KB |
n=100 |
24 |
Correct |
21 ms |
24268 KB |
n=100 |
25 |
Correct |
22 ms |
24268 KB |
n=100 |
26 |
Correct |
21 ms |
24268 KB |
n=12 |
27 |
Correct |
23 ms |
24268 KB |
n=100 |
28 |
Correct |
23 ms |
24312 KB |
n=500 |
29 |
Correct |
22 ms |
24324 KB |
n=500 |
30 |
Correct |
22 ms |
24340 KB |
n=500 |
31 |
Correct |
23 ms |
24356 KB |
n=500 |
32 |
Correct |
23 ms |
24372 KB |
n=500 |
33 |
Correct |
24 ms |
24384 KB |
n=500 |
34 |
Correct |
24 ms |
24400 KB |
n=500 |
35 |
Correct |
22 ms |
24412 KB |
n=500 |
36 |
Correct |
25 ms |
24428 KB |
n=500 |
37 |
Correct |
23 ms |
24440 KB |
n=500 |
38 |
Correct |
23 ms |
24452 KB |
n=500 |
39 |
Correct |
22 ms |
24464 KB |
n=500 |
40 |
Correct |
22 ms |
24484 KB |
n=500 |
41 |
Correct |
24 ms |
24496 KB |
n=500 |
42 |
Correct |
22 ms |
24516 KB |
n=500 |
43 |
Correct |
24 ms |
24524 KB |
n=500 |
44 |
Correct |
24 ms |
24536 KB |
n=500 |
45 |
Correct |
23 ms |
24548 KB |
n=500 |
46 |
Correct |
22 ms |
24560 KB |
n=500 |
47 |
Correct |
23 ms |
24704 KB |
n=500 |
48 |
Correct |
24 ms |
24704 KB |
n=500 |
49 |
Correct |
24 ms |
24704 KB |
n=500 |
50 |
Correct |
24 ms |
24704 KB |
n=500 |
51 |
Correct |
23 ms |
24704 KB |
n=500 |
52 |
Correct |
23 ms |
24776 KB |
n=500 |
53 |
Correct |
23 ms |
24776 KB |
n=500 |
54 |
Correct |
24 ms |
24776 KB |
n=500 |
55 |
Correct |
25 ms |
24816 KB |
n=278 |
56 |
Correct |
26 ms |
24824 KB |
n=500 |
57 |
Correct |
26 ms |
24824 KB |
n=500 |
58 |
Correct |
23 ms |
24824 KB |
n=500 |
59 |
Correct |
35 ms |
25124 KB |
n=2000 |
60 |
Correct |
29 ms |
25212 KB |
n=2000 |
61 |
Correct |
29 ms |
25248 KB |
n=2000 |
62 |
Correct |
29 ms |
25320 KB |
n=2000 |
63 |
Correct |
28 ms |
25392 KB |
n=2000 |
64 |
Correct |
30 ms |
25572 KB |
n=2000 |
65 |
Correct |
29 ms |
25620 KB |
n=2000 |
66 |
Correct |
30 ms |
25620 KB |
n=2000 |
67 |
Correct |
30 ms |
25620 KB |
n=2000 |
68 |
Correct |
29 ms |
25680 KB |
n=2000 |
69 |
Correct |
27 ms |
25736 KB |
n=2000 |
70 |
Correct |
29 ms |
25788 KB |
n=2000 |
71 |
Correct |
28 ms |
25840 KB |
n=2000 |
72 |
Correct |
28 ms |
25988 KB |
n=2000 |
73 |
Correct |
28 ms |
25988 KB |
n=2000 |
74 |
Correct |
29 ms |
25988 KB |
n=1844 |
75 |
Correct |
27 ms |
26048 KB |
n=2000 |
76 |
Correct |
29 ms |
26104 KB |
n=2000 |
77 |
Correct |
29 ms |
26160 KB |
n=2000 |
78 |
Correct |
30 ms |
26208 KB |
n=2000 |
79 |
Correct |
30 ms |
26260 KB |
n=2000 |
80 |
Correct |
30 ms |
26416 KB |
n=2000 |
81 |
Correct |
30 ms |
26472 KB |
n=2000 |
82 |
Correct |
33 ms |
26528 KB |
n=2000 |
83 |
Correct |
29 ms |
26528 KB |
n=2000 |
84 |
Correct |
29 ms |
26528 KB |
n=2000 |
85 |
Correct |
29 ms |
26576 KB |
n=2000 |
86 |
Correct |
33 ms |
26704 KB |
n=2000 |
87 |
Correct |
29 ms |
26704 KB |
n=2000 |
88 |
Correct |
31 ms |
26868 KB |
n=2000 |
89 |
Correct |
29 ms |
26868 KB |
n=2000 |
90 |
Correct |
38 ms |
26868 KB |
n=2000 |
91 |
Correct |
29 ms |
26892 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
23928 KB |
n=5 |
2 |
Correct |
21 ms |
24124 KB |
n=100 |
3 |
Correct |
21 ms |
24124 KB |
n=100 |
4 |
Correct |
21 ms |
24124 KB |
n=100 |
5 |
Correct |
22 ms |
24124 KB |
n=100 |
6 |
Correct |
21 ms |
24124 KB |
n=100 |
7 |
Correct |
21 ms |
24124 KB |
n=100 |
8 |
Correct |
20 ms |
24268 KB |
n=100 |
9 |
Correct |
20 ms |
24268 KB |
n=100 |
10 |
Correct |
21 ms |
24268 KB |
n=100 |
11 |
Correct |
21 ms |
24268 KB |
n=100 |
12 |
Correct |
21 ms |
24268 KB |
n=100 |
13 |
Correct |
22 ms |
24268 KB |
n=100 |
14 |
Correct |
22 ms |
24268 KB |
n=100 |
15 |
Correct |
22 ms |
24268 KB |
n=100 |
16 |
Correct |
20 ms |
24268 KB |
n=100 |
17 |
Correct |
21 ms |
24268 KB |
n=100 |
18 |
Correct |
22 ms |
24268 KB |
n=100 |
19 |
Correct |
21 ms |
24268 KB |
n=100 |
20 |
Correct |
21 ms |
24268 KB |
n=100 |
21 |
Correct |
21 ms |
24268 KB |
n=100 |
22 |
Correct |
21 ms |
24268 KB |
n=100 |
23 |
Correct |
21 ms |
24268 KB |
n=100 |
24 |
Correct |
21 ms |
24268 KB |
n=100 |
25 |
Correct |
22 ms |
24268 KB |
n=100 |
26 |
Correct |
21 ms |
24268 KB |
n=12 |
27 |
Correct |
23 ms |
24268 KB |
n=100 |
28 |
Correct |
23 ms |
24312 KB |
n=500 |
29 |
Correct |
22 ms |
24324 KB |
n=500 |
30 |
Correct |
22 ms |
24340 KB |
n=500 |
31 |
Correct |
23 ms |
24356 KB |
n=500 |
32 |
Correct |
23 ms |
24372 KB |
n=500 |
33 |
Correct |
24 ms |
24384 KB |
n=500 |
34 |
Correct |
24 ms |
24400 KB |
n=500 |
35 |
Correct |
22 ms |
24412 KB |
n=500 |
36 |
Correct |
25 ms |
24428 KB |
n=500 |
37 |
Correct |
23 ms |
24440 KB |
n=500 |
38 |
Correct |
23 ms |
24452 KB |
n=500 |
39 |
Correct |
22 ms |
24464 KB |
n=500 |
40 |
Correct |
22 ms |
24484 KB |
n=500 |
41 |
Correct |
24 ms |
24496 KB |
n=500 |
42 |
Correct |
22 ms |
24516 KB |
n=500 |
43 |
Correct |
24 ms |
24524 KB |
n=500 |
44 |
Correct |
24 ms |
24536 KB |
n=500 |
45 |
Correct |
23 ms |
24548 KB |
n=500 |
46 |
Correct |
22 ms |
24560 KB |
n=500 |
47 |
Correct |
23 ms |
24704 KB |
n=500 |
48 |
Correct |
24 ms |
24704 KB |
n=500 |
49 |
Correct |
24 ms |
24704 KB |
n=500 |
50 |
Correct |
24 ms |
24704 KB |
n=500 |
51 |
Correct |
23 ms |
24704 KB |
n=500 |
52 |
Correct |
23 ms |
24776 KB |
n=500 |
53 |
Correct |
23 ms |
24776 KB |
n=500 |
54 |
Correct |
24 ms |
24776 KB |
n=500 |
55 |
Correct |
25 ms |
24816 KB |
n=278 |
56 |
Correct |
26 ms |
24824 KB |
n=500 |
57 |
Correct |
26 ms |
24824 KB |
n=500 |
58 |
Correct |
23 ms |
24824 KB |
n=500 |
59 |
Correct |
35 ms |
25124 KB |
n=2000 |
60 |
Correct |
29 ms |
25212 KB |
n=2000 |
61 |
Correct |
29 ms |
25248 KB |
n=2000 |
62 |
Correct |
29 ms |
25320 KB |
n=2000 |
63 |
Correct |
28 ms |
25392 KB |
n=2000 |
64 |
Correct |
30 ms |
25572 KB |
n=2000 |
65 |
Correct |
29 ms |
25620 KB |
n=2000 |
66 |
Correct |
30 ms |
25620 KB |
n=2000 |
67 |
Correct |
30 ms |
25620 KB |
n=2000 |
68 |
Correct |
29 ms |
25680 KB |
n=2000 |
69 |
Correct |
27 ms |
25736 KB |
n=2000 |
70 |
Correct |
29 ms |
25788 KB |
n=2000 |
71 |
Correct |
28 ms |
25840 KB |
n=2000 |
72 |
Correct |
28 ms |
25988 KB |
n=2000 |
73 |
Correct |
28 ms |
25988 KB |
n=2000 |
74 |
Correct |
29 ms |
25988 KB |
n=1844 |
75 |
Correct |
27 ms |
26048 KB |
n=2000 |
76 |
Correct |
29 ms |
26104 KB |
n=2000 |
77 |
Correct |
29 ms |
26160 KB |
n=2000 |
78 |
Correct |
30 ms |
26208 KB |
n=2000 |
79 |
Correct |
30 ms |
26260 KB |
n=2000 |
80 |
Correct |
30 ms |
26416 KB |
n=2000 |
81 |
Correct |
30 ms |
26472 KB |
n=2000 |
82 |
Correct |
33 ms |
26528 KB |
n=2000 |
83 |
Correct |
29 ms |
26528 KB |
n=2000 |
84 |
Correct |
29 ms |
26528 KB |
n=2000 |
85 |
Correct |
29 ms |
26576 KB |
n=2000 |
86 |
Correct |
33 ms |
26704 KB |
n=2000 |
87 |
Correct |
29 ms |
26704 KB |
n=2000 |
88 |
Correct |
31 ms |
26868 KB |
n=2000 |
89 |
Correct |
29 ms |
26868 KB |
n=2000 |
90 |
Correct |
38 ms |
26868 KB |
n=2000 |
91 |
Correct |
29 ms |
26892 KB |
n=2000 |
92 |
Correct |
2701 ms |
76440 KB |
n=200000 |
93 |
Correct |
3357 ms |
87776 KB |
n=200000 |
94 |
Correct |
3254 ms |
98904 KB |
n=200000 |
95 |
Correct |
2706 ms |
98904 KB |
n=200000 |
96 |
Correct |
2515 ms |
104568 KB |
n=200000 |
97 |
Correct |
3151 ms |
107920 KB |
n=200000 |
98 |
Correct |
2677 ms |
107920 KB |
n=200000 |
99 |
Correct |
3206 ms |
107920 KB |
n=200000 |
100 |
Correct |
2486 ms |
107920 KB |
n=200000 |
101 |
Correct |
2924 ms |
113572 KB |
n=200000 |
102 |
Correct |
1277 ms |
113572 KB |
n=200000 |
103 |
Correct |
1332 ms |
113572 KB |
n=200000 |
104 |
Correct |
1305 ms |
113572 KB |
n=200000 |
105 |
Correct |
1337 ms |
113572 KB |
n=200000 |
106 |
Correct |
1306 ms |
113572 KB |
n=200000 |
107 |
Correct |
1349 ms |
113572 KB |
n=200000 |
108 |
Correct |
2867 ms |
113572 KB |
n=200000 |
109 |
Correct |
3013 ms |
113572 KB |
n=200000 |
110 |
Correct |
2936 ms |
113572 KB |
n=200000 |
111 |
Correct |
2282 ms |
113572 KB |
n=200000 |
112 |
Correct |
3054 ms |
113572 KB |
n=200000 |
113 |
Correct |
3092 ms |
113572 KB |
n=200000 |
114 |
Correct |
2279 ms |
113572 KB |
n=200000 |
115 |
Correct |
3333 ms |
113572 KB |
n=200000 |
116 |
Correct |
2512 ms |
113572 KB |
n=200000 |
117 |
Correct |
2881 ms |
113572 KB |
n=200000 |
118 |
Correct |
3121 ms |
113572 KB |
n=200000 |
119 |
Correct |
2449 ms |
113572 KB |
n=200000 |
120 |
Correct |
2843 ms |
113572 KB |
n=200000 |
121 |
Correct |
2873 ms |
113572 KB |
n=200000 |
122 |
Correct |
2900 ms |
113572 KB |
n=200000 |
123 |
Correct |
1411 ms |
113572 KB |
n=200000 |
124 |
Correct |
509 ms |
113572 KB |
n=25264 |