// Muallif: Mansuraliyev Husanboy Murotali o'g'li >> NamPS
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(a) a.begin(), a.end()
#define F first
#define S second
// 0-9 >> 48-57; A-Z>>65-90 and a-z>>97-122 respectively;
const int N=2e5+5;
vector<int> g[N]; int up[N][17],depth[N];
set<int> pos[N],pospair[N];
void dfs(int a, int p){
for(auto u:g[a]){
if(u!=p){
up[u][0]=a;
for(int i=1;i<17;i++){
up[u][i]=up[up[u][i-1]][i-1];
}
depth[u]=depth[a]+1;
dfs(u,a);
}
}
}
int lca(int a, int b){
if(depth[a]<depth[b]){
swap(a,b);
}
int k=depth[a]-depth[b];
for(int i=0;i<17;i++){
if((1<<i)&k){
a=up[a][i];
}
}
if(a==b) return a;
for(int i=16;i>=0;i--){
if(up[a][i]!=up[b][i]){
a=up[a][i],b=up[b][i];
}
}
return up[a][0];
}
void solve(){
int n,m,q; cin>>n>>m>>q;
for(int i=0;i<n-1;i++){
int x,y; cin>>x>>y; g[x].push_back(y); g[y].push_back(x);
}
dfs(1,1);
// for(int i=1;i<=n;i++) cout<<depth[i]<<endl;
int a[m+1];
for(int i=1;i<=m;i++){
cin>>a[i]; pos[a[i]].insert(i);
}
for(int i=1;i<m;i++){
pospair[lca(a[i],a[i+1])].insert(i);
}
/* int aa,bb; cin>>aa>>bb;
cout<<lca(aa,bb)<<" lca"<<endl;*/
while(q--){
int type; cin>>type;
if(type==1){
int x,y; cin>>x>>y;
pos[a[x]].erase(x);
pos[y].insert(x);
if(x>1){
pospair[lca(a[x-1],a[x])].erase(x-1);
pospair[lca(a[x-1],y)].insert(x-1);
}
if(x<m){
pospair[lca(a[x],a[x+1])].erase(x);
pospair[lca(y,a[x+1])].insert(x);
}
a[x]=y;
}else{
int l,r,x; cin>>l>>r>>x;
auto pp=pospair[x].lower_bound(l);
/* for(int i=1;i<=n;i++){
cout<<i<<": ";
for(auto u:pospair[i]){
cout<<u<<' ';
}cout<<endl;
}*/
auto p=pos[x].lower_bound(l);
if(p!=pos[x].end()&&*p<=r){
cout<<*p<<' '<<*p<<"\n";
}else
if(pp!=pospair[x].end()&&*pp<r){
cout<<*pp<<' '<<*pp+1<<"\n";
}else cout<<"-1 -1\n";
}
}
}
int main(){
ios;
//int t=1; cin>>t; while(t--)
solve();
}
/*
5 4 4
1 2
3 1
3 4
5 3
4 5 2 3
2 1 3 1
1 3 5
2 3 4 5
2 1 3 1
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23756 KB |
n=5 |
2 |
Correct |
12 ms |
23756 KB |
n=100 |
3 |
Correct |
12 ms |
23792 KB |
n=100 |
4 |
Correct |
12 ms |
23756 KB |
n=100 |
5 |
Correct |
12 ms |
23756 KB |
n=100 |
6 |
Correct |
13 ms |
23736 KB |
n=100 |
7 |
Correct |
12 ms |
23728 KB |
n=100 |
8 |
Correct |
12 ms |
23756 KB |
n=100 |
9 |
Correct |
11 ms |
23780 KB |
n=100 |
10 |
Correct |
11 ms |
23776 KB |
n=100 |
11 |
Correct |
12 ms |
23824 KB |
n=100 |
12 |
Correct |
12 ms |
23756 KB |
n=100 |
13 |
Correct |
12 ms |
23760 KB |
n=100 |
14 |
Correct |
12 ms |
23756 KB |
n=100 |
15 |
Correct |
12 ms |
23756 KB |
n=100 |
16 |
Correct |
12 ms |
23756 KB |
n=100 |
17 |
Correct |
12 ms |
23756 KB |
n=100 |
18 |
Correct |
12 ms |
23824 KB |
n=100 |
19 |
Correct |
12 ms |
23756 KB |
n=100 |
20 |
Correct |
12 ms |
23708 KB |
n=100 |
21 |
Correct |
15 ms |
23736 KB |
n=100 |
22 |
Correct |
12 ms |
23704 KB |
n=100 |
23 |
Correct |
12 ms |
23756 KB |
n=100 |
24 |
Correct |
11 ms |
23756 KB |
n=100 |
25 |
Correct |
12 ms |
23756 KB |
n=100 |
26 |
Correct |
12 ms |
23800 KB |
n=12 |
27 |
Correct |
12 ms |
23756 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23756 KB |
n=5 |
2 |
Correct |
12 ms |
23756 KB |
n=100 |
3 |
Correct |
12 ms |
23792 KB |
n=100 |
4 |
Correct |
12 ms |
23756 KB |
n=100 |
5 |
Correct |
12 ms |
23756 KB |
n=100 |
6 |
Correct |
13 ms |
23736 KB |
n=100 |
7 |
Correct |
12 ms |
23728 KB |
n=100 |
8 |
Correct |
12 ms |
23756 KB |
n=100 |
9 |
Correct |
11 ms |
23780 KB |
n=100 |
10 |
Correct |
11 ms |
23776 KB |
n=100 |
11 |
Correct |
12 ms |
23824 KB |
n=100 |
12 |
Correct |
12 ms |
23756 KB |
n=100 |
13 |
Correct |
12 ms |
23760 KB |
n=100 |
14 |
Correct |
12 ms |
23756 KB |
n=100 |
15 |
Correct |
12 ms |
23756 KB |
n=100 |
16 |
Correct |
12 ms |
23756 KB |
n=100 |
17 |
Correct |
12 ms |
23756 KB |
n=100 |
18 |
Correct |
12 ms |
23824 KB |
n=100 |
19 |
Correct |
12 ms |
23756 KB |
n=100 |
20 |
Correct |
12 ms |
23708 KB |
n=100 |
21 |
Correct |
15 ms |
23736 KB |
n=100 |
22 |
Correct |
12 ms |
23704 KB |
n=100 |
23 |
Correct |
12 ms |
23756 KB |
n=100 |
24 |
Correct |
11 ms |
23756 KB |
n=100 |
25 |
Correct |
12 ms |
23756 KB |
n=100 |
26 |
Correct |
12 ms |
23800 KB |
n=12 |
27 |
Correct |
12 ms |
23756 KB |
n=100 |
28 |
Correct |
14 ms |
23912 KB |
n=500 |
29 |
Correct |
12 ms |
23884 KB |
n=500 |
30 |
Correct |
13 ms |
23884 KB |
n=500 |
31 |
Correct |
12 ms |
23820 KB |
n=500 |
32 |
Correct |
13 ms |
23884 KB |
n=500 |
33 |
Correct |
13 ms |
23852 KB |
n=500 |
34 |
Correct |
12 ms |
23884 KB |
n=500 |
35 |
Correct |
12 ms |
23884 KB |
n=500 |
36 |
Correct |
13 ms |
23884 KB |
n=500 |
37 |
Correct |
12 ms |
23884 KB |
n=500 |
38 |
Correct |
12 ms |
23884 KB |
n=500 |
39 |
Correct |
12 ms |
23868 KB |
n=500 |
40 |
Correct |
12 ms |
23876 KB |
n=500 |
41 |
Correct |
12 ms |
23884 KB |
n=500 |
42 |
Correct |
12 ms |
23884 KB |
n=500 |
43 |
Correct |
12 ms |
23884 KB |
n=500 |
44 |
Correct |
13 ms |
23884 KB |
n=500 |
45 |
Correct |
13 ms |
23884 KB |
n=500 |
46 |
Correct |
13 ms |
23892 KB |
n=500 |
47 |
Correct |
14 ms |
23812 KB |
n=500 |
48 |
Correct |
13 ms |
23884 KB |
n=500 |
49 |
Correct |
13 ms |
23824 KB |
n=500 |
50 |
Correct |
12 ms |
23820 KB |
n=500 |
51 |
Correct |
12 ms |
23872 KB |
n=500 |
52 |
Correct |
12 ms |
23884 KB |
n=500 |
53 |
Correct |
13 ms |
23884 KB |
n=500 |
54 |
Correct |
12 ms |
23884 KB |
n=500 |
55 |
Correct |
12 ms |
23836 KB |
n=278 |
56 |
Correct |
15 ms |
23884 KB |
n=500 |
57 |
Correct |
12 ms |
23884 KB |
n=500 |
58 |
Correct |
12 ms |
23792 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23756 KB |
n=5 |
2 |
Correct |
12 ms |
23756 KB |
n=100 |
3 |
Correct |
12 ms |
23792 KB |
n=100 |
4 |
Correct |
12 ms |
23756 KB |
n=100 |
5 |
Correct |
12 ms |
23756 KB |
n=100 |
6 |
Correct |
13 ms |
23736 KB |
n=100 |
7 |
Correct |
12 ms |
23728 KB |
n=100 |
8 |
Correct |
12 ms |
23756 KB |
n=100 |
9 |
Correct |
11 ms |
23780 KB |
n=100 |
10 |
Correct |
11 ms |
23776 KB |
n=100 |
11 |
Correct |
12 ms |
23824 KB |
n=100 |
12 |
Correct |
12 ms |
23756 KB |
n=100 |
13 |
Correct |
12 ms |
23760 KB |
n=100 |
14 |
Correct |
12 ms |
23756 KB |
n=100 |
15 |
Correct |
12 ms |
23756 KB |
n=100 |
16 |
Correct |
12 ms |
23756 KB |
n=100 |
17 |
Correct |
12 ms |
23756 KB |
n=100 |
18 |
Correct |
12 ms |
23824 KB |
n=100 |
19 |
Correct |
12 ms |
23756 KB |
n=100 |
20 |
Correct |
12 ms |
23708 KB |
n=100 |
21 |
Correct |
15 ms |
23736 KB |
n=100 |
22 |
Correct |
12 ms |
23704 KB |
n=100 |
23 |
Correct |
12 ms |
23756 KB |
n=100 |
24 |
Correct |
11 ms |
23756 KB |
n=100 |
25 |
Correct |
12 ms |
23756 KB |
n=100 |
26 |
Correct |
12 ms |
23800 KB |
n=12 |
27 |
Correct |
12 ms |
23756 KB |
n=100 |
28 |
Correct |
14 ms |
23912 KB |
n=500 |
29 |
Correct |
12 ms |
23884 KB |
n=500 |
30 |
Correct |
13 ms |
23884 KB |
n=500 |
31 |
Correct |
12 ms |
23820 KB |
n=500 |
32 |
Correct |
13 ms |
23884 KB |
n=500 |
33 |
Correct |
13 ms |
23852 KB |
n=500 |
34 |
Correct |
12 ms |
23884 KB |
n=500 |
35 |
Correct |
12 ms |
23884 KB |
n=500 |
36 |
Correct |
13 ms |
23884 KB |
n=500 |
37 |
Correct |
12 ms |
23884 KB |
n=500 |
38 |
Correct |
12 ms |
23884 KB |
n=500 |
39 |
Correct |
12 ms |
23868 KB |
n=500 |
40 |
Correct |
12 ms |
23876 KB |
n=500 |
41 |
Correct |
12 ms |
23884 KB |
n=500 |
42 |
Correct |
12 ms |
23884 KB |
n=500 |
43 |
Correct |
12 ms |
23884 KB |
n=500 |
44 |
Correct |
13 ms |
23884 KB |
n=500 |
45 |
Correct |
13 ms |
23884 KB |
n=500 |
46 |
Correct |
13 ms |
23892 KB |
n=500 |
47 |
Correct |
14 ms |
23812 KB |
n=500 |
48 |
Correct |
13 ms |
23884 KB |
n=500 |
49 |
Correct |
13 ms |
23824 KB |
n=500 |
50 |
Correct |
12 ms |
23820 KB |
n=500 |
51 |
Correct |
12 ms |
23872 KB |
n=500 |
52 |
Correct |
12 ms |
23884 KB |
n=500 |
53 |
Correct |
13 ms |
23884 KB |
n=500 |
54 |
Correct |
12 ms |
23884 KB |
n=500 |
55 |
Correct |
12 ms |
23836 KB |
n=278 |
56 |
Correct |
15 ms |
23884 KB |
n=500 |
57 |
Correct |
12 ms |
23884 KB |
n=500 |
58 |
Correct |
12 ms |
23792 KB |
n=500 |
59 |
Correct |
16 ms |
24132 KB |
n=2000 |
60 |
Correct |
14 ms |
24268 KB |
n=2000 |
61 |
Correct |
14 ms |
24184 KB |
n=2000 |
62 |
Correct |
14 ms |
24140 KB |
n=2000 |
63 |
Correct |
14 ms |
24220 KB |
n=2000 |
64 |
Correct |
14 ms |
24200 KB |
n=2000 |
65 |
Correct |
14 ms |
24164 KB |
n=2000 |
66 |
Correct |
14 ms |
24268 KB |
n=2000 |
67 |
Correct |
15 ms |
24140 KB |
n=2000 |
68 |
Correct |
14 ms |
24268 KB |
n=2000 |
69 |
Correct |
14 ms |
24140 KB |
n=2000 |
70 |
Correct |
14 ms |
24120 KB |
n=2000 |
71 |
Correct |
15 ms |
24268 KB |
n=2000 |
72 |
Correct |
13 ms |
24140 KB |
n=2000 |
73 |
Correct |
14 ms |
24140 KB |
n=2000 |
74 |
Correct |
14 ms |
24140 KB |
n=1844 |
75 |
Correct |
14 ms |
24200 KB |
n=2000 |
76 |
Correct |
15 ms |
24140 KB |
n=2000 |
77 |
Correct |
14 ms |
24140 KB |
n=2000 |
78 |
Correct |
14 ms |
24144 KB |
n=2000 |
79 |
Correct |
14 ms |
24152 KB |
n=2000 |
80 |
Correct |
14 ms |
24268 KB |
n=2000 |
81 |
Correct |
14 ms |
24140 KB |
n=2000 |
82 |
Correct |
14 ms |
24116 KB |
n=2000 |
83 |
Correct |
14 ms |
24248 KB |
n=2000 |
84 |
Correct |
16 ms |
24144 KB |
n=2000 |
85 |
Correct |
15 ms |
24140 KB |
n=2000 |
86 |
Correct |
15 ms |
24240 KB |
n=2000 |
87 |
Correct |
14 ms |
24152 KB |
n=2000 |
88 |
Correct |
14 ms |
24292 KB |
n=2000 |
89 |
Correct |
14 ms |
24328 KB |
n=2000 |
90 |
Correct |
14 ms |
24268 KB |
n=2000 |
91 |
Correct |
14 ms |
24184 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23756 KB |
n=5 |
2 |
Correct |
12 ms |
23756 KB |
n=100 |
3 |
Correct |
12 ms |
23792 KB |
n=100 |
4 |
Correct |
12 ms |
23756 KB |
n=100 |
5 |
Correct |
12 ms |
23756 KB |
n=100 |
6 |
Correct |
13 ms |
23736 KB |
n=100 |
7 |
Correct |
12 ms |
23728 KB |
n=100 |
8 |
Correct |
12 ms |
23756 KB |
n=100 |
9 |
Correct |
11 ms |
23780 KB |
n=100 |
10 |
Correct |
11 ms |
23776 KB |
n=100 |
11 |
Correct |
12 ms |
23824 KB |
n=100 |
12 |
Correct |
12 ms |
23756 KB |
n=100 |
13 |
Correct |
12 ms |
23760 KB |
n=100 |
14 |
Correct |
12 ms |
23756 KB |
n=100 |
15 |
Correct |
12 ms |
23756 KB |
n=100 |
16 |
Correct |
12 ms |
23756 KB |
n=100 |
17 |
Correct |
12 ms |
23756 KB |
n=100 |
18 |
Correct |
12 ms |
23824 KB |
n=100 |
19 |
Correct |
12 ms |
23756 KB |
n=100 |
20 |
Correct |
12 ms |
23708 KB |
n=100 |
21 |
Correct |
15 ms |
23736 KB |
n=100 |
22 |
Correct |
12 ms |
23704 KB |
n=100 |
23 |
Correct |
12 ms |
23756 KB |
n=100 |
24 |
Correct |
11 ms |
23756 KB |
n=100 |
25 |
Correct |
12 ms |
23756 KB |
n=100 |
26 |
Correct |
12 ms |
23800 KB |
n=12 |
27 |
Correct |
12 ms |
23756 KB |
n=100 |
28 |
Correct |
14 ms |
23912 KB |
n=500 |
29 |
Correct |
12 ms |
23884 KB |
n=500 |
30 |
Correct |
13 ms |
23884 KB |
n=500 |
31 |
Correct |
12 ms |
23820 KB |
n=500 |
32 |
Correct |
13 ms |
23884 KB |
n=500 |
33 |
Correct |
13 ms |
23852 KB |
n=500 |
34 |
Correct |
12 ms |
23884 KB |
n=500 |
35 |
Correct |
12 ms |
23884 KB |
n=500 |
36 |
Correct |
13 ms |
23884 KB |
n=500 |
37 |
Correct |
12 ms |
23884 KB |
n=500 |
38 |
Correct |
12 ms |
23884 KB |
n=500 |
39 |
Correct |
12 ms |
23868 KB |
n=500 |
40 |
Correct |
12 ms |
23876 KB |
n=500 |
41 |
Correct |
12 ms |
23884 KB |
n=500 |
42 |
Correct |
12 ms |
23884 KB |
n=500 |
43 |
Correct |
12 ms |
23884 KB |
n=500 |
44 |
Correct |
13 ms |
23884 KB |
n=500 |
45 |
Correct |
13 ms |
23884 KB |
n=500 |
46 |
Correct |
13 ms |
23892 KB |
n=500 |
47 |
Correct |
14 ms |
23812 KB |
n=500 |
48 |
Correct |
13 ms |
23884 KB |
n=500 |
49 |
Correct |
13 ms |
23824 KB |
n=500 |
50 |
Correct |
12 ms |
23820 KB |
n=500 |
51 |
Correct |
12 ms |
23872 KB |
n=500 |
52 |
Correct |
12 ms |
23884 KB |
n=500 |
53 |
Correct |
13 ms |
23884 KB |
n=500 |
54 |
Correct |
12 ms |
23884 KB |
n=500 |
55 |
Correct |
12 ms |
23836 KB |
n=278 |
56 |
Correct |
15 ms |
23884 KB |
n=500 |
57 |
Correct |
12 ms |
23884 KB |
n=500 |
58 |
Correct |
12 ms |
23792 KB |
n=500 |
59 |
Correct |
16 ms |
24132 KB |
n=2000 |
60 |
Correct |
14 ms |
24268 KB |
n=2000 |
61 |
Correct |
14 ms |
24184 KB |
n=2000 |
62 |
Correct |
14 ms |
24140 KB |
n=2000 |
63 |
Correct |
14 ms |
24220 KB |
n=2000 |
64 |
Correct |
14 ms |
24200 KB |
n=2000 |
65 |
Correct |
14 ms |
24164 KB |
n=2000 |
66 |
Correct |
14 ms |
24268 KB |
n=2000 |
67 |
Correct |
15 ms |
24140 KB |
n=2000 |
68 |
Correct |
14 ms |
24268 KB |
n=2000 |
69 |
Correct |
14 ms |
24140 KB |
n=2000 |
70 |
Correct |
14 ms |
24120 KB |
n=2000 |
71 |
Correct |
15 ms |
24268 KB |
n=2000 |
72 |
Correct |
13 ms |
24140 KB |
n=2000 |
73 |
Correct |
14 ms |
24140 KB |
n=2000 |
74 |
Correct |
14 ms |
24140 KB |
n=1844 |
75 |
Correct |
14 ms |
24200 KB |
n=2000 |
76 |
Correct |
15 ms |
24140 KB |
n=2000 |
77 |
Correct |
14 ms |
24140 KB |
n=2000 |
78 |
Correct |
14 ms |
24144 KB |
n=2000 |
79 |
Correct |
14 ms |
24152 KB |
n=2000 |
80 |
Correct |
14 ms |
24268 KB |
n=2000 |
81 |
Correct |
14 ms |
24140 KB |
n=2000 |
82 |
Correct |
14 ms |
24116 KB |
n=2000 |
83 |
Correct |
14 ms |
24248 KB |
n=2000 |
84 |
Correct |
16 ms |
24144 KB |
n=2000 |
85 |
Correct |
15 ms |
24140 KB |
n=2000 |
86 |
Correct |
15 ms |
24240 KB |
n=2000 |
87 |
Correct |
14 ms |
24152 KB |
n=2000 |
88 |
Correct |
14 ms |
24292 KB |
n=2000 |
89 |
Correct |
14 ms |
24328 KB |
n=2000 |
90 |
Correct |
14 ms |
24268 KB |
n=2000 |
91 |
Correct |
14 ms |
24184 KB |
n=2000 |
92 |
Correct |
600 ms |
65736 KB |
n=200000 |
93 |
Correct |
821 ms |
70156 KB |
n=200000 |
94 |
Incorrect |
878 ms |
74516 KB |
Wrong range. |
95 |
Halted |
0 ms |
0 KB |
- |