#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i<= b; ++i)
#define FORD(i, a, b) for (int i = a; i>=b; --i)
#define REP(i, a) for (int i = 0; i<a; ++i)
#define DEBUG(x) { cerr << #x << " = " << x << endl; }
#define Arr(A, l, r) { cerr << #A << " = "; FOR(_, l, r) cerr << A[_] << ' '; cerr << endl; }
#define N 201000
#define pp pair<int, int>
#define next __next
#define prev __prev
#define __builtin_popcount __builtin_popcountll
#define bit(S, i) (((S) >> i) & 1)
#define IO ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
using namespace std;
int n, m, q, a[N], h[N];
int L[N][20];
vector<int> e[N];
set<int> o[N], t[N];
set<int> :: iterator io, it;
void dfs(int u, int p) {
for (int v : e[u]) if (v != p) {
h[v] = h[u] + 1;
L[v][0] = u;
dfs(v, u);
}
}
int lca(int u, int v) {
if (h[u] < h[v]) swap(u, v);
int delta = h[u] - h[v];
FORD(i, 17, 0) if (bit(delta, i)) u = L[u][i];
if (u == v) return u;
FORD(i, 17, 0) if (L[u][i] != L[v][i]) {
u = L[u][i]; v = L[v][i];
}
return L[u][0];
}
int main() {
IO;
cin >> n >> m >> q;
FOR(i, 2, n) {
int u, v;
cin >> u >> v;
e[u].push_back(v);
e[v].push_back(u);
}
dfs(1, -1);
FOR(j, 1, 17) FOR(v, 1, n) L[v][j] = L[L[v][j - 1]][j - 1];
FOR(i, 1, m) {
cin >> a[i];
o[a[i]].insert(i);
if (i != 1) {
t[lca(a[i], a[i - 1])].insert(i);
}
}
while (q--) {
int type, v, l, r;
cin >> type;
if (type == 1) {
cin >> l >> v;
o[a[l]].erase(l);
if (l > 1) t[lca(a[l - 1], a[l])].erase(l);
if (l < m) t[lca(a[l], a[l + 1])].erase(l + 1);
a[l] = v;
o[a[l]].insert(l);
if (l > 1) t[lca(a[l], a[l - 1])].insert(l);
if (l < m) t[lca(a[l], a[l + 1])].insert(l + 1);
}
else {
cin >> l >> r >> v;
set<int>::iterator it1 = o[v].lower_bound(l);
set<int>::iterator it2 = t[v].lower_bound(l + 1);
int x = -1, y = -1;
if (it1 != o[v].end() && (*it1) <= r) x = (*it1), y = (*it1);
if (it2 != t[v].end() && (*it2) <= r) x = (*it2) - 1, y = (*it2);
printf("%d %d\n", x, y);
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
23932 KB |
n=5 |
2 |
Correct |
20 ms |
24032 KB |
n=100 |
3 |
Correct |
19 ms |
24104 KB |
n=100 |
4 |
Correct |
20 ms |
24140 KB |
n=100 |
5 |
Correct |
20 ms |
24140 KB |
n=100 |
6 |
Correct |
19 ms |
24212 KB |
n=100 |
7 |
Correct |
19 ms |
24212 KB |
n=100 |
8 |
Correct |
19 ms |
24212 KB |
n=100 |
9 |
Correct |
19 ms |
24212 KB |
n=100 |
10 |
Correct |
19 ms |
24212 KB |
n=100 |
11 |
Correct |
19 ms |
24212 KB |
n=100 |
12 |
Correct |
20 ms |
24212 KB |
n=100 |
13 |
Correct |
20 ms |
24212 KB |
n=100 |
14 |
Correct |
19 ms |
24212 KB |
n=100 |
15 |
Correct |
20 ms |
24300 KB |
n=100 |
16 |
Correct |
20 ms |
24300 KB |
n=100 |
17 |
Correct |
19 ms |
24300 KB |
n=100 |
18 |
Correct |
22 ms |
24300 KB |
n=100 |
19 |
Correct |
20 ms |
24300 KB |
n=100 |
20 |
Correct |
20 ms |
24300 KB |
n=100 |
21 |
Correct |
19 ms |
24300 KB |
n=100 |
22 |
Correct |
21 ms |
24300 KB |
n=100 |
23 |
Correct |
19 ms |
24300 KB |
n=100 |
24 |
Correct |
20 ms |
24424 KB |
n=100 |
25 |
Correct |
24 ms |
24424 KB |
n=100 |
26 |
Correct |
19 ms |
24424 KB |
n=12 |
27 |
Correct |
20 ms |
24424 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
23932 KB |
n=5 |
2 |
Correct |
20 ms |
24032 KB |
n=100 |
3 |
Correct |
19 ms |
24104 KB |
n=100 |
4 |
Correct |
20 ms |
24140 KB |
n=100 |
5 |
Correct |
20 ms |
24140 KB |
n=100 |
6 |
Correct |
19 ms |
24212 KB |
n=100 |
7 |
Correct |
19 ms |
24212 KB |
n=100 |
8 |
Correct |
19 ms |
24212 KB |
n=100 |
9 |
Correct |
19 ms |
24212 KB |
n=100 |
10 |
Correct |
19 ms |
24212 KB |
n=100 |
11 |
Correct |
19 ms |
24212 KB |
n=100 |
12 |
Correct |
20 ms |
24212 KB |
n=100 |
13 |
Correct |
20 ms |
24212 KB |
n=100 |
14 |
Correct |
19 ms |
24212 KB |
n=100 |
15 |
Correct |
20 ms |
24300 KB |
n=100 |
16 |
Correct |
20 ms |
24300 KB |
n=100 |
17 |
Correct |
19 ms |
24300 KB |
n=100 |
18 |
Correct |
22 ms |
24300 KB |
n=100 |
19 |
Correct |
20 ms |
24300 KB |
n=100 |
20 |
Correct |
20 ms |
24300 KB |
n=100 |
21 |
Correct |
19 ms |
24300 KB |
n=100 |
22 |
Correct |
21 ms |
24300 KB |
n=100 |
23 |
Correct |
19 ms |
24300 KB |
n=100 |
24 |
Correct |
20 ms |
24424 KB |
n=100 |
25 |
Correct |
24 ms |
24424 KB |
n=100 |
26 |
Correct |
19 ms |
24424 KB |
n=12 |
27 |
Correct |
20 ms |
24424 KB |
n=100 |
28 |
Correct |
26 ms |
24424 KB |
n=500 |
29 |
Correct |
20 ms |
24424 KB |
n=500 |
30 |
Correct |
24 ms |
24428 KB |
n=500 |
31 |
Correct |
24 ms |
24428 KB |
n=500 |
32 |
Correct |
20 ms |
24428 KB |
n=500 |
33 |
Correct |
22 ms |
24428 KB |
n=500 |
34 |
Correct |
20 ms |
24428 KB |
n=500 |
35 |
Correct |
19 ms |
24428 KB |
n=500 |
36 |
Correct |
20 ms |
24428 KB |
n=500 |
37 |
Correct |
20 ms |
24428 KB |
n=500 |
38 |
Correct |
20 ms |
24428 KB |
n=500 |
39 |
Correct |
20 ms |
24428 KB |
n=500 |
40 |
Correct |
20 ms |
24428 KB |
n=500 |
41 |
Correct |
20 ms |
24428 KB |
n=500 |
42 |
Correct |
20 ms |
24428 KB |
n=500 |
43 |
Correct |
20 ms |
24428 KB |
n=500 |
44 |
Correct |
20 ms |
24428 KB |
n=500 |
45 |
Correct |
19 ms |
24428 KB |
n=500 |
46 |
Correct |
19 ms |
24428 KB |
n=500 |
47 |
Correct |
19 ms |
24428 KB |
n=500 |
48 |
Correct |
20 ms |
24428 KB |
n=500 |
49 |
Correct |
21 ms |
24428 KB |
n=500 |
50 |
Correct |
20 ms |
24428 KB |
n=500 |
51 |
Correct |
20 ms |
24428 KB |
n=500 |
52 |
Correct |
21 ms |
24428 KB |
n=500 |
53 |
Correct |
20 ms |
24428 KB |
n=500 |
54 |
Correct |
26 ms |
24428 KB |
n=500 |
55 |
Correct |
19 ms |
24428 KB |
n=278 |
56 |
Correct |
20 ms |
24428 KB |
n=500 |
57 |
Correct |
20 ms |
24428 KB |
n=500 |
58 |
Correct |
20 ms |
24428 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
23932 KB |
n=5 |
2 |
Correct |
20 ms |
24032 KB |
n=100 |
3 |
Correct |
19 ms |
24104 KB |
n=100 |
4 |
Correct |
20 ms |
24140 KB |
n=100 |
5 |
Correct |
20 ms |
24140 KB |
n=100 |
6 |
Correct |
19 ms |
24212 KB |
n=100 |
7 |
Correct |
19 ms |
24212 KB |
n=100 |
8 |
Correct |
19 ms |
24212 KB |
n=100 |
9 |
Correct |
19 ms |
24212 KB |
n=100 |
10 |
Correct |
19 ms |
24212 KB |
n=100 |
11 |
Correct |
19 ms |
24212 KB |
n=100 |
12 |
Correct |
20 ms |
24212 KB |
n=100 |
13 |
Correct |
20 ms |
24212 KB |
n=100 |
14 |
Correct |
19 ms |
24212 KB |
n=100 |
15 |
Correct |
20 ms |
24300 KB |
n=100 |
16 |
Correct |
20 ms |
24300 KB |
n=100 |
17 |
Correct |
19 ms |
24300 KB |
n=100 |
18 |
Correct |
22 ms |
24300 KB |
n=100 |
19 |
Correct |
20 ms |
24300 KB |
n=100 |
20 |
Correct |
20 ms |
24300 KB |
n=100 |
21 |
Correct |
19 ms |
24300 KB |
n=100 |
22 |
Correct |
21 ms |
24300 KB |
n=100 |
23 |
Correct |
19 ms |
24300 KB |
n=100 |
24 |
Correct |
20 ms |
24424 KB |
n=100 |
25 |
Correct |
24 ms |
24424 KB |
n=100 |
26 |
Correct |
19 ms |
24424 KB |
n=12 |
27 |
Correct |
20 ms |
24424 KB |
n=100 |
28 |
Correct |
26 ms |
24424 KB |
n=500 |
29 |
Correct |
20 ms |
24424 KB |
n=500 |
30 |
Correct |
24 ms |
24428 KB |
n=500 |
31 |
Correct |
24 ms |
24428 KB |
n=500 |
32 |
Correct |
20 ms |
24428 KB |
n=500 |
33 |
Correct |
22 ms |
24428 KB |
n=500 |
34 |
Correct |
20 ms |
24428 KB |
n=500 |
35 |
Correct |
19 ms |
24428 KB |
n=500 |
36 |
Correct |
20 ms |
24428 KB |
n=500 |
37 |
Correct |
20 ms |
24428 KB |
n=500 |
38 |
Correct |
20 ms |
24428 KB |
n=500 |
39 |
Correct |
20 ms |
24428 KB |
n=500 |
40 |
Correct |
20 ms |
24428 KB |
n=500 |
41 |
Correct |
20 ms |
24428 KB |
n=500 |
42 |
Correct |
20 ms |
24428 KB |
n=500 |
43 |
Correct |
20 ms |
24428 KB |
n=500 |
44 |
Correct |
20 ms |
24428 KB |
n=500 |
45 |
Correct |
19 ms |
24428 KB |
n=500 |
46 |
Correct |
19 ms |
24428 KB |
n=500 |
47 |
Correct |
19 ms |
24428 KB |
n=500 |
48 |
Correct |
20 ms |
24428 KB |
n=500 |
49 |
Correct |
21 ms |
24428 KB |
n=500 |
50 |
Correct |
20 ms |
24428 KB |
n=500 |
51 |
Correct |
20 ms |
24428 KB |
n=500 |
52 |
Correct |
21 ms |
24428 KB |
n=500 |
53 |
Correct |
20 ms |
24428 KB |
n=500 |
54 |
Correct |
26 ms |
24428 KB |
n=500 |
55 |
Correct |
19 ms |
24428 KB |
n=278 |
56 |
Correct |
20 ms |
24428 KB |
n=500 |
57 |
Correct |
20 ms |
24428 KB |
n=500 |
58 |
Correct |
20 ms |
24428 KB |
n=500 |
59 |
Correct |
31 ms |
24812 KB |
n=2000 |
60 |
Correct |
31 ms |
24812 KB |
n=2000 |
61 |
Correct |
24 ms |
24812 KB |
n=2000 |
62 |
Correct |
24 ms |
24812 KB |
n=2000 |
63 |
Correct |
27 ms |
24812 KB |
n=2000 |
64 |
Correct |
23 ms |
24832 KB |
n=2000 |
65 |
Correct |
24 ms |
24832 KB |
n=2000 |
66 |
Correct |
24 ms |
24832 KB |
n=2000 |
67 |
Correct |
25 ms |
24832 KB |
n=2000 |
68 |
Correct |
24 ms |
24832 KB |
n=2000 |
69 |
Correct |
22 ms |
24832 KB |
n=2000 |
70 |
Correct |
22 ms |
24832 KB |
n=2000 |
71 |
Correct |
22 ms |
24832 KB |
n=2000 |
72 |
Correct |
22 ms |
24832 KB |
n=2000 |
73 |
Correct |
22 ms |
24832 KB |
n=2000 |
74 |
Correct |
23 ms |
24832 KB |
n=1844 |
75 |
Correct |
22 ms |
24832 KB |
n=2000 |
76 |
Correct |
23 ms |
24832 KB |
n=2000 |
77 |
Correct |
28 ms |
24832 KB |
n=2000 |
78 |
Correct |
24 ms |
24872 KB |
n=2000 |
79 |
Correct |
31 ms |
24876 KB |
n=2000 |
80 |
Correct |
25 ms |
24880 KB |
n=2000 |
81 |
Correct |
31 ms |
24880 KB |
n=2000 |
82 |
Correct |
23 ms |
24880 KB |
n=2000 |
83 |
Correct |
23 ms |
24880 KB |
n=2000 |
84 |
Correct |
25 ms |
24880 KB |
n=2000 |
85 |
Correct |
31 ms |
24880 KB |
n=2000 |
86 |
Correct |
29 ms |
24880 KB |
n=2000 |
87 |
Correct |
25 ms |
24880 KB |
n=2000 |
88 |
Correct |
24 ms |
24880 KB |
n=2000 |
89 |
Correct |
26 ms |
24880 KB |
n=2000 |
90 |
Correct |
23 ms |
24880 KB |
n=2000 |
91 |
Correct |
23 ms |
24880 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
23932 KB |
n=5 |
2 |
Correct |
20 ms |
24032 KB |
n=100 |
3 |
Correct |
19 ms |
24104 KB |
n=100 |
4 |
Correct |
20 ms |
24140 KB |
n=100 |
5 |
Correct |
20 ms |
24140 KB |
n=100 |
6 |
Correct |
19 ms |
24212 KB |
n=100 |
7 |
Correct |
19 ms |
24212 KB |
n=100 |
8 |
Correct |
19 ms |
24212 KB |
n=100 |
9 |
Correct |
19 ms |
24212 KB |
n=100 |
10 |
Correct |
19 ms |
24212 KB |
n=100 |
11 |
Correct |
19 ms |
24212 KB |
n=100 |
12 |
Correct |
20 ms |
24212 KB |
n=100 |
13 |
Correct |
20 ms |
24212 KB |
n=100 |
14 |
Correct |
19 ms |
24212 KB |
n=100 |
15 |
Correct |
20 ms |
24300 KB |
n=100 |
16 |
Correct |
20 ms |
24300 KB |
n=100 |
17 |
Correct |
19 ms |
24300 KB |
n=100 |
18 |
Correct |
22 ms |
24300 KB |
n=100 |
19 |
Correct |
20 ms |
24300 KB |
n=100 |
20 |
Correct |
20 ms |
24300 KB |
n=100 |
21 |
Correct |
19 ms |
24300 KB |
n=100 |
22 |
Correct |
21 ms |
24300 KB |
n=100 |
23 |
Correct |
19 ms |
24300 KB |
n=100 |
24 |
Correct |
20 ms |
24424 KB |
n=100 |
25 |
Correct |
24 ms |
24424 KB |
n=100 |
26 |
Correct |
19 ms |
24424 KB |
n=12 |
27 |
Correct |
20 ms |
24424 KB |
n=100 |
28 |
Correct |
26 ms |
24424 KB |
n=500 |
29 |
Correct |
20 ms |
24424 KB |
n=500 |
30 |
Correct |
24 ms |
24428 KB |
n=500 |
31 |
Correct |
24 ms |
24428 KB |
n=500 |
32 |
Correct |
20 ms |
24428 KB |
n=500 |
33 |
Correct |
22 ms |
24428 KB |
n=500 |
34 |
Correct |
20 ms |
24428 KB |
n=500 |
35 |
Correct |
19 ms |
24428 KB |
n=500 |
36 |
Correct |
20 ms |
24428 KB |
n=500 |
37 |
Correct |
20 ms |
24428 KB |
n=500 |
38 |
Correct |
20 ms |
24428 KB |
n=500 |
39 |
Correct |
20 ms |
24428 KB |
n=500 |
40 |
Correct |
20 ms |
24428 KB |
n=500 |
41 |
Correct |
20 ms |
24428 KB |
n=500 |
42 |
Correct |
20 ms |
24428 KB |
n=500 |
43 |
Correct |
20 ms |
24428 KB |
n=500 |
44 |
Correct |
20 ms |
24428 KB |
n=500 |
45 |
Correct |
19 ms |
24428 KB |
n=500 |
46 |
Correct |
19 ms |
24428 KB |
n=500 |
47 |
Correct |
19 ms |
24428 KB |
n=500 |
48 |
Correct |
20 ms |
24428 KB |
n=500 |
49 |
Correct |
21 ms |
24428 KB |
n=500 |
50 |
Correct |
20 ms |
24428 KB |
n=500 |
51 |
Correct |
20 ms |
24428 KB |
n=500 |
52 |
Correct |
21 ms |
24428 KB |
n=500 |
53 |
Correct |
20 ms |
24428 KB |
n=500 |
54 |
Correct |
26 ms |
24428 KB |
n=500 |
55 |
Correct |
19 ms |
24428 KB |
n=278 |
56 |
Correct |
20 ms |
24428 KB |
n=500 |
57 |
Correct |
20 ms |
24428 KB |
n=500 |
58 |
Correct |
20 ms |
24428 KB |
n=500 |
59 |
Correct |
31 ms |
24812 KB |
n=2000 |
60 |
Correct |
31 ms |
24812 KB |
n=2000 |
61 |
Correct |
24 ms |
24812 KB |
n=2000 |
62 |
Correct |
24 ms |
24812 KB |
n=2000 |
63 |
Correct |
27 ms |
24812 KB |
n=2000 |
64 |
Correct |
23 ms |
24832 KB |
n=2000 |
65 |
Correct |
24 ms |
24832 KB |
n=2000 |
66 |
Correct |
24 ms |
24832 KB |
n=2000 |
67 |
Correct |
25 ms |
24832 KB |
n=2000 |
68 |
Correct |
24 ms |
24832 KB |
n=2000 |
69 |
Correct |
22 ms |
24832 KB |
n=2000 |
70 |
Correct |
22 ms |
24832 KB |
n=2000 |
71 |
Correct |
22 ms |
24832 KB |
n=2000 |
72 |
Correct |
22 ms |
24832 KB |
n=2000 |
73 |
Correct |
22 ms |
24832 KB |
n=2000 |
74 |
Correct |
23 ms |
24832 KB |
n=1844 |
75 |
Correct |
22 ms |
24832 KB |
n=2000 |
76 |
Correct |
23 ms |
24832 KB |
n=2000 |
77 |
Correct |
28 ms |
24832 KB |
n=2000 |
78 |
Correct |
24 ms |
24872 KB |
n=2000 |
79 |
Correct |
31 ms |
24876 KB |
n=2000 |
80 |
Correct |
25 ms |
24880 KB |
n=2000 |
81 |
Correct |
31 ms |
24880 KB |
n=2000 |
82 |
Correct |
23 ms |
24880 KB |
n=2000 |
83 |
Correct |
23 ms |
24880 KB |
n=2000 |
84 |
Correct |
25 ms |
24880 KB |
n=2000 |
85 |
Correct |
31 ms |
24880 KB |
n=2000 |
86 |
Correct |
29 ms |
24880 KB |
n=2000 |
87 |
Correct |
25 ms |
24880 KB |
n=2000 |
88 |
Correct |
24 ms |
24880 KB |
n=2000 |
89 |
Correct |
26 ms |
24880 KB |
n=2000 |
90 |
Correct |
23 ms |
24880 KB |
n=2000 |
91 |
Correct |
23 ms |
24880 KB |
n=2000 |
92 |
Correct |
962 ms |
71744 KB |
n=200000 |
93 |
Correct |
1313 ms |
83112 KB |
n=200000 |
94 |
Correct |
1332 ms |
93980 KB |
n=200000 |
95 |
Correct |
906 ms |
93980 KB |
n=200000 |
96 |
Correct |
930 ms |
99868 KB |
n=200000 |
97 |
Correct |
1333 ms |
110436 KB |
n=200000 |
98 |
Correct |
891 ms |
113832 KB |
n=200000 |
99 |
Correct |
1103 ms |
116196 KB |
n=200000 |
100 |
Correct |
939 ms |
116804 KB |
n=200000 |
101 |
Correct |
1347 ms |
125236 KB |
n=200000 |
102 |
Correct |
559 ms |
125236 KB |
n=200000 |
103 |
Correct |
679 ms |
125236 KB |
n=200000 |
104 |
Correct |
604 ms |
125236 KB |
n=200000 |
105 |
Correct |
548 ms |
125236 KB |
n=200000 |
106 |
Correct |
606 ms |
125236 KB |
n=200000 |
107 |
Correct |
562 ms |
125236 KB |
n=200000 |
108 |
Correct |
1040 ms |
125236 KB |
n=200000 |
109 |
Correct |
1016 ms |
125236 KB |
n=200000 |
110 |
Correct |
991 ms |
125236 KB |
n=200000 |
111 |
Correct |
1008 ms |
125236 KB |
n=200000 |
112 |
Correct |
1348 ms |
125236 KB |
n=200000 |
113 |
Correct |
1487 ms |
125236 KB |
n=200000 |
114 |
Correct |
944 ms |
125236 KB |
n=200000 |
115 |
Correct |
1270 ms |
125236 KB |
n=200000 |
116 |
Correct |
867 ms |
125236 KB |
n=200000 |
117 |
Correct |
1234 ms |
125236 KB |
n=200000 |
118 |
Correct |
1256 ms |
125236 KB |
n=200000 |
119 |
Correct |
823 ms |
125236 KB |
n=200000 |
120 |
Correct |
1168 ms |
125236 KB |
n=200000 |
121 |
Correct |
1194 ms |
125236 KB |
n=200000 |
122 |
Correct |
1230 ms |
125340 KB |
n=200000 |
123 |
Correct |
520 ms |
125340 KB |
n=200000 |
124 |
Correct |
271 ms |
125340 KB |
n=25264 |