#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define ft first
#define sc second
using namespace std;
const int mod=1e9+7,INF=1e17;
vector<int> v[200005];
int tin[200005],tout[200005],a[200005],cnt=1,up[200005][20];
set<pair<int,int>> s[200005];
void dfs(int x,int p){
tin[x]=cnt++;
up[x][0]=p;
for(int i=1;i<20;i++){
up[x][i]=up[up[x][i-1]][i-1];
}
for(auto w : v[x]){
if(w==p){
continue;
}
else{
dfs(w,x);
}
}
tout[x]=cnt++;
}
bool is_up(int x,int y){
return tin[x]<=tin[y] && tout[x]>=tout[y];
}
int lca(int x,int y){
if(is_up(x,y)){
return x;
}
if(is_up(y,x)){
return y;
}
for(int i=19;i>=0;i--){
if(!is_up(up[x][i],y)){
x=up[x][i];
}
}
return up[x][0];
}
main(){
int n,m,q,x1,y1;
cin >> n >> m >> q;
for(int i=1;i<n;i++){
cin >> x1 >> y1;
v[x1].push_back(y1);
v[y1].push_back(x1);
}
dfs(1,1);
for(int i=1;i<=m;i++){
cin >> a[i];
if(i>1){
int lc=lca(a[i],a[i-1]);
s[lc].insert({i-1,i});
}
s[a[i]].insert({i,i});
}
while(q--){
int type;
cin >> type;
if(type==2){
int l,r,ver;
cin >> l >> r >> ver;
auto it=s[ver].lower_bound({l,0});
if(it == s[ver].end() || it->sc > r){
cout << "-1 -1" << endl;
}
else{
cout << it->ft << " " << it->sc << endl;
}
}
else{
int pos,val;
cin >> pos >> val;
s[a[pos]].erase({pos,pos});
if (pos > 1){
int lc = lca(a[pos],a[pos-1]);
s[lc].erase({pos-1,pos});
}
if (pos < m){
int lc = lca(a[pos],a[pos+1]);
s[lc].erase({pos,pos+1});
}
a[pos] = val;
s[a[pos]].insert({pos,pos});
if (pos > 1){
int lc = lca(a[pos],a[pos-1]);
s[lc].insert({pos-1,pos});
}
if (pos < m){
int lc = lca(a[pos],a[pos+1]);
s[lc].insert({pos,pos+1});
}
}
}
}
Compilation message
treearray.cpp:49:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
49 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14412 KB |
n=5 |
2 |
Correct |
7 ms |
14392 KB |
n=100 |
3 |
Correct |
7 ms |
14412 KB |
n=100 |
4 |
Correct |
8 ms |
14396 KB |
n=100 |
5 |
Correct |
8 ms |
14412 KB |
n=100 |
6 |
Correct |
8 ms |
14392 KB |
n=100 |
7 |
Correct |
8 ms |
14412 KB |
n=100 |
8 |
Correct |
8 ms |
14372 KB |
n=100 |
9 |
Correct |
7 ms |
14412 KB |
n=100 |
10 |
Correct |
7 ms |
14396 KB |
n=100 |
11 |
Correct |
7 ms |
14384 KB |
n=100 |
12 |
Correct |
7 ms |
14416 KB |
n=100 |
13 |
Correct |
8 ms |
14412 KB |
n=100 |
14 |
Correct |
10 ms |
14396 KB |
n=100 |
15 |
Correct |
8 ms |
14412 KB |
n=100 |
16 |
Correct |
7 ms |
14412 KB |
n=100 |
17 |
Correct |
11 ms |
14452 KB |
n=100 |
18 |
Correct |
8 ms |
14400 KB |
n=100 |
19 |
Correct |
8 ms |
14412 KB |
n=100 |
20 |
Correct |
7 ms |
14412 KB |
n=100 |
21 |
Correct |
10 ms |
14424 KB |
n=100 |
22 |
Correct |
7 ms |
14392 KB |
n=100 |
23 |
Correct |
8 ms |
14392 KB |
n=100 |
24 |
Correct |
7 ms |
14412 KB |
n=100 |
25 |
Correct |
8 ms |
14412 KB |
n=100 |
26 |
Correct |
7 ms |
14312 KB |
n=12 |
27 |
Correct |
8 ms |
14412 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14412 KB |
n=5 |
2 |
Correct |
7 ms |
14392 KB |
n=100 |
3 |
Correct |
7 ms |
14412 KB |
n=100 |
4 |
Correct |
8 ms |
14396 KB |
n=100 |
5 |
Correct |
8 ms |
14412 KB |
n=100 |
6 |
Correct |
8 ms |
14392 KB |
n=100 |
7 |
Correct |
8 ms |
14412 KB |
n=100 |
8 |
Correct |
8 ms |
14372 KB |
n=100 |
9 |
Correct |
7 ms |
14412 KB |
n=100 |
10 |
Correct |
7 ms |
14396 KB |
n=100 |
11 |
Correct |
7 ms |
14384 KB |
n=100 |
12 |
Correct |
7 ms |
14416 KB |
n=100 |
13 |
Correct |
8 ms |
14412 KB |
n=100 |
14 |
Correct |
10 ms |
14396 KB |
n=100 |
15 |
Correct |
8 ms |
14412 KB |
n=100 |
16 |
Correct |
7 ms |
14412 KB |
n=100 |
17 |
Correct |
11 ms |
14452 KB |
n=100 |
18 |
Correct |
8 ms |
14400 KB |
n=100 |
19 |
Correct |
8 ms |
14412 KB |
n=100 |
20 |
Correct |
7 ms |
14412 KB |
n=100 |
21 |
Correct |
10 ms |
14424 KB |
n=100 |
22 |
Correct |
7 ms |
14392 KB |
n=100 |
23 |
Correct |
8 ms |
14392 KB |
n=100 |
24 |
Correct |
7 ms |
14412 KB |
n=100 |
25 |
Correct |
8 ms |
14412 KB |
n=100 |
26 |
Correct |
7 ms |
14312 KB |
n=12 |
27 |
Correct |
8 ms |
14412 KB |
n=100 |
28 |
Correct |
9 ms |
14540 KB |
n=500 |
29 |
Correct |
9 ms |
14572 KB |
n=500 |
30 |
Correct |
11 ms |
14532 KB |
n=500 |
31 |
Correct |
9 ms |
14532 KB |
n=500 |
32 |
Correct |
9 ms |
14540 KB |
n=500 |
33 |
Correct |
8 ms |
14540 KB |
n=500 |
34 |
Correct |
9 ms |
14540 KB |
n=500 |
35 |
Correct |
9 ms |
14540 KB |
n=500 |
36 |
Correct |
9 ms |
14508 KB |
n=500 |
37 |
Correct |
9 ms |
14540 KB |
n=500 |
38 |
Correct |
9 ms |
14528 KB |
n=500 |
39 |
Correct |
9 ms |
14540 KB |
n=500 |
40 |
Correct |
9 ms |
14572 KB |
n=500 |
41 |
Correct |
10 ms |
14524 KB |
n=500 |
42 |
Correct |
11 ms |
14540 KB |
n=500 |
43 |
Correct |
8 ms |
14528 KB |
n=500 |
44 |
Correct |
9 ms |
14524 KB |
n=500 |
45 |
Correct |
8 ms |
14540 KB |
n=500 |
46 |
Correct |
9 ms |
14588 KB |
n=500 |
47 |
Correct |
9 ms |
14540 KB |
n=500 |
48 |
Correct |
10 ms |
14540 KB |
n=500 |
49 |
Correct |
8 ms |
14540 KB |
n=500 |
50 |
Correct |
8 ms |
14536 KB |
n=500 |
51 |
Correct |
9 ms |
14540 KB |
n=500 |
52 |
Correct |
8 ms |
14552 KB |
n=500 |
53 |
Correct |
9 ms |
14504 KB |
n=500 |
54 |
Correct |
9 ms |
14540 KB |
n=500 |
55 |
Correct |
8 ms |
14540 KB |
n=278 |
56 |
Correct |
9 ms |
14540 KB |
n=500 |
57 |
Correct |
9 ms |
14532 KB |
n=500 |
58 |
Correct |
9 ms |
14540 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14412 KB |
n=5 |
2 |
Correct |
7 ms |
14392 KB |
n=100 |
3 |
Correct |
7 ms |
14412 KB |
n=100 |
4 |
Correct |
8 ms |
14396 KB |
n=100 |
5 |
Correct |
8 ms |
14412 KB |
n=100 |
6 |
Correct |
8 ms |
14392 KB |
n=100 |
7 |
Correct |
8 ms |
14412 KB |
n=100 |
8 |
Correct |
8 ms |
14372 KB |
n=100 |
9 |
Correct |
7 ms |
14412 KB |
n=100 |
10 |
Correct |
7 ms |
14396 KB |
n=100 |
11 |
Correct |
7 ms |
14384 KB |
n=100 |
12 |
Correct |
7 ms |
14416 KB |
n=100 |
13 |
Correct |
8 ms |
14412 KB |
n=100 |
14 |
Correct |
10 ms |
14396 KB |
n=100 |
15 |
Correct |
8 ms |
14412 KB |
n=100 |
16 |
Correct |
7 ms |
14412 KB |
n=100 |
17 |
Correct |
11 ms |
14452 KB |
n=100 |
18 |
Correct |
8 ms |
14400 KB |
n=100 |
19 |
Correct |
8 ms |
14412 KB |
n=100 |
20 |
Correct |
7 ms |
14412 KB |
n=100 |
21 |
Correct |
10 ms |
14424 KB |
n=100 |
22 |
Correct |
7 ms |
14392 KB |
n=100 |
23 |
Correct |
8 ms |
14392 KB |
n=100 |
24 |
Correct |
7 ms |
14412 KB |
n=100 |
25 |
Correct |
8 ms |
14412 KB |
n=100 |
26 |
Correct |
7 ms |
14312 KB |
n=12 |
27 |
Correct |
8 ms |
14412 KB |
n=100 |
28 |
Correct |
9 ms |
14540 KB |
n=500 |
29 |
Correct |
9 ms |
14572 KB |
n=500 |
30 |
Correct |
11 ms |
14532 KB |
n=500 |
31 |
Correct |
9 ms |
14532 KB |
n=500 |
32 |
Correct |
9 ms |
14540 KB |
n=500 |
33 |
Correct |
8 ms |
14540 KB |
n=500 |
34 |
Correct |
9 ms |
14540 KB |
n=500 |
35 |
Correct |
9 ms |
14540 KB |
n=500 |
36 |
Correct |
9 ms |
14508 KB |
n=500 |
37 |
Correct |
9 ms |
14540 KB |
n=500 |
38 |
Correct |
9 ms |
14528 KB |
n=500 |
39 |
Correct |
9 ms |
14540 KB |
n=500 |
40 |
Correct |
9 ms |
14572 KB |
n=500 |
41 |
Correct |
10 ms |
14524 KB |
n=500 |
42 |
Correct |
11 ms |
14540 KB |
n=500 |
43 |
Correct |
8 ms |
14528 KB |
n=500 |
44 |
Correct |
9 ms |
14524 KB |
n=500 |
45 |
Correct |
8 ms |
14540 KB |
n=500 |
46 |
Correct |
9 ms |
14588 KB |
n=500 |
47 |
Correct |
9 ms |
14540 KB |
n=500 |
48 |
Correct |
10 ms |
14540 KB |
n=500 |
49 |
Correct |
8 ms |
14540 KB |
n=500 |
50 |
Correct |
8 ms |
14536 KB |
n=500 |
51 |
Correct |
9 ms |
14540 KB |
n=500 |
52 |
Correct |
8 ms |
14552 KB |
n=500 |
53 |
Correct |
9 ms |
14504 KB |
n=500 |
54 |
Correct |
9 ms |
14540 KB |
n=500 |
55 |
Correct |
8 ms |
14540 KB |
n=278 |
56 |
Correct |
9 ms |
14540 KB |
n=500 |
57 |
Correct |
9 ms |
14532 KB |
n=500 |
58 |
Correct |
9 ms |
14540 KB |
n=500 |
59 |
Correct |
13 ms |
15040 KB |
n=2000 |
60 |
Correct |
13 ms |
15180 KB |
n=2000 |
61 |
Correct |
15 ms |
15204 KB |
n=2000 |
62 |
Correct |
14 ms |
15180 KB |
n=2000 |
63 |
Correct |
14 ms |
15172 KB |
n=2000 |
64 |
Correct |
16 ms |
15136 KB |
n=2000 |
65 |
Correct |
13 ms |
15044 KB |
n=2000 |
66 |
Correct |
13 ms |
15176 KB |
n=2000 |
67 |
Correct |
14 ms |
15052 KB |
n=2000 |
68 |
Correct |
14 ms |
15296 KB |
n=2000 |
69 |
Correct |
15 ms |
15052 KB |
n=2000 |
70 |
Correct |
16 ms |
15180 KB |
n=2000 |
71 |
Correct |
15 ms |
15128 KB |
n=2000 |
72 |
Correct |
15 ms |
15172 KB |
n=2000 |
73 |
Correct |
14 ms |
15136 KB |
n=2000 |
74 |
Correct |
13 ms |
15040 KB |
n=1844 |
75 |
Correct |
14 ms |
15044 KB |
n=2000 |
76 |
Correct |
14 ms |
15164 KB |
n=2000 |
77 |
Correct |
14 ms |
15048 KB |
n=2000 |
78 |
Correct |
15 ms |
15052 KB |
n=2000 |
79 |
Correct |
14 ms |
15052 KB |
n=2000 |
80 |
Correct |
12 ms |
15180 KB |
n=2000 |
81 |
Correct |
14 ms |
15180 KB |
n=2000 |
82 |
Correct |
14 ms |
15136 KB |
n=2000 |
83 |
Correct |
13 ms |
15172 KB |
n=2000 |
84 |
Correct |
16 ms |
15156 KB |
n=2000 |
85 |
Correct |
14 ms |
15176 KB |
n=2000 |
86 |
Correct |
18 ms |
15144 KB |
n=2000 |
87 |
Correct |
13 ms |
15176 KB |
n=2000 |
88 |
Correct |
12 ms |
15136 KB |
n=2000 |
89 |
Correct |
12 ms |
15180 KB |
n=2000 |
90 |
Correct |
12 ms |
15180 KB |
n=2000 |
91 |
Correct |
20 ms |
15052 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14412 KB |
n=5 |
2 |
Correct |
7 ms |
14392 KB |
n=100 |
3 |
Correct |
7 ms |
14412 KB |
n=100 |
4 |
Correct |
8 ms |
14396 KB |
n=100 |
5 |
Correct |
8 ms |
14412 KB |
n=100 |
6 |
Correct |
8 ms |
14392 KB |
n=100 |
7 |
Correct |
8 ms |
14412 KB |
n=100 |
8 |
Correct |
8 ms |
14372 KB |
n=100 |
9 |
Correct |
7 ms |
14412 KB |
n=100 |
10 |
Correct |
7 ms |
14396 KB |
n=100 |
11 |
Correct |
7 ms |
14384 KB |
n=100 |
12 |
Correct |
7 ms |
14416 KB |
n=100 |
13 |
Correct |
8 ms |
14412 KB |
n=100 |
14 |
Correct |
10 ms |
14396 KB |
n=100 |
15 |
Correct |
8 ms |
14412 KB |
n=100 |
16 |
Correct |
7 ms |
14412 KB |
n=100 |
17 |
Correct |
11 ms |
14452 KB |
n=100 |
18 |
Correct |
8 ms |
14400 KB |
n=100 |
19 |
Correct |
8 ms |
14412 KB |
n=100 |
20 |
Correct |
7 ms |
14412 KB |
n=100 |
21 |
Correct |
10 ms |
14424 KB |
n=100 |
22 |
Correct |
7 ms |
14392 KB |
n=100 |
23 |
Correct |
8 ms |
14392 KB |
n=100 |
24 |
Correct |
7 ms |
14412 KB |
n=100 |
25 |
Correct |
8 ms |
14412 KB |
n=100 |
26 |
Correct |
7 ms |
14312 KB |
n=12 |
27 |
Correct |
8 ms |
14412 KB |
n=100 |
28 |
Correct |
9 ms |
14540 KB |
n=500 |
29 |
Correct |
9 ms |
14572 KB |
n=500 |
30 |
Correct |
11 ms |
14532 KB |
n=500 |
31 |
Correct |
9 ms |
14532 KB |
n=500 |
32 |
Correct |
9 ms |
14540 KB |
n=500 |
33 |
Correct |
8 ms |
14540 KB |
n=500 |
34 |
Correct |
9 ms |
14540 KB |
n=500 |
35 |
Correct |
9 ms |
14540 KB |
n=500 |
36 |
Correct |
9 ms |
14508 KB |
n=500 |
37 |
Correct |
9 ms |
14540 KB |
n=500 |
38 |
Correct |
9 ms |
14528 KB |
n=500 |
39 |
Correct |
9 ms |
14540 KB |
n=500 |
40 |
Correct |
9 ms |
14572 KB |
n=500 |
41 |
Correct |
10 ms |
14524 KB |
n=500 |
42 |
Correct |
11 ms |
14540 KB |
n=500 |
43 |
Correct |
8 ms |
14528 KB |
n=500 |
44 |
Correct |
9 ms |
14524 KB |
n=500 |
45 |
Correct |
8 ms |
14540 KB |
n=500 |
46 |
Correct |
9 ms |
14588 KB |
n=500 |
47 |
Correct |
9 ms |
14540 KB |
n=500 |
48 |
Correct |
10 ms |
14540 KB |
n=500 |
49 |
Correct |
8 ms |
14540 KB |
n=500 |
50 |
Correct |
8 ms |
14536 KB |
n=500 |
51 |
Correct |
9 ms |
14540 KB |
n=500 |
52 |
Correct |
8 ms |
14552 KB |
n=500 |
53 |
Correct |
9 ms |
14504 KB |
n=500 |
54 |
Correct |
9 ms |
14540 KB |
n=500 |
55 |
Correct |
8 ms |
14540 KB |
n=278 |
56 |
Correct |
9 ms |
14540 KB |
n=500 |
57 |
Correct |
9 ms |
14532 KB |
n=500 |
58 |
Correct |
9 ms |
14540 KB |
n=500 |
59 |
Correct |
13 ms |
15040 KB |
n=2000 |
60 |
Correct |
13 ms |
15180 KB |
n=2000 |
61 |
Correct |
15 ms |
15204 KB |
n=2000 |
62 |
Correct |
14 ms |
15180 KB |
n=2000 |
63 |
Correct |
14 ms |
15172 KB |
n=2000 |
64 |
Correct |
16 ms |
15136 KB |
n=2000 |
65 |
Correct |
13 ms |
15044 KB |
n=2000 |
66 |
Correct |
13 ms |
15176 KB |
n=2000 |
67 |
Correct |
14 ms |
15052 KB |
n=2000 |
68 |
Correct |
14 ms |
15296 KB |
n=2000 |
69 |
Correct |
15 ms |
15052 KB |
n=2000 |
70 |
Correct |
16 ms |
15180 KB |
n=2000 |
71 |
Correct |
15 ms |
15128 KB |
n=2000 |
72 |
Correct |
15 ms |
15172 KB |
n=2000 |
73 |
Correct |
14 ms |
15136 KB |
n=2000 |
74 |
Correct |
13 ms |
15040 KB |
n=1844 |
75 |
Correct |
14 ms |
15044 KB |
n=2000 |
76 |
Correct |
14 ms |
15164 KB |
n=2000 |
77 |
Correct |
14 ms |
15048 KB |
n=2000 |
78 |
Correct |
15 ms |
15052 KB |
n=2000 |
79 |
Correct |
14 ms |
15052 KB |
n=2000 |
80 |
Correct |
12 ms |
15180 KB |
n=2000 |
81 |
Correct |
14 ms |
15180 KB |
n=2000 |
82 |
Correct |
14 ms |
15136 KB |
n=2000 |
83 |
Correct |
13 ms |
15172 KB |
n=2000 |
84 |
Correct |
16 ms |
15156 KB |
n=2000 |
85 |
Correct |
14 ms |
15176 KB |
n=2000 |
86 |
Correct |
18 ms |
15144 KB |
n=2000 |
87 |
Correct |
13 ms |
15176 KB |
n=2000 |
88 |
Correct |
12 ms |
15136 KB |
n=2000 |
89 |
Correct |
12 ms |
15180 KB |
n=2000 |
90 |
Correct |
12 ms |
15180 KB |
n=2000 |
91 |
Correct |
20 ms |
15052 KB |
n=2000 |
92 |
Correct |
1082 ms |
88388 KB |
n=200000 |
93 |
Correct |
1161 ms |
91952 KB |
n=200000 |
94 |
Correct |
951 ms |
94860 KB |
n=200000 |
95 |
Correct |
1069 ms |
87968 KB |
n=200000 |
96 |
Correct |
1092 ms |
87980 KB |
n=200000 |
97 |
Correct |
1242 ms |
91128 KB |
n=200000 |
98 |
Correct |
1094 ms |
87916 KB |
n=200000 |
99 |
Correct |
1271 ms |
87544 KB |
n=200000 |
100 |
Correct |
1120 ms |
87972 KB |
n=200000 |
101 |
Correct |
876 ms |
95488 KB |
n=200000 |
102 |
Correct |
942 ms |
89032 KB |
n=200000 |
103 |
Correct |
899 ms |
89156 KB |
n=200000 |
104 |
Correct |
937 ms |
88836 KB |
n=200000 |
105 |
Correct |
889 ms |
88720 KB |
n=200000 |
106 |
Correct |
941 ms |
88592 KB |
n=200000 |
107 |
Correct |
924 ms |
88636 KB |
n=200000 |
108 |
Correct |
1188 ms |
87512 KB |
n=200000 |
109 |
Correct |
1137 ms |
87404 KB |
n=200000 |
110 |
Correct |
1177 ms |
87340 KB |
n=200000 |
111 |
Correct |
1137 ms |
87364 KB |
n=200000 |
112 |
Correct |
953 ms |
94572 KB |
n=200000 |
113 |
Correct |
1323 ms |
90568 KB |
n=200000 |
114 |
Correct |
1089 ms |
87372 KB |
n=200000 |
115 |
Correct |
1640 ms |
88328 KB |
n=200000 |
116 |
Correct |
1058 ms |
87016 KB |
n=200000 |
117 |
Correct |
859 ms |
94480 KB |
n=200000 |
118 |
Correct |
1319 ms |
89248 KB |
n=200000 |
119 |
Correct |
999 ms |
86936 KB |
n=200000 |
120 |
Correct |
761 ms |
94468 KB |
n=200000 |
121 |
Correct |
773 ms |
94560 KB |
n=200000 |
122 |
Correct |
771 ms |
94984 KB |
n=200000 |
123 |
Correct |
922 ms |
87832 KB |
n=200000 |
124 |
Correct |
266 ms |
34756 KB |
n=25264 |