#include<bits/stdc++.h>
using namespace std;
const int MAXN=200005,LOG=18;
vector<int> adj[MAXN];
int depth[MAXN],pa[LOG][MAXN],a[MAXN];
set<int> sendiri[MAXN],berdua[MAXN];
void dfs(int now,int par){
for(auto nxt : adj[now]){
if(nxt==par)continue;
depth[nxt]=depth[now]+1;
pa[0][nxt]=now;
for(int i=1;i<LOG;i++)pa[i][nxt]=pa[i-1][pa[i-1][nxt]];
dfs(nxt,now);
}
}
int LCA(int u,int v){
if(depth[u]<depth[v])swap(u,v);
int diff=depth[u]-depth[v];
for(int i=LOG-1;i>=0;i--){
if(diff&(1<<i))u=pa[i][u];
}
if(u==v)return u;
for(int i=LOG-1;i>=0;i--){
if(pa[i][u]!=pa[i][v]){
u=pa[i][u];
v=pa[i][v];
}
}
return pa[0][u];
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n,m,q,op,x,y,u,v;
cin >> n >> m >> q;
for(int i=1;i<n;i++){
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(1,-1);
for(int i=1;i<=m;i++){
cin >> a[i];
sendiri[a[i]].insert(i);
if(i>=2){
berdua[LCA(a[i-1],a[i])].insert(i-1);
}
}
while(q--){
cin >> op >> x >> y;
if(op==1){
sendiri[a[x]].erase(x);
if(x>=2)berdua[LCA(a[x],a[x-1])].erase(x-1);
if(x<=m-1)berdua[LCA(a[x],a[x+1])].erase(x);
a[x]=y;
sendiri[a[x]].insert(x);
if(x>=2)berdua[LCA(a[x],a[x-1])].insert(x-1);
if(x<=m-1)berdua[LCA(a[x],a[x+1])].insert(x);
}
else{
cin >> v;
bool sudah=false;
auto it=sendiri[v].lower_bound(x);
auto it2=berdua[v].lower_bound(x);
if(it!=sendiri[v].end() && *it<=y){
cout << *it << " " << *it << '\n';
}
else if(it2!=berdua[v].end() && *it2<=y-1){
cout << *it2 << " " << (*it2)+1 << '\n';
}
else{
cout << -1 << " " << -1 << '\n';
}
}
}
return 0;
}
Compilation message
treearray.cpp: In function 'int main()':
treearray.cpp:65:9: warning: unused variable 'sudah' [-Wunused-variable]
65 | bool sudah=false;
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23916 KB |
n=5 |
2 |
Correct |
17 ms |
23916 KB |
n=100 |
3 |
Correct |
16 ms |
23916 KB |
n=100 |
4 |
Correct |
16 ms |
23916 KB |
n=100 |
5 |
Correct |
16 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 |
23940 KB |
n=100 |
11 |
Correct |
16 ms |
23916 KB |
n=100 |
12 |
Correct |
16 ms |
23916 KB |
n=100 |
13 |
Correct |
17 ms |
23916 KB |
n=100 |
14 |
Correct |
16 ms |
23916 KB |
n=100 |
15 |
Correct |
17 ms |
23916 KB |
n=100 |
16 |
Correct |
17 ms |
23912 KB |
n=100 |
17 |
Correct |
16 ms |
23916 KB |
n=100 |
18 |
Correct |
17 ms |
23916 KB |
n=100 |
19 |
Correct |
16 ms |
23916 KB |
n=100 |
20 |
Correct |
17 ms |
23916 KB |
n=100 |
21 |
Correct |
17 ms |
23916 KB |
n=100 |
22 |
Correct |
17 ms |
23916 KB |
n=100 |
23 |
Correct |
17 ms |
23916 KB |
n=100 |
24 |
Correct |
19 ms |
23916 KB |
n=100 |
25 |
Correct |
17 ms |
23916 KB |
n=100 |
26 |
Correct |
17 ms |
23916 KB |
n=12 |
27 |
Correct |
18 ms |
23916 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23916 KB |
n=5 |
2 |
Correct |
17 ms |
23916 KB |
n=100 |
3 |
Correct |
16 ms |
23916 KB |
n=100 |
4 |
Correct |
16 ms |
23916 KB |
n=100 |
5 |
Correct |
16 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 |
23940 KB |
n=100 |
11 |
Correct |
16 ms |
23916 KB |
n=100 |
12 |
Correct |
16 ms |
23916 KB |
n=100 |
13 |
Correct |
17 ms |
23916 KB |
n=100 |
14 |
Correct |
16 ms |
23916 KB |
n=100 |
15 |
Correct |
17 ms |
23916 KB |
n=100 |
16 |
Correct |
17 ms |
23912 KB |
n=100 |
17 |
Correct |
16 ms |
23916 KB |
n=100 |
18 |
Correct |
17 ms |
23916 KB |
n=100 |
19 |
Correct |
16 ms |
23916 KB |
n=100 |
20 |
Correct |
17 ms |
23916 KB |
n=100 |
21 |
Correct |
17 ms |
23916 KB |
n=100 |
22 |
Correct |
17 ms |
23916 KB |
n=100 |
23 |
Correct |
17 ms |
23916 KB |
n=100 |
24 |
Correct |
19 ms |
23916 KB |
n=100 |
25 |
Correct |
17 ms |
23916 KB |
n=100 |
26 |
Correct |
17 ms |
23916 KB |
n=12 |
27 |
Correct |
18 ms |
23916 KB |
n=100 |
28 |
Correct |
17 ms |
24044 KB |
n=500 |
29 |
Correct |
17 ms |
24044 KB |
n=500 |
30 |
Correct |
17 ms |
24044 KB |
n=500 |
31 |
Correct |
17 ms |
24044 KB |
n=500 |
32 |
Correct |
17 ms |
24044 KB |
n=500 |
33 |
Correct |
17 ms |
24044 KB |
n=500 |
34 |
Correct |
17 ms |
24044 KB |
n=500 |
35 |
Correct |
18 ms |
24044 KB |
n=500 |
36 |
Correct |
17 ms |
24044 KB |
n=500 |
37 |
Correct |
18 ms |
24044 KB |
n=500 |
38 |
Correct |
17 ms |
24044 KB |
n=500 |
39 |
Correct |
17 ms |
24084 KB |
n=500 |
40 |
Correct |
17 ms |
24044 KB |
n=500 |
41 |
Correct |
17 ms |
24044 KB |
n=500 |
42 |
Correct |
17 ms |
24044 KB |
n=500 |
43 |
Correct |
17 ms |
24044 KB |
n=500 |
44 |
Correct |
17 ms |
24044 KB |
n=500 |
45 |
Correct |
17 ms |
24044 KB |
n=500 |
46 |
Correct |
17 ms |
24044 KB |
n=500 |
47 |
Correct |
17 ms |
24044 KB |
n=500 |
48 |
Correct |
17 ms |
24044 KB |
n=500 |
49 |
Correct |
17 ms |
24044 KB |
n=500 |
50 |
Correct |
17 ms |
24044 KB |
n=500 |
51 |
Correct |
17 ms |
24044 KB |
n=500 |
52 |
Correct |
17 ms |
24044 KB |
n=500 |
53 |
Correct |
17 ms |
24044 KB |
n=500 |
54 |
Correct |
17 ms |
24044 KB |
n=500 |
55 |
Correct |
17 ms |
24044 KB |
n=278 |
56 |
Correct |
17 ms |
24044 KB |
n=500 |
57 |
Correct |
17 ms |
24044 KB |
n=500 |
58 |
Correct |
17 ms |
24044 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23916 KB |
n=5 |
2 |
Correct |
17 ms |
23916 KB |
n=100 |
3 |
Correct |
16 ms |
23916 KB |
n=100 |
4 |
Correct |
16 ms |
23916 KB |
n=100 |
5 |
Correct |
16 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 |
23940 KB |
n=100 |
11 |
Correct |
16 ms |
23916 KB |
n=100 |
12 |
Correct |
16 ms |
23916 KB |
n=100 |
13 |
Correct |
17 ms |
23916 KB |
n=100 |
14 |
Correct |
16 ms |
23916 KB |
n=100 |
15 |
Correct |
17 ms |
23916 KB |
n=100 |
16 |
Correct |
17 ms |
23912 KB |
n=100 |
17 |
Correct |
16 ms |
23916 KB |
n=100 |
18 |
Correct |
17 ms |
23916 KB |
n=100 |
19 |
Correct |
16 ms |
23916 KB |
n=100 |
20 |
Correct |
17 ms |
23916 KB |
n=100 |
21 |
Correct |
17 ms |
23916 KB |
n=100 |
22 |
Correct |
17 ms |
23916 KB |
n=100 |
23 |
Correct |
17 ms |
23916 KB |
n=100 |
24 |
Correct |
19 ms |
23916 KB |
n=100 |
25 |
Correct |
17 ms |
23916 KB |
n=100 |
26 |
Correct |
17 ms |
23916 KB |
n=12 |
27 |
Correct |
18 ms |
23916 KB |
n=100 |
28 |
Correct |
17 ms |
24044 KB |
n=500 |
29 |
Correct |
17 ms |
24044 KB |
n=500 |
30 |
Correct |
17 ms |
24044 KB |
n=500 |
31 |
Correct |
17 ms |
24044 KB |
n=500 |
32 |
Correct |
17 ms |
24044 KB |
n=500 |
33 |
Correct |
17 ms |
24044 KB |
n=500 |
34 |
Correct |
17 ms |
24044 KB |
n=500 |
35 |
Correct |
18 ms |
24044 KB |
n=500 |
36 |
Correct |
17 ms |
24044 KB |
n=500 |
37 |
Correct |
18 ms |
24044 KB |
n=500 |
38 |
Correct |
17 ms |
24044 KB |
n=500 |
39 |
Correct |
17 ms |
24084 KB |
n=500 |
40 |
Correct |
17 ms |
24044 KB |
n=500 |
41 |
Correct |
17 ms |
24044 KB |
n=500 |
42 |
Correct |
17 ms |
24044 KB |
n=500 |
43 |
Correct |
17 ms |
24044 KB |
n=500 |
44 |
Correct |
17 ms |
24044 KB |
n=500 |
45 |
Correct |
17 ms |
24044 KB |
n=500 |
46 |
Correct |
17 ms |
24044 KB |
n=500 |
47 |
Correct |
17 ms |
24044 KB |
n=500 |
48 |
Correct |
17 ms |
24044 KB |
n=500 |
49 |
Correct |
17 ms |
24044 KB |
n=500 |
50 |
Correct |
17 ms |
24044 KB |
n=500 |
51 |
Correct |
17 ms |
24044 KB |
n=500 |
52 |
Correct |
17 ms |
24044 KB |
n=500 |
53 |
Correct |
17 ms |
24044 KB |
n=500 |
54 |
Correct |
17 ms |
24044 KB |
n=500 |
55 |
Correct |
17 ms |
24044 KB |
n=278 |
56 |
Correct |
17 ms |
24044 KB |
n=500 |
57 |
Correct |
17 ms |
24044 KB |
n=500 |
58 |
Correct |
17 ms |
24044 KB |
n=500 |
59 |
Correct |
20 ms |
24300 KB |
n=2000 |
60 |
Correct |
20 ms |
24556 KB |
n=2000 |
61 |
Correct |
21 ms |
24428 KB |
n=2000 |
62 |
Correct |
20 ms |
24428 KB |
n=2000 |
63 |
Correct |
20 ms |
24300 KB |
n=2000 |
64 |
Correct |
22 ms |
24428 KB |
n=2000 |
65 |
Correct |
20 ms |
24300 KB |
n=2000 |
66 |
Correct |
20 ms |
24448 KB |
n=2000 |
67 |
Correct |
20 ms |
24300 KB |
n=2000 |
68 |
Correct |
20 ms |
24428 KB |
n=2000 |
69 |
Correct |
19 ms |
24300 KB |
n=2000 |
70 |
Correct |
19 ms |
24300 KB |
n=2000 |
71 |
Correct |
19 ms |
24300 KB |
n=2000 |
72 |
Correct |
22 ms |
24300 KB |
n=2000 |
73 |
Correct |
19 ms |
24300 KB |
n=2000 |
74 |
Correct |
20 ms |
24300 KB |
n=1844 |
75 |
Correct |
19 ms |
24300 KB |
n=2000 |
76 |
Correct |
21 ms |
24300 KB |
n=2000 |
77 |
Correct |
20 ms |
24300 KB |
n=2000 |
78 |
Correct |
20 ms |
24300 KB |
n=2000 |
79 |
Correct |
20 ms |
24300 KB |
n=2000 |
80 |
Correct |
20 ms |
24428 KB |
n=2000 |
81 |
Correct |
20 ms |
24428 KB |
n=2000 |
82 |
Correct |
20 ms |
24300 KB |
n=2000 |
83 |
Correct |
20 ms |
24428 KB |
n=2000 |
84 |
Correct |
20 ms |
24300 KB |
n=2000 |
85 |
Correct |
22 ms |
24428 KB |
n=2000 |
86 |
Correct |
20 ms |
24428 KB |
n=2000 |
87 |
Correct |
20 ms |
24428 KB |
n=2000 |
88 |
Correct |
20 ms |
24556 KB |
n=2000 |
89 |
Correct |
20 ms |
24556 KB |
n=2000 |
90 |
Correct |
21 ms |
24556 KB |
n=2000 |
91 |
Correct |
19 ms |
24300 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23916 KB |
n=5 |
2 |
Correct |
17 ms |
23916 KB |
n=100 |
3 |
Correct |
16 ms |
23916 KB |
n=100 |
4 |
Correct |
16 ms |
23916 KB |
n=100 |
5 |
Correct |
16 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 |
23940 KB |
n=100 |
11 |
Correct |
16 ms |
23916 KB |
n=100 |
12 |
Correct |
16 ms |
23916 KB |
n=100 |
13 |
Correct |
17 ms |
23916 KB |
n=100 |
14 |
Correct |
16 ms |
23916 KB |
n=100 |
15 |
Correct |
17 ms |
23916 KB |
n=100 |
16 |
Correct |
17 ms |
23912 KB |
n=100 |
17 |
Correct |
16 ms |
23916 KB |
n=100 |
18 |
Correct |
17 ms |
23916 KB |
n=100 |
19 |
Correct |
16 ms |
23916 KB |
n=100 |
20 |
Correct |
17 ms |
23916 KB |
n=100 |
21 |
Correct |
17 ms |
23916 KB |
n=100 |
22 |
Correct |
17 ms |
23916 KB |
n=100 |
23 |
Correct |
17 ms |
23916 KB |
n=100 |
24 |
Correct |
19 ms |
23916 KB |
n=100 |
25 |
Correct |
17 ms |
23916 KB |
n=100 |
26 |
Correct |
17 ms |
23916 KB |
n=12 |
27 |
Correct |
18 ms |
23916 KB |
n=100 |
28 |
Correct |
17 ms |
24044 KB |
n=500 |
29 |
Correct |
17 ms |
24044 KB |
n=500 |
30 |
Correct |
17 ms |
24044 KB |
n=500 |
31 |
Correct |
17 ms |
24044 KB |
n=500 |
32 |
Correct |
17 ms |
24044 KB |
n=500 |
33 |
Correct |
17 ms |
24044 KB |
n=500 |
34 |
Correct |
17 ms |
24044 KB |
n=500 |
35 |
Correct |
18 ms |
24044 KB |
n=500 |
36 |
Correct |
17 ms |
24044 KB |
n=500 |
37 |
Correct |
18 ms |
24044 KB |
n=500 |
38 |
Correct |
17 ms |
24044 KB |
n=500 |
39 |
Correct |
17 ms |
24084 KB |
n=500 |
40 |
Correct |
17 ms |
24044 KB |
n=500 |
41 |
Correct |
17 ms |
24044 KB |
n=500 |
42 |
Correct |
17 ms |
24044 KB |
n=500 |
43 |
Correct |
17 ms |
24044 KB |
n=500 |
44 |
Correct |
17 ms |
24044 KB |
n=500 |
45 |
Correct |
17 ms |
24044 KB |
n=500 |
46 |
Correct |
17 ms |
24044 KB |
n=500 |
47 |
Correct |
17 ms |
24044 KB |
n=500 |
48 |
Correct |
17 ms |
24044 KB |
n=500 |
49 |
Correct |
17 ms |
24044 KB |
n=500 |
50 |
Correct |
17 ms |
24044 KB |
n=500 |
51 |
Correct |
17 ms |
24044 KB |
n=500 |
52 |
Correct |
17 ms |
24044 KB |
n=500 |
53 |
Correct |
17 ms |
24044 KB |
n=500 |
54 |
Correct |
17 ms |
24044 KB |
n=500 |
55 |
Correct |
17 ms |
24044 KB |
n=278 |
56 |
Correct |
17 ms |
24044 KB |
n=500 |
57 |
Correct |
17 ms |
24044 KB |
n=500 |
58 |
Correct |
17 ms |
24044 KB |
n=500 |
59 |
Correct |
20 ms |
24300 KB |
n=2000 |
60 |
Correct |
20 ms |
24556 KB |
n=2000 |
61 |
Correct |
21 ms |
24428 KB |
n=2000 |
62 |
Correct |
20 ms |
24428 KB |
n=2000 |
63 |
Correct |
20 ms |
24300 KB |
n=2000 |
64 |
Correct |
22 ms |
24428 KB |
n=2000 |
65 |
Correct |
20 ms |
24300 KB |
n=2000 |
66 |
Correct |
20 ms |
24448 KB |
n=2000 |
67 |
Correct |
20 ms |
24300 KB |
n=2000 |
68 |
Correct |
20 ms |
24428 KB |
n=2000 |
69 |
Correct |
19 ms |
24300 KB |
n=2000 |
70 |
Correct |
19 ms |
24300 KB |
n=2000 |
71 |
Correct |
19 ms |
24300 KB |
n=2000 |
72 |
Correct |
22 ms |
24300 KB |
n=2000 |
73 |
Correct |
19 ms |
24300 KB |
n=2000 |
74 |
Correct |
20 ms |
24300 KB |
n=1844 |
75 |
Correct |
19 ms |
24300 KB |
n=2000 |
76 |
Correct |
21 ms |
24300 KB |
n=2000 |
77 |
Correct |
20 ms |
24300 KB |
n=2000 |
78 |
Correct |
20 ms |
24300 KB |
n=2000 |
79 |
Correct |
20 ms |
24300 KB |
n=2000 |
80 |
Correct |
20 ms |
24428 KB |
n=2000 |
81 |
Correct |
20 ms |
24428 KB |
n=2000 |
82 |
Correct |
20 ms |
24300 KB |
n=2000 |
83 |
Correct |
20 ms |
24428 KB |
n=2000 |
84 |
Correct |
20 ms |
24300 KB |
n=2000 |
85 |
Correct |
22 ms |
24428 KB |
n=2000 |
86 |
Correct |
20 ms |
24428 KB |
n=2000 |
87 |
Correct |
20 ms |
24428 KB |
n=2000 |
88 |
Correct |
20 ms |
24556 KB |
n=2000 |
89 |
Correct |
20 ms |
24556 KB |
n=2000 |
90 |
Correct |
21 ms |
24556 KB |
n=2000 |
91 |
Correct |
19 ms |
24300 KB |
n=2000 |
92 |
Correct |
1085 ms |
66616 KB |
n=200000 |
93 |
Correct |
1241 ms |
73332 KB |
n=200000 |
94 |
Correct |
1170 ms |
78956 KB |
n=200000 |
95 |
Correct |
1022 ms |
66352 KB |
n=200000 |
96 |
Correct |
1028 ms |
66400 KB |
n=200000 |
97 |
Correct |
1251 ms |
71944 KB |
n=200000 |
98 |
Correct |
1029 ms |
66492 KB |
n=200000 |
99 |
Correct |
1275 ms |
65956 KB |
n=200000 |
100 |
Correct |
1066 ms |
66520 KB |
n=200000 |
101 |
Correct |
1158 ms |
81004 KB |
n=200000 |
102 |
Correct |
614 ms |
67308 KB |
n=200000 |
103 |
Correct |
598 ms |
67436 KB |
n=200000 |
104 |
Correct |
602 ms |
67308 KB |
n=200000 |
105 |
Correct |
606 ms |
67180 KB |
n=200000 |
106 |
Correct |
601 ms |
67180 KB |
n=200000 |
107 |
Correct |
598 ms |
67308 KB |
n=200000 |
108 |
Correct |
1133 ms |
66156 KB |
n=200000 |
109 |
Correct |
1133 ms |
66284 KB |
n=200000 |
110 |
Correct |
1135 ms |
66372 KB |
n=200000 |
111 |
Correct |
1057 ms |
66412 KB |
n=200000 |
112 |
Correct |
1167 ms |
79276 KB |
n=200000 |
113 |
Correct |
1257 ms |
71816 KB |
n=200000 |
114 |
Correct |
1050 ms |
66312 KB |
n=200000 |
115 |
Correct |
1398 ms |
68252 KB |
n=200000 |
116 |
Correct |
979 ms |
66164 KB |
n=200000 |
117 |
Correct |
1144 ms |
80192 KB |
n=200000 |
118 |
Correct |
1301 ms |
69996 KB |
n=200000 |
119 |
Correct |
983 ms |
66140 KB |
n=200000 |
120 |
Correct |
1104 ms |
80948 KB |
n=200000 |
121 |
Correct |
1105 ms |
80784 KB |
n=200000 |
122 |
Correct |
1100 ms |
81388 KB |
n=200000 |
123 |
Correct |
637 ms |
66796 KB |
n=200000 |
124 |
Correct |
273 ms |
37356 KB |
n=25264 |