#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long
#define maksim gay
#define int ll
#define pb push_back
#define sz(s) (int)s.size()
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define mem(a,i) memset(a,i,sizeof(a))
#define in insert
#define lb lower_bound
#define ub upper_bound
const int MAX=4e5+10;
const int inf=1e10;
const int N=2e5;
int n,m,q;
int up[MAX][20];
int tin[MAX],tout[MAX],timer;
vector<int> g[MAX];
int a[MAX];
set<int> p[MAX],p1[MAX];
void dfs(int v,int p=1){
tin[v]=++timer;
up[v][0]=p;
for(int i=1;i<20;i++)up[v][i]=up[up[v][i-1]][i-1];
for(auto to:g[v]){
if(to==p)continue;
dfs(to,v);
}
tout[v]=timer;
}
int par(int u,int v){
return tin[u]<=tin[v]&&tout[v]<=tout[u];
}
int lca(int u,int v){
if(par(u,v))return u;
if(par(v,u))return v;
for(int i=19;i>=0;i--){
if(!par(up[u][i],v)){
u=up[u][i];
}
}
return up[u][0];
}
void upd(int pos,int v){
p1[a[pos]].erase(pos);
if(pos-1>=1){
p[lca(a[pos],a[pos-1])].erase(pos-1);
}
if(pos+1<=m){
p[lca(a[pos],a[pos+1])].erase(pos);
}
a[pos]=v;
p1[a[pos]].in(pos);
if(pos-1>=1){
p[lca(a[pos],a[pos-1])].in(pos-1);
}
if(pos+1<=m){
p[lca(a[pos],a[pos+1])].in(pos);
}
}
void solve(){
cin>>n>>m>>q;
for(int i=1;i<n;i++){
int u,v;
cin>>u>>v;
g[u].pb(v);
g[v].pb(u);
}
dfs(1);
for(int i=1;i<=m;i++){
cin>>a[i];
p1[a[i]].in(i);
}
for(int i=2;i<=m;i++){
p[lca(a[i],a[i-1])].in(i-1);
}
while(q--){
int t;
cin>>t;
if(t==1){
int pos,v;
cin>>pos>>v;
upd(pos,v);
}
else{
int l,r,v;
cin>>l>>r>>v;
auto f=p[v].lb(l);
if(f!=p[v].end()&&*f+1<=r){
cout<<*f<<" "<<*f+1<<"\n";
continue;
}
f=p1[v].lb(l);
if(f!=p1[v].end()&&*f<=r){
cout<<*f<<" "<<*f<<"\n";
continue;
}
cout<<-1<<" "<<-1<<"\n";
}
}
}
main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t=1;
// cin>>t;
while(t--){
solve();
}
}
Compilation message
treearray.cpp:117:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
117 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
56032 KB |
n=5 |
2 |
Correct |
10 ms |
55900 KB |
n=100 |
3 |
Correct |
11 ms |
55900 KB |
n=100 |
4 |
Correct |
10 ms |
55900 KB |
n=100 |
5 |
Correct |
13 ms |
55896 KB |
n=100 |
6 |
Correct |
11 ms |
56044 KB |
n=100 |
7 |
Correct |
11 ms |
55896 KB |
n=100 |
8 |
Correct |
11 ms |
55896 KB |
n=100 |
9 |
Correct |
11 ms |
55896 KB |
n=100 |
10 |
Correct |
11 ms |
55900 KB |
n=100 |
11 |
Correct |
10 ms |
55896 KB |
n=100 |
12 |
Correct |
11 ms |
55896 KB |
n=100 |
13 |
Correct |
11 ms |
55896 KB |
n=100 |
14 |
Correct |
11 ms |
55896 KB |
n=100 |
15 |
Correct |
11 ms |
55900 KB |
n=100 |
16 |
Correct |
11 ms |
55900 KB |
n=100 |
17 |
Correct |
11 ms |
55900 KB |
n=100 |
18 |
Correct |
11 ms |
55900 KB |
n=100 |
19 |
Correct |
10 ms |
55900 KB |
n=100 |
20 |
Correct |
11 ms |
55900 KB |
n=100 |
21 |
Correct |
13 ms |
55900 KB |
n=100 |
22 |
Correct |
11 ms |
55900 KB |
n=100 |
23 |
Correct |
11 ms |
55896 KB |
n=100 |
24 |
Correct |
12 ms |
55900 KB |
n=100 |
25 |
Correct |
11 ms |
55896 KB |
n=100 |
26 |
Correct |
11 ms |
55896 KB |
n=12 |
27 |
Correct |
11 ms |
55900 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
56032 KB |
n=5 |
2 |
Correct |
10 ms |
55900 KB |
n=100 |
3 |
Correct |
11 ms |
55900 KB |
n=100 |
4 |
Correct |
10 ms |
55900 KB |
n=100 |
5 |
Correct |
13 ms |
55896 KB |
n=100 |
6 |
Correct |
11 ms |
56044 KB |
n=100 |
7 |
Correct |
11 ms |
55896 KB |
n=100 |
8 |
Correct |
11 ms |
55896 KB |
n=100 |
9 |
Correct |
11 ms |
55896 KB |
n=100 |
10 |
Correct |
11 ms |
55900 KB |
n=100 |
11 |
Correct |
10 ms |
55896 KB |
n=100 |
12 |
Correct |
11 ms |
55896 KB |
n=100 |
13 |
Correct |
11 ms |
55896 KB |
n=100 |
14 |
Correct |
11 ms |
55896 KB |
n=100 |
15 |
Correct |
11 ms |
55900 KB |
n=100 |
16 |
Correct |
11 ms |
55900 KB |
n=100 |
17 |
Correct |
11 ms |
55900 KB |
n=100 |
18 |
Correct |
11 ms |
55900 KB |
n=100 |
19 |
Correct |
10 ms |
55900 KB |
n=100 |
20 |
Correct |
11 ms |
55900 KB |
n=100 |
21 |
Correct |
13 ms |
55900 KB |
n=100 |
22 |
Correct |
11 ms |
55900 KB |
n=100 |
23 |
Correct |
11 ms |
55896 KB |
n=100 |
24 |
Correct |
12 ms |
55900 KB |
n=100 |
25 |
Correct |
11 ms |
55896 KB |
n=100 |
26 |
Correct |
11 ms |
55896 KB |
n=12 |
27 |
Correct |
11 ms |
55900 KB |
n=100 |
28 |
Correct |
12 ms |
55900 KB |
n=500 |
29 |
Correct |
11 ms |
55896 KB |
n=500 |
30 |
Correct |
12 ms |
55896 KB |
n=500 |
31 |
Correct |
11 ms |
55900 KB |
n=500 |
32 |
Correct |
12 ms |
55900 KB |
n=500 |
33 |
Correct |
11 ms |
55900 KB |
n=500 |
34 |
Correct |
11 ms |
56108 KB |
n=500 |
35 |
Correct |
11 ms |
56120 KB |
n=500 |
36 |
Correct |
11 ms |
55896 KB |
n=500 |
37 |
Correct |
12 ms |
55896 KB |
n=500 |
38 |
Correct |
11 ms |
55900 KB |
n=500 |
39 |
Correct |
11 ms |
55900 KB |
n=500 |
40 |
Correct |
11 ms |
56364 KB |
n=500 |
41 |
Correct |
11 ms |
55896 KB |
n=500 |
42 |
Correct |
11 ms |
56100 KB |
n=500 |
43 |
Correct |
12 ms |
55900 KB |
n=500 |
44 |
Correct |
11 ms |
56104 KB |
n=500 |
45 |
Correct |
12 ms |
55976 KB |
n=500 |
46 |
Correct |
12 ms |
55900 KB |
n=500 |
47 |
Correct |
11 ms |
55900 KB |
n=500 |
48 |
Correct |
12 ms |
55996 KB |
n=500 |
49 |
Correct |
11 ms |
55900 KB |
n=500 |
50 |
Correct |
12 ms |
56104 KB |
n=500 |
51 |
Correct |
11 ms |
56112 KB |
n=500 |
52 |
Correct |
11 ms |
55900 KB |
n=500 |
53 |
Correct |
12 ms |
55900 KB |
n=500 |
54 |
Correct |
12 ms |
55900 KB |
n=500 |
55 |
Correct |
11 ms |
55896 KB |
n=278 |
56 |
Correct |
12 ms |
56120 KB |
n=500 |
57 |
Correct |
13 ms |
56156 KB |
n=500 |
58 |
Correct |
11 ms |
55900 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
56032 KB |
n=5 |
2 |
Correct |
10 ms |
55900 KB |
n=100 |
3 |
Correct |
11 ms |
55900 KB |
n=100 |
4 |
Correct |
10 ms |
55900 KB |
n=100 |
5 |
Correct |
13 ms |
55896 KB |
n=100 |
6 |
Correct |
11 ms |
56044 KB |
n=100 |
7 |
Correct |
11 ms |
55896 KB |
n=100 |
8 |
Correct |
11 ms |
55896 KB |
n=100 |
9 |
Correct |
11 ms |
55896 KB |
n=100 |
10 |
Correct |
11 ms |
55900 KB |
n=100 |
11 |
Correct |
10 ms |
55896 KB |
n=100 |
12 |
Correct |
11 ms |
55896 KB |
n=100 |
13 |
Correct |
11 ms |
55896 KB |
n=100 |
14 |
Correct |
11 ms |
55896 KB |
n=100 |
15 |
Correct |
11 ms |
55900 KB |
n=100 |
16 |
Correct |
11 ms |
55900 KB |
n=100 |
17 |
Correct |
11 ms |
55900 KB |
n=100 |
18 |
Correct |
11 ms |
55900 KB |
n=100 |
19 |
Correct |
10 ms |
55900 KB |
n=100 |
20 |
Correct |
11 ms |
55900 KB |
n=100 |
21 |
Correct |
13 ms |
55900 KB |
n=100 |
22 |
Correct |
11 ms |
55900 KB |
n=100 |
23 |
Correct |
11 ms |
55896 KB |
n=100 |
24 |
Correct |
12 ms |
55900 KB |
n=100 |
25 |
Correct |
11 ms |
55896 KB |
n=100 |
26 |
Correct |
11 ms |
55896 KB |
n=12 |
27 |
Correct |
11 ms |
55900 KB |
n=100 |
28 |
Correct |
12 ms |
55900 KB |
n=500 |
29 |
Correct |
11 ms |
55896 KB |
n=500 |
30 |
Correct |
12 ms |
55896 KB |
n=500 |
31 |
Correct |
11 ms |
55900 KB |
n=500 |
32 |
Correct |
12 ms |
55900 KB |
n=500 |
33 |
Correct |
11 ms |
55900 KB |
n=500 |
34 |
Correct |
11 ms |
56108 KB |
n=500 |
35 |
Correct |
11 ms |
56120 KB |
n=500 |
36 |
Correct |
11 ms |
55896 KB |
n=500 |
37 |
Correct |
12 ms |
55896 KB |
n=500 |
38 |
Correct |
11 ms |
55900 KB |
n=500 |
39 |
Correct |
11 ms |
55900 KB |
n=500 |
40 |
Correct |
11 ms |
56364 KB |
n=500 |
41 |
Correct |
11 ms |
55896 KB |
n=500 |
42 |
Correct |
11 ms |
56100 KB |
n=500 |
43 |
Correct |
12 ms |
55900 KB |
n=500 |
44 |
Correct |
11 ms |
56104 KB |
n=500 |
45 |
Correct |
12 ms |
55976 KB |
n=500 |
46 |
Correct |
12 ms |
55900 KB |
n=500 |
47 |
Correct |
11 ms |
55900 KB |
n=500 |
48 |
Correct |
12 ms |
55996 KB |
n=500 |
49 |
Correct |
11 ms |
55900 KB |
n=500 |
50 |
Correct |
12 ms |
56104 KB |
n=500 |
51 |
Correct |
11 ms |
56112 KB |
n=500 |
52 |
Correct |
11 ms |
55900 KB |
n=500 |
53 |
Correct |
12 ms |
55900 KB |
n=500 |
54 |
Correct |
12 ms |
55900 KB |
n=500 |
55 |
Correct |
11 ms |
55896 KB |
n=278 |
56 |
Correct |
12 ms |
56120 KB |
n=500 |
57 |
Correct |
13 ms |
56156 KB |
n=500 |
58 |
Correct |
11 ms |
55900 KB |
n=500 |
59 |
Correct |
13 ms |
56156 KB |
n=2000 |
60 |
Correct |
13 ms |
56152 KB |
n=2000 |
61 |
Correct |
13 ms |
56156 KB |
n=2000 |
62 |
Correct |
13 ms |
56156 KB |
n=2000 |
63 |
Correct |
13 ms |
56152 KB |
n=2000 |
64 |
Correct |
14 ms |
56336 KB |
n=2000 |
65 |
Correct |
15 ms |
56156 KB |
n=2000 |
66 |
Correct |
13 ms |
56156 KB |
n=2000 |
67 |
Correct |
14 ms |
56268 KB |
n=2000 |
68 |
Correct |
14 ms |
56156 KB |
n=2000 |
69 |
Correct |
12 ms |
56156 KB |
n=2000 |
70 |
Correct |
13 ms |
56156 KB |
n=2000 |
71 |
Correct |
13 ms |
56156 KB |
n=2000 |
72 |
Correct |
14 ms |
56156 KB |
n=2000 |
73 |
Correct |
13 ms |
56152 KB |
n=2000 |
74 |
Correct |
13 ms |
56156 KB |
n=1844 |
75 |
Correct |
13 ms |
56156 KB |
n=2000 |
76 |
Correct |
13 ms |
56156 KB |
n=2000 |
77 |
Correct |
14 ms |
56308 KB |
n=2000 |
78 |
Correct |
13 ms |
56152 KB |
n=2000 |
79 |
Correct |
14 ms |
56156 KB |
n=2000 |
80 |
Correct |
13 ms |
56156 KB |
n=2000 |
81 |
Correct |
13 ms |
56152 KB |
n=2000 |
82 |
Correct |
14 ms |
56156 KB |
n=2000 |
83 |
Correct |
13 ms |
56260 KB |
n=2000 |
84 |
Correct |
13 ms |
56156 KB |
n=2000 |
85 |
Correct |
13 ms |
56156 KB |
n=2000 |
86 |
Correct |
14 ms |
56156 KB |
n=2000 |
87 |
Correct |
14 ms |
56152 KB |
n=2000 |
88 |
Correct |
14 ms |
56152 KB |
n=2000 |
89 |
Correct |
15 ms |
56412 KB |
n=2000 |
90 |
Correct |
12 ms |
56156 KB |
n=2000 |
91 |
Correct |
14 ms |
56156 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
56032 KB |
n=5 |
2 |
Correct |
10 ms |
55900 KB |
n=100 |
3 |
Correct |
11 ms |
55900 KB |
n=100 |
4 |
Correct |
10 ms |
55900 KB |
n=100 |
5 |
Correct |
13 ms |
55896 KB |
n=100 |
6 |
Correct |
11 ms |
56044 KB |
n=100 |
7 |
Correct |
11 ms |
55896 KB |
n=100 |
8 |
Correct |
11 ms |
55896 KB |
n=100 |
9 |
Correct |
11 ms |
55896 KB |
n=100 |
10 |
Correct |
11 ms |
55900 KB |
n=100 |
11 |
Correct |
10 ms |
55896 KB |
n=100 |
12 |
Correct |
11 ms |
55896 KB |
n=100 |
13 |
Correct |
11 ms |
55896 KB |
n=100 |
14 |
Correct |
11 ms |
55896 KB |
n=100 |
15 |
Correct |
11 ms |
55900 KB |
n=100 |
16 |
Correct |
11 ms |
55900 KB |
n=100 |
17 |
Correct |
11 ms |
55900 KB |
n=100 |
18 |
Correct |
11 ms |
55900 KB |
n=100 |
19 |
Correct |
10 ms |
55900 KB |
n=100 |
20 |
Correct |
11 ms |
55900 KB |
n=100 |
21 |
Correct |
13 ms |
55900 KB |
n=100 |
22 |
Correct |
11 ms |
55900 KB |
n=100 |
23 |
Correct |
11 ms |
55896 KB |
n=100 |
24 |
Correct |
12 ms |
55900 KB |
n=100 |
25 |
Correct |
11 ms |
55896 KB |
n=100 |
26 |
Correct |
11 ms |
55896 KB |
n=12 |
27 |
Correct |
11 ms |
55900 KB |
n=100 |
28 |
Correct |
12 ms |
55900 KB |
n=500 |
29 |
Correct |
11 ms |
55896 KB |
n=500 |
30 |
Correct |
12 ms |
55896 KB |
n=500 |
31 |
Correct |
11 ms |
55900 KB |
n=500 |
32 |
Correct |
12 ms |
55900 KB |
n=500 |
33 |
Correct |
11 ms |
55900 KB |
n=500 |
34 |
Correct |
11 ms |
56108 KB |
n=500 |
35 |
Correct |
11 ms |
56120 KB |
n=500 |
36 |
Correct |
11 ms |
55896 KB |
n=500 |
37 |
Correct |
12 ms |
55896 KB |
n=500 |
38 |
Correct |
11 ms |
55900 KB |
n=500 |
39 |
Correct |
11 ms |
55900 KB |
n=500 |
40 |
Correct |
11 ms |
56364 KB |
n=500 |
41 |
Correct |
11 ms |
55896 KB |
n=500 |
42 |
Correct |
11 ms |
56100 KB |
n=500 |
43 |
Correct |
12 ms |
55900 KB |
n=500 |
44 |
Correct |
11 ms |
56104 KB |
n=500 |
45 |
Correct |
12 ms |
55976 KB |
n=500 |
46 |
Correct |
12 ms |
55900 KB |
n=500 |
47 |
Correct |
11 ms |
55900 KB |
n=500 |
48 |
Correct |
12 ms |
55996 KB |
n=500 |
49 |
Correct |
11 ms |
55900 KB |
n=500 |
50 |
Correct |
12 ms |
56104 KB |
n=500 |
51 |
Correct |
11 ms |
56112 KB |
n=500 |
52 |
Correct |
11 ms |
55900 KB |
n=500 |
53 |
Correct |
12 ms |
55900 KB |
n=500 |
54 |
Correct |
12 ms |
55900 KB |
n=500 |
55 |
Correct |
11 ms |
55896 KB |
n=278 |
56 |
Correct |
12 ms |
56120 KB |
n=500 |
57 |
Correct |
13 ms |
56156 KB |
n=500 |
58 |
Correct |
11 ms |
55900 KB |
n=500 |
59 |
Correct |
13 ms |
56156 KB |
n=2000 |
60 |
Correct |
13 ms |
56152 KB |
n=2000 |
61 |
Correct |
13 ms |
56156 KB |
n=2000 |
62 |
Correct |
13 ms |
56156 KB |
n=2000 |
63 |
Correct |
13 ms |
56152 KB |
n=2000 |
64 |
Correct |
14 ms |
56336 KB |
n=2000 |
65 |
Correct |
15 ms |
56156 KB |
n=2000 |
66 |
Correct |
13 ms |
56156 KB |
n=2000 |
67 |
Correct |
14 ms |
56268 KB |
n=2000 |
68 |
Correct |
14 ms |
56156 KB |
n=2000 |
69 |
Correct |
12 ms |
56156 KB |
n=2000 |
70 |
Correct |
13 ms |
56156 KB |
n=2000 |
71 |
Correct |
13 ms |
56156 KB |
n=2000 |
72 |
Correct |
14 ms |
56156 KB |
n=2000 |
73 |
Correct |
13 ms |
56152 KB |
n=2000 |
74 |
Correct |
13 ms |
56156 KB |
n=1844 |
75 |
Correct |
13 ms |
56156 KB |
n=2000 |
76 |
Correct |
13 ms |
56156 KB |
n=2000 |
77 |
Correct |
14 ms |
56308 KB |
n=2000 |
78 |
Correct |
13 ms |
56152 KB |
n=2000 |
79 |
Correct |
14 ms |
56156 KB |
n=2000 |
80 |
Correct |
13 ms |
56156 KB |
n=2000 |
81 |
Correct |
13 ms |
56152 KB |
n=2000 |
82 |
Correct |
14 ms |
56156 KB |
n=2000 |
83 |
Correct |
13 ms |
56260 KB |
n=2000 |
84 |
Correct |
13 ms |
56156 KB |
n=2000 |
85 |
Correct |
13 ms |
56156 KB |
n=2000 |
86 |
Correct |
14 ms |
56156 KB |
n=2000 |
87 |
Correct |
14 ms |
56152 KB |
n=2000 |
88 |
Correct |
14 ms |
56152 KB |
n=2000 |
89 |
Correct |
15 ms |
56412 KB |
n=2000 |
90 |
Correct |
12 ms |
56156 KB |
n=2000 |
91 |
Correct |
14 ms |
56156 KB |
n=2000 |
92 |
Correct |
576 ms |
116860 KB |
n=200000 |
93 |
Correct |
667 ms |
120552 KB |
n=200000 |
94 |
Correct |
478 ms |
123336 KB |
n=200000 |
95 |
Correct |
571 ms |
116480 KB |
n=200000 |
96 |
Correct |
516 ms |
116536 KB |
n=200000 |
97 |
Correct |
716 ms |
119568 KB |
n=200000 |
98 |
Correct |
528 ms |
116784 KB |
n=200000 |
99 |
Correct |
626 ms |
116196 KB |
n=200000 |
100 |
Correct |
543 ms |
116644 KB |
n=200000 |
101 |
Correct |
442 ms |
124356 KB |
n=200000 |
102 |
Correct |
326 ms |
117644 KB |
n=200000 |
103 |
Correct |
334 ms |
117668 KB |
n=200000 |
104 |
Correct |
320 ms |
117584 KB |
n=200000 |
105 |
Correct |
307 ms |
117356 KB |
n=200000 |
106 |
Correct |
337 ms |
117252 KB |
n=200000 |
107 |
Correct |
353 ms |
117328 KB |
n=200000 |
108 |
Correct |
596 ms |
116332 KB |
n=200000 |
109 |
Correct |
567 ms |
116236 KB |
n=200000 |
110 |
Correct |
574 ms |
116340 KB |
n=200000 |
111 |
Correct |
521 ms |
116356 KB |
n=200000 |
112 |
Correct |
421 ms |
123480 KB |
n=200000 |
113 |
Correct |
702 ms |
119680 KB |
n=200000 |
114 |
Correct |
526 ms |
116416 KB |
n=200000 |
115 |
Correct |
835 ms |
117356 KB |
n=200000 |
116 |
Correct |
517 ms |
116156 KB |
n=200000 |
117 |
Correct |
437 ms |
124004 KB |
n=200000 |
118 |
Correct |
762 ms |
118356 KB |
n=200000 |
119 |
Correct |
523 ms |
116336 KB |
n=200000 |
120 |
Correct |
358 ms |
123728 KB |
n=200000 |
121 |
Correct |
345 ms |
123708 KB |
n=200000 |
122 |
Correct |
357 ms |
124460 KB |
n=200000 |
123 |
Correct |
319 ms |
117076 KB |
n=200000 |
124 |
Correct |
103 ms |
70600 KB |
n=25264 |