#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#include <cassert>
#define ericxiao ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
using namespace std;
const int maxN = 2e5 + 326, maxLog = 19;
set<int> pos[maxN], sing[maxN];
int N, M, com, v, x, y, l, r, dep[maxN], jump[maxN], pa[maxN], Q, arr[maxN], anc[maxLog][maxN];
vector<int> adj[maxN];
void getAnc(int p = 1, int u = 1){
pa[u] = p;
//anc[0][u] = p;
dep[u] = dep[p] + 1;
//for(int i = 1; i < maxLog; i++) anc[i][u] = anc[i - 1][anc[i - 1][u]];
if(u == p){
jump[u] = p;
} else {
if(dep[jump[jump[p]]] - dep[jump[p]] == dep[jump[p]] - dep[p]) jump[u] = jump[jump[p]];
else jump[u] = p;
}
for(int v : adj[u]) if(v != p) getAnc(u, v);
}
int lca(int a, int b){
if(dep[a] > dep[b]) swap(a, b);
while(dep[b] > dep[a]){
if(dep[jump[b]] < dep[a]) b = pa[b];
else b = jump[b];
}
if(a == b) return a;
while(pa[a] != pa[b]){
if(jump[a] == jump[b]){
a = pa[a];
b = pa[b];
} else {
a = jump[a];
b = jump[b];
}
}
return pa[a];
}
int main(){
ericxiao
cin >> N >> M >> Q;
for(int i = 0; i < N - 1; i++){
cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
}
getAnc();
for(int i = 1; i <= M; i++){
cin >> arr[i];
sing[arr[i]].insert(i);
}
for(int i = 1; i < M; i++){
pos[lca(arr[i], arr[i + 1])].insert(i);
//cout << arr[i] << " " << arr[i + 1] << ": " << lca(arr[i], arr[i + 1]) << endl;
}
while(Q--){
cin >> com;
if(com == 1){
cin >> x >> v;
sing[arr[x]].erase(x);
if(x + 1 <= M){
pos[lca(arr[x], arr[x + 1])].erase(x);
}
if(x - 1 >= 1){
pos[lca(arr[x - 1], arr[x])].erase(x - 1);
}
arr[x] = v;
sing[arr[x]].insert(x);
if(x + 1 <= M){
pos[lca(arr[x], arr[x + 1])].insert(x);
}
if(x - 1 >= 1){
pos[lca(arr[x - 1], arr[x])].insert(x - 1);
}
} else {
cin >> l >> r >> v;
auto it = sing[v].lower_bound(l);
if(it != sing[v].end() && *it <= r){
assert(*it >= l && *it <= r);
assert(arr[*it] == v);
cout << *it << " " << *it << endl;
} else {
auto it2 = pos[v].lower_bound(l);
//if(it2 != pos[v].end()) cout << "found: " << *it2 << endl;
if(it2 != pos[v].end() && *it2 + 1 <= r){
assert(*it2 >= l && *it2 + 1 <= r);
assert(lca(arr[*it2], arr[*it2 + 1]) == v);
cout << *it2 << " " << *it2 + 1 << endl;
} else {
cout << "-1 -1" << endl;
}
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23916 KB |
n=5 |
2 |
Correct |
16 ms |
23916 KB |
n=100 |
3 |
Correct |
16 ms |
23916 KB |
n=100 |
4 |
Correct |
15 ms |
23916 KB |
n=100 |
5 |
Correct |
17 ms |
23916 KB |
n=100 |
6 |
Correct |
16 ms |
23916 KB |
n=100 |
7 |
Correct |
16 ms |
23916 KB |
n=100 |
8 |
Correct |
17 ms |
23916 KB |
n=100 |
9 |
Correct |
17 ms |
23916 KB |
n=100 |
10 |
Correct |
16 ms |
23916 KB |
n=100 |
11 |
Correct |
17 ms |
23916 KB |
n=100 |
12 |
Correct |
15 ms |
23948 KB |
n=100 |
13 |
Correct |
16 ms |
23916 KB |
n=100 |
14 |
Correct |
16 ms |
23916 KB |
n=100 |
15 |
Correct |
16 ms |
24064 KB |
n=100 |
16 |
Correct |
15 ms |
23916 KB |
n=100 |
17 |
Correct |
15 ms |
23916 KB |
n=100 |
18 |
Correct |
16 ms |
23916 KB |
n=100 |
19 |
Correct |
18 ms |
23916 KB |
n=100 |
20 |
Correct |
15 ms |
23916 KB |
n=100 |
21 |
Correct |
15 ms |
23916 KB |
n=100 |
22 |
Correct |
16 ms |
23916 KB |
n=100 |
23 |
Correct |
15 ms |
23916 KB |
n=100 |
24 |
Correct |
16 ms |
23916 KB |
n=100 |
25 |
Correct |
15 ms |
23916 KB |
n=100 |
26 |
Correct |
16 ms |
23904 KB |
n=12 |
27 |
Correct |
15 ms |
23916 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23916 KB |
n=5 |
2 |
Correct |
16 ms |
23916 KB |
n=100 |
3 |
Correct |
16 ms |
23916 KB |
n=100 |
4 |
Correct |
15 ms |
23916 KB |
n=100 |
5 |
Correct |
17 ms |
23916 KB |
n=100 |
6 |
Correct |
16 ms |
23916 KB |
n=100 |
7 |
Correct |
16 ms |
23916 KB |
n=100 |
8 |
Correct |
17 ms |
23916 KB |
n=100 |
9 |
Correct |
17 ms |
23916 KB |
n=100 |
10 |
Correct |
16 ms |
23916 KB |
n=100 |
11 |
Correct |
17 ms |
23916 KB |
n=100 |
12 |
Correct |
15 ms |
23948 KB |
n=100 |
13 |
Correct |
16 ms |
23916 KB |
n=100 |
14 |
Correct |
16 ms |
23916 KB |
n=100 |
15 |
Correct |
16 ms |
24064 KB |
n=100 |
16 |
Correct |
15 ms |
23916 KB |
n=100 |
17 |
Correct |
15 ms |
23916 KB |
n=100 |
18 |
Correct |
16 ms |
23916 KB |
n=100 |
19 |
Correct |
18 ms |
23916 KB |
n=100 |
20 |
Correct |
15 ms |
23916 KB |
n=100 |
21 |
Correct |
15 ms |
23916 KB |
n=100 |
22 |
Correct |
16 ms |
23916 KB |
n=100 |
23 |
Correct |
15 ms |
23916 KB |
n=100 |
24 |
Correct |
16 ms |
23916 KB |
n=100 |
25 |
Correct |
15 ms |
23916 KB |
n=100 |
26 |
Correct |
16 ms |
23904 KB |
n=12 |
27 |
Correct |
15 ms |
23916 KB |
n=100 |
28 |
Correct |
16 ms |
23916 KB |
n=500 |
29 |
Correct |
17 ms |
23916 KB |
n=500 |
30 |
Correct |
16 ms |
23916 KB |
n=500 |
31 |
Correct |
16 ms |
23916 KB |
n=500 |
32 |
Correct |
16 ms |
23916 KB |
n=500 |
33 |
Correct |
16 ms |
23916 KB |
n=500 |
34 |
Correct |
18 ms |
23916 KB |
n=500 |
35 |
Correct |
18 ms |
23916 KB |
n=500 |
36 |
Correct |
19 ms |
23916 KB |
n=500 |
37 |
Correct |
16 ms |
23916 KB |
n=500 |
38 |
Correct |
16 ms |
23916 KB |
n=500 |
39 |
Correct |
16 ms |
23916 KB |
n=500 |
40 |
Correct |
16 ms |
23916 KB |
n=500 |
41 |
Correct |
18 ms |
23944 KB |
n=500 |
42 |
Correct |
16 ms |
23916 KB |
n=500 |
43 |
Correct |
16 ms |
23916 KB |
n=500 |
44 |
Correct |
17 ms |
23916 KB |
n=500 |
45 |
Correct |
17 ms |
23916 KB |
n=500 |
46 |
Correct |
18 ms |
23916 KB |
n=500 |
47 |
Correct |
16 ms |
23916 KB |
n=500 |
48 |
Correct |
17 ms |
23916 KB |
n=500 |
49 |
Correct |
16 ms |
23916 KB |
n=500 |
50 |
Correct |
16 ms |
23916 KB |
n=500 |
51 |
Correct |
17 ms |
23916 KB |
n=500 |
52 |
Correct |
17 ms |
23916 KB |
n=500 |
53 |
Correct |
18 ms |
24044 KB |
n=500 |
54 |
Correct |
16 ms |
23916 KB |
n=500 |
55 |
Correct |
17 ms |
23920 KB |
n=278 |
56 |
Correct |
17 ms |
23916 KB |
n=500 |
57 |
Correct |
16 ms |
23916 KB |
n=500 |
58 |
Correct |
16 ms |
23916 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23916 KB |
n=5 |
2 |
Correct |
16 ms |
23916 KB |
n=100 |
3 |
Correct |
16 ms |
23916 KB |
n=100 |
4 |
Correct |
15 ms |
23916 KB |
n=100 |
5 |
Correct |
17 ms |
23916 KB |
n=100 |
6 |
Correct |
16 ms |
23916 KB |
n=100 |
7 |
Correct |
16 ms |
23916 KB |
n=100 |
8 |
Correct |
17 ms |
23916 KB |
n=100 |
9 |
Correct |
17 ms |
23916 KB |
n=100 |
10 |
Correct |
16 ms |
23916 KB |
n=100 |
11 |
Correct |
17 ms |
23916 KB |
n=100 |
12 |
Correct |
15 ms |
23948 KB |
n=100 |
13 |
Correct |
16 ms |
23916 KB |
n=100 |
14 |
Correct |
16 ms |
23916 KB |
n=100 |
15 |
Correct |
16 ms |
24064 KB |
n=100 |
16 |
Correct |
15 ms |
23916 KB |
n=100 |
17 |
Correct |
15 ms |
23916 KB |
n=100 |
18 |
Correct |
16 ms |
23916 KB |
n=100 |
19 |
Correct |
18 ms |
23916 KB |
n=100 |
20 |
Correct |
15 ms |
23916 KB |
n=100 |
21 |
Correct |
15 ms |
23916 KB |
n=100 |
22 |
Correct |
16 ms |
23916 KB |
n=100 |
23 |
Correct |
15 ms |
23916 KB |
n=100 |
24 |
Correct |
16 ms |
23916 KB |
n=100 |
25 |
Correct |
15 ms |
23916 KB |
n=100 |
26 |
Correct |
16 ms |
23904 KB |
n=12 |
27 |
Correct |
15 ms |
23916 KB |
n=100 |
28 |
Correct |
16 ms |
23916 KB |
n=500 |
29 |
Correct |
17 ms |
23916 KB |
n=500 |
30 |
Correct |
16 ms |
23916 KB |
n=500 |
31 |
Correct |
16 ms |
23916 KB |
n=500 |
32 |
Correct |
16 ms |
23916 KB |
n=500 |
33 |
Correct |
16 ms |
23916 KB |
n=500 |
34 |
Correct |
18 ms |
23916 KB |
n=500 |
35 |
Correct |
18 ms |
23916 KB |
n=500 |
36 |
Correct |
19 ms |
23916 KB |
n=500 |
37 |
Correct |
16 ms |
23916 KB |
n=500 |
38 |
Correct |
16 ms |
23916 KB |
n=500 |
39 |
Correct |
16 ms |
23916 KB |
n=500 |
40 |
Correct |
16 ms |
23916 KB |
n=500 |
41 |
Correct |
18 ms |
23944 KB |
n=500 |
42 |
Correct |
16 ms |
23916 KB |
n=500 |
43 |
Correct |
16 ms |
23916 KB |
n=500 |
44 |
Correct |
17 ms |
23916 KB |
n=500 |
45 |
Correct |
17 ms |
23916 KB |
n=500 |
46 |
Correct |
18 ms |
23916 KB |
n=500 |
47 |
Correct |
16 ms |
23916 KB |
n=500 |
48 |
Correct |
17 ms |
23916 KB |
n=500 |
49 |
Correct |
16 ms |
23916 KB |
n=500 |
50 |
Correct |
16 ms |
23916 KB |
n=500 |
51 |
Correct |
17 ms |
23916 KB |
n=500 |
52 |
Correct |
17 ms |
23916 KB |
n=500 |
53 |
Correct |
18 ms |
24044 KB |
n=500 |
54 |
Correct |
16 ms |
23916 KB |
n=500 |
55 |
Correct |
17 ms |
23920 KB |
n=278 |
56 |
Correct |
17 ms |
23916 KB |
n=500 |
57 |
Correct |
16 ms |
23916 KB |
n=500 |
58 |
Correct |
16 ms |
23916 KB |
n=500 |
59 |
Correct |
20 ms |
24172 KB |
n=2000 |
60 |
Correct |
21 ms |
24300 KB |
n=2000 |
61 |
Correct |
22 ms |
24172 KB |
n=2000 |
62 |
Correct |
19 ms |
24172 KB |
n=2000 |
63 |
Correct |
20 ms |
24172 KB |
n=2000 |
64 |
Correct |
21 ms |
24172 KB |
n=2000 |
65 |
Correct |
21 ms |
24172 KB |
n=2000 |
66 |
Correct |
19 ms |
24300 KB |
n=2000 |
67 |
Correct |
22 ms |
24172 KB |
n=2000 |
68 |
Correct |
20 ms |
24180 KB |
n=2000 |
69 |
Correct |
18 ms |
24172 KB |
n=2000 |
70 |
Correct |
18 ms |
24176 KB |
n=2000 |
71 |
Correct |
18 ms |
24172 KB |
n=2000 |
72 |
Correct |
21 ms |
24172 KB |
n=2000 |
73 |
Correct |
19 ms |
24172 KB |
n=2000 |
74 |
Correct |
19 ms |
24172 KB |
n=1844 |
75 |
Correct |
20 ms |
24172 KB |
n=2000 |
76 |
Correct |
19 ms |
24172 KB |
n=2000 |
77 |
Correct |
19 ms |
24172 KB |
n=2000 |
78 |
Correct |
21 ms |
24172 KB |
n=2000 |
79 |
Correct |
22 ms |
24172 KB |
n=2000 |
80 |
Correct |
19 ms |
24300 KB |
n=2000 |
81 |
Correct |
19 ms |
24172 KB |
n=2000 |
82 |
Correct |
19 ms |
24172 KB |
n=2000 |
83 |
Correct |
21 ms |
24300 KB |
n=2000 |
84 |
Correct |
18 ms |
24172 KB |
n=2000 |
85 |
Correct |
19 ms |
24172 KB |
n=2000 |
86 |
Correct |
19 ms |
24172 KB |
n=2000 |
87 |
Correct |
18 ms |
24172 KB |
n=2000 |
88 |
Correct |
19 ms |
24300 KB |
n=2000 |
89 |
Correct |
19 ms |
24300 KB |
n=2000 |
90 |
Correct |
19 ms |
24300 KB |
n=2000 |
91 |
Correct |
18 ms |
24172 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23916 KB |
n=5 |
2 |
Correct |
16 ms |
23916 KB |
n=100 |
3 |
Correct |
16 ms |
23916 KB |
n=100 |
4 |
Correct |
15 ms |
23916 KB |
n=100 |
5 |
Correct |
17 ms |
23916 KB |
n=100 |
6 |
Correct |
16 ms |
23916 KB |
n=100 |
7 |
Correct |
16 ms |
23916 KB |
n=100 |
8 |
Correct |
17 ms |
23916 KB |
n=100 |
9 |
Correct |
17 ms |
23916 KB |
n=100 |
10 |
Correct |
16 ms |
23916 KB |
n=100 |
11 |
Correct |
17 ms |
23916 KB |
n=100 |
12 |
Correct |
15 ms |
23948 KB |
n=100 |
13 |
Correct |
16 ms |
23916 KB |
n=100 |
14 |
Correct |
16 ms |
23916 KB |
n=100 |
15 |
Correct |
16 ms |
24064 KB |
n=100 |
16 |
Correct |
15 ms |
23916 KB |
n=100 |
17 |
Correct |
15 ms |
23916 KB |
n=100 |
18 |
Correct |
16 ms |
23916 KB |
n=100 |
19 |
Correct |
18 ms |
23916 KB |
n=100 |
20 |
Correct |
15 ms |
23916 KB |
n=100 |
21 |
Correct |
15 ms |
23916 KB |
n=100 |
22 |
Correct |
16 ms |
23916 KB |
n=100 |
23 |
Correct |
15 ms |
23916 KB |
n=100 |
24 |
Correct |
16 ms |
23916 KB |
n=100 |
25 |
Correct |
15 ms |
23916 KB |
n=100 |
26 |
Correct |
16 ms |
23904 KB |
n=12 |
27 |
Correct |
15 ms |
23916 KB |
n=100 |
28 |
Correct |
16 ms |
23916 KB |
n=500 |
29 |
Correct |
17 ms |
23916 KB |
n=500 |
30 |
Correct |
16 ms |
23916 KB |
n=500 |
31 |
Correct |
16 ms |
23916 KB |
n=500 |
32 |
Correct |
16 ms |
23916 KB |
n=500 |
33 |
Correct |
16 ms |
23916 KB |
n=500 |
34 |
Correct |
18 ms |
23916 KB |
n=500 |
35 |
Correct |
18 ms |
23916 KB |
n=500 |
36 |
Correct |
19 ms |
23916 KB |
n=500 |
37 |
Correct |
16 ms |
23916 KB |
n=500 |
38 |
Correct |
16 ms |
23916 KB |
n=500 |
39 |
Correct |
16 ms |
23916 KB |
n=500 |
40 |
Correct |
16 ms |
23916 KB |
n=500 |
41 |
Correct |
18 ms |
23944 KB |
n=500 |
42 |
Correct |
16 ms |
23916 KB |
n=500 |
43 |
Correct |
16 ms |
23916 KB |
n=500 |
44 |
Correct |
17 ms |
23916 KB |
n=500 |
45 |
Correct |
17 ms |
23916 KB |
n=500 |
46 |
Correct |
18 ms |
23916 KB |
n=500 |
47 |
Correct |
16 ms |
23916 KB |
n=500 |
48 |
Correct |
17 ms |
23916 KB |
n=500 |
49 |
Correct |
16 ms |
23916 KB |
n=500 |
50 |
Correct |
16 ms |
23916 KB |
n=500 |
51 |
Correct |
17 ms |
23916 KB |
n=500 |
52 |
Correct |
17 ms |
23916 KB |
n=500 |
53 |
Correct |
18 ms |
24044 KB |
n=500 |
54 |
Correct |
16 ms |
23916 KB |
n=500 |
55 |
Correct |
17 ms |
23920 KB |
n=278 |
56 |
Correct |
17 ms |
23916 KB |
n=500 |
57 |
Correct |
16 ms |
23916 KB |
n=500 |
58 |
Correct |
16 ms |
23916 KB |
n=500 |
59 |
Correct |
20 ms |
24172 KB |
n=2000 |
60 |
Correct |
21 ms |
24300 KB |
n=2000 |
61 |
Correct |
22 ms |
24172 KB |
n=2000 |
62 |
Correct |
19 ms |
24172 KB |
n=2000 |
63 |
Correct |
20 ms |
24172 KB |
n=2000 |
64 |
Correct |
21 ms |
24172 KB |
n=2000 |
65 |
Correct |
21 ms |
24172 KB |
n=2000 |
66 |
Correct |
19 ms |
24300 KB |
n=2000 |
67 |
Correct |
22 ms |
24172 KB |
n=2000 |
68 |
Correct |
20 ms |
24180 KB |
n=2000 |
69 |
Correct |
18 ms |
24172 KB |
n=2000 |
70 |
Correct |
18 ms |
24176 KB |
n=2000 |
71 |
Correct |
18 ms |
24172 KB |
n=2000 |
72 |
Correct |
21 ms |
24172 KB |
n=2000 |
73 |
Correct |
19 ms |
24172 KB |
n=2000 |
74 |
Correct |
19 ms |
24172 KB |
n=1844 |
75 |
Correct |
20 ms |
24172 KB |
n=2000 |
76 |
Correct |
19 ms |
24172 KB |
n=2000 |
77 |
Correct |
19 ms |
24172 KB |
n=2000 |
78 |
Correct |
21 ms |
24172 KB |
n=2000 |
79 |
Correct |
22 ms |
24172 KB |
n=2000 |
80 |
Correct |
19 ms |
24300 KB |
n=2000 |
81 |
Correct |
19 ms |
24172 KB |
n=2000 |
82 |
Correct |
19 ms |
24172 KB |
n=2000 |
83 |
Correct |
21 ms |
24300 KB |
n=2000 |
84 |
Correct |
18 ms |
24172 KB |
n=2000 |
85 |
Correct |
19 ms |
24172 KB |
n=2000 |
86 |
Correct |
19 ms |
24172 KB |
n=2000 |
87 |
Correct |
18 ms |
24172 KB |
n=2000 |
88 |
Correct |
19 ms |
24300 KB |
n=2000 |
89 |
Correct |
19 ms |
24300 KB |
n=2000 |
90 |
Correct |
19 ms |
24300 KB |
n=2000 |
91 |
Correct |
18 ms |
24172 KB |
n=2000 |
92 |
Correct |
678 ms |
54212 KB |
n=200000 |
93 |
Correct |
869 ms |
57792 KB |
n=200000 |
94 |
Correct |
823 ms |
61124 KB |
n=200000 |
95 |
Correct |
635 ms |
53880 KB |
n=200000 |
96 |
Correct |
593 ms |
54136 KB |
n=200000 |
97 |
Correct |
902 ms |
56940 KB |
n=200000 |
98 |
Correct |
632 ms |
54112 KB |
n=200000 |
99 |
Correct |
852 ms |
53612 KB |
n=200000 |
100 |
Correct |
634 ms |
54244 KB |
n=200000 |
101 |
Correct |
811 ms |
62328 KB |
n=200000 |
102 |
Correct |
410 ms |
54892 KB |
n=200000 |
103 |
Correct |
399 ms |
55020 KB |
n=200000 |
104 |
Correct |
416 ms |
55020 KB |
n=200000 |
105 |
Correct |
407 ms |
54636 KB |
n=200000 |
106 |
Correct |
412 ms |
54636 KB |
n=200000 |
107 |
Correct |
444 ms |
54636 KB |
n=200000 |
108 |
Correct |
795 ms |
53740 KB |
n=200000 |
109 |
Correct |
764 ms |
53612 KB |
n=200000 |
110 |
Correct |
796 ms |
53868 KB |
n=200000 |
111 |
Correct |
618 ms |
53860 KB |
n=200000 |
112 |
Correct |
791 ms |
61292 KB |
n=200000 |
113 |
Correct |
875 ms |
56940 KB |
n=200000 |
114 |
Correct |
649 ms |
53912 KB |
n=200000 |
115 |
Correct |
1020 ms |
54892 KB |
n=200000 |
116 |
Correct |
600 ms |
53764 KB |
n=200000 |
117 |
Correct |
775 ms |
61740 KB |
n=200000 |
118 |
Correct |
871 ms |
55660 KB |
n=200000 |
119 |
Correct |
622 ms |
53728 KB |
n=200000 |
120 |
Correct |
792 ms |
62136 KB |
n=200000 |
121 |
Correct |
800 ms |
62096 KB |
n=200000 |
122 |
Correct |
835 ms |
62572 KB |
n=200000 |
123 |
Correct |
414 ms |
54380 KB |
n=200000 |
124 |
Correct |
248 ms |
35180 KB |
n=25264 |