// 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][20],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<20;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<20;i++){
if((1<<i)&k){
a=up[a][i];
}
}
if(a==b) return a;
for(int i=19;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
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23756 KB |
n=5 |
2 |
Correct |
11 ms |
23772 KB |
n=100 |
3 |
Correct |
12 ms |
23808 KB |
n=100 |
4 |
Correct |
13 ms |
23700 KB |
n=100 |
5 |
Correct |
14 ms |
23820 KB |
n=100 |
6 |
Correct |
16 ms |
23756 KB |
n=100 |
7 |
Correct |
13 ms |
23724 KB |
n=100 |
8 |
Correct |
12 ms |
23828 KB |
n=100 |
9 |
Correct |
12 ms |
23824 KB |
n=100 |
10 |
Correct |
12 ms |
23756 KB |
n=100 |
11 |
Correct |
14 ms |
23808 KB |
n=100 |
12 |
Correct |
14 ms |
23804 KB |
n=100 |
13 |
Correct |
12 ms |
23784 KB |
n=100 |
14 |
Correct |
12 ms |
23824 KB |
n=100 |
15 |
Correct |
14 ms |
23744 KB |
n=100 |
16 |
Correct |
12 ms |
23712 KB |
n=100 |
17 |
Correct |
12 ms |
23756 KB |
n=100 |
18 |
Correct |
13 ms |
23756 KB |
n=100 |
19 |
Correct |
12 ms |
23756 KB |
n=100 |
20 |
Correct |
12 ms |
23756 KB |
n=100 |
21 |
Correct |
12 ms |
23792 KB |
n=100 |
22 |
Correct |
11 ms |
23704 KB |
n=100 |
23 |
Correct |
11 ms |
23756 KB |
n=100 |
24 |
Correct |
12 ms |
23820 KB |
n=100 |
25 |
Correct |
12 ms |
23744 KB |
n=100 |
26 |
Correct |
12 ms |
23752 KB |
n=12 |
27 |
Correct |
12 ms |
23756 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23756 KB |
n=5 |
2 |
Correct |
11 ms |
23772 KB |
n=100 |
3 |
Correct |
12 ms |
23808 KB |
n=100 |
4 |
Correct |
13 ms |
23700 KB |
n=100 |
5 |
Correct |
14 ms |
23820 KB |
n=100 |
6 |
Correct |
16 ms |
23756 KB |
n=100 |
7 |
Correct |
13 ms |
23724 KB |
n=100 |
8 |
Correct |
12 ms |
23828 KB |
n=100 |
9 |
Correct |
12 ms |
23824 KB |
n=100 |
10 |
Correct |
12 ms |
23756 KB |
n=100 |
11 |
Correct |
14 ms |
23808 KB |
n=100 |
12 |
Correct |
14 ms |
23804 KB |
n=100 |
13 |
Correct |
12 ms |
23784 KB |
n=100 |
14 |
Correct |
12 ms |
23824 KB |
n=100 |
15 |
Correct |
14 ms |
23744 KB |
n=100 |
16 |
Correct |
12 ms |
23712 KB |
n=100 |
17 |
Correct |
12 ms |
23756 KB |
n=100 |
18 |
Correct |
13 ms |
23756 KB |
n=100 |
19 |
Correct |
12 ms |
23756 KB |
n=100 |
20 |
Correct |
12 ms |
23756 KB |
n=100 |
21 |
Correct |
12 ms |
23792 KB |
n=100 |
22 |
Correct |
11 ms |
23704 KB |
n=100 |
23 |
Correct |
11 ms |
23756 KB |
n=100 |
24 |
Correct |
12 ms |
23820 KB |
n=100 |
25 |
Correct |
12 ms |
23744 KB |
n=100 |
26 |
Correct |
12 ms |
23752 KB |
n=12 |
27 |
Correct |
12 ms |
23756 KB |
n=100 |
28 |
Correct |
12 ms |
23868 KB |
n=500 |
29 |
Correct |
12 ms |
23940 KB |
n=500 |
30 |
Correct |
13 ms |
23920 KB |
n=500 |
31 |
Correct |
12 ms |
23808 KB |
n=500 |
32 |
Correct |
12 ms |
23884 KB |
n=500 |
33 |
Correct |
12 ms |
23884 KB |
n=500 |
34 |
Correct |
13 ms |
23808 KB |
n=500 |
35 |
Correct |
13 ms |
23884 KB |
n=500 |
36 |
Correct |
13 ms |
23808 KB |
n=500 |
37 |
Correct |
13 ms |
23808 KB |
n=500 |
38 |
Correct |
13 ms |
23884 KB |
n=500 |
39 |
Correct |
12 ms |
23816 KB |
n=500 |
40 |
Correct |
12 ms |
23820 KB |
n=500 |
41 |
Correct |
13 ms |
23820 KB |
n=500 |
42 |
Correct |
12 ms |
23884 KB |
n=500 |
43 |
Correct |
12 ms |
23852 KB |
n=500 |
44 |
Correct |
12 ms |
23816 KB |
n=500 |
45 |
Correct |
12 ms |
23808 KB |
n=500 |
46 |
Correct |
12 ms |
23884 KB |
n=500 |
47 |
Correct |
13 ms |
23944 KB |
n=500 |
48 |
Correct |
13 ms |
23884 KB |
n=500 |
49 |
Correct |
13 ms |
23884 KB |
n=500 |
50 |
Correct |
12 ms |
23916 KB |
n=500 |
51 |
Correct |
13 ms |
23884 KB |
n=500 |
52 |
Correct |
14 ms |
23936 KB |
n=500 |
53 |
Correct |
15 ms |
23908 KB |
n=500 |
54 |
Correct |
12 ms |
23900 KB |
n=500 |
55 |
Correct |
12 ms |
23892 KB |
n=278 |
56 |
Correct |
13 ms |
23884 KB |
n=500 |
57 |
Correct |
12 ms |
23944 KB |
n=500 |
58 |
Correct |
13 ms |
23884 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23756 KB |
n=5 |
2 |
Correct |
11 ms |
23772 KB |
n=100 |
3 |
Correct |
12 ms |
23808 KB |
n=100 |
4 |
Correct |
13 ms |
23700 KB |
n=100 |
5 |
Correct |
14 ms |
23820 KB |
n=100 |
6 |
Correct |
16 ms |
23756 KB |
n=100 |
7 |
Correct |
13 ms |
23724 KB |
n=100 |
8 |
Correct |
12 ms |
23828 KB |
n=100 |
9 |
Correct |
12 ms |
23824 KB |
n=100 |
10 |
Correct |
12 ms |
23756 KB |
n=100 |
11 |
Correct |
14 ms |
23808 KB |
n=100 |
12 |
Correct |
14 ms |
23804 KB |
n=100 |
13 |
Correct |
12 ms |
23784 KB |
n=100 |
14 |
Correct |
12 ms |
23824 KB |
n=100 |
15 |
Correct |
14 ms |
23744 KB |
n=100 |
16 |
Correct |
12 ms |
23712 KB |
n=100 |
17 |
Correct |
12 ms |
23756 KB |
n=100 |
18 |
Correct |
13 ms |
23756 KB |
n=100 |
19 |
Correct |
12 ms |
23756 KB |
n=100 |
20 |
Correct |
12 ms |
23756 KB |
n=100 |
21 |
Correct |
12 ms |
23792 KB |
n=100 |
22 |
Correct |
11 ms |
23704 KB |
n=100 |
23 |
Correct |
11 ms |
23756 KB |
n=100 |
24 |
Correct |
12 ms |
23820 KB |
n=100 |
25 |
Correct |
12 ms |
23744 KB |
n=100 |
26 |
Correct |
12 ms |
23752 KB |
n=12 |
27 |
Correct |
12 ms |
23756 KB |
n=100 |
28 |
Correct |
12 ms |
23868 KB |
n=500 |
29 |
Correct |
12 ms |
23940 KB |
n=500 |
30 |
Correct |
13 ms |
23920 KB |
n=500 |
31 |
Correct |
12 ms |
23808 KB |
n=500 |
32 |
Correct |
12 ms |
23884 KB |
n=500 |
33 |
Correct |
12 ms |
23884 KB |
n=500 |
34 |
Correct |
13 ms |
23808 KB |
n=500 |
35 |
Correct |
13 ms |
23884 KB |
n=500 |
36 |
Correct |
13 ms |
23808 KB |
n=500 |
37 |
Correct |
13 ms |
23808 KB |
n=500 |
38 |
Correct |
13 ms |
23884 KB |
n=500 |
39 |
Correct |
12 ms |
23816 KB |
n=500 |
40 |
Correct |
12 ms |
23820 KB |
n=500 |
41 |
Correct |
13 ms |
23820 KB |
n=500 |
42 |
Correct |
12 ms |
23884 KB |
n=500 |
43 |
Correct |
12 ms |
23852 KB |
n=500 |
44 |
Correct |
12 ms |
23816 KB |
n=500 |
45 |
Correct |
12 ms |
23808 KB |
n=500 |
46 |
Correct |
12 ms |
23884 KB |
n=500 |
47 |
Correct |
13 ms |
23944 KB |
n=500 |
48 |
Correct |
13 ms |
23884 KB |
n=500 |
49 |
Correct |
13 ms |
23884 KB |
n=500 |
50 |
Correct |
12 ms |
23916 KB |
n=500 |
51 |
Correct |
13 ms |
23884 KB |
n=500 |
52 |
Correct |
14 ms |
23936 KB |
n=500 |
53 |
Correct |
15 ms |
23908 KB |
n=500 |
54 |
Correct |
12 ms |
23900 KB |
n=500 |
55 |
Correct |
12 ms |
23892 KB |
n=278 |
56 |
Correct |
13 ms |
23884 KB |
n=500 |
57 |
Correct |
12 ms |
23944 KB |
n=500 |
58 |
Correct |
13 ms |
23884 KB |
n=500 |
59 |
Correct |
16 ms |
24260 KB |
n=2000 |
60 |
Correct |
14 ms |
24324 KB |
n=2000 |
61 |
Correct |
15 ms |
24244 KB |
n=2000 |
62 |
Correct |
15 ms |
24188 KB |
n=2000 |
63 |
Correct |
15 ms |
24268 KB |
n=2000 |
64 |
Correct |
15 ms |
24328 KB |
n=2000 |
65 |
Correct |
15 ms |
24224 KB |
n=2000 |
66 |
Correct |
14 ms |
24348 KB |
n=2000 |
67 |
Correct |
15 ms |
24196 KB |
n=2000 |
68 |
Correct |
19 ms |
24324 KB |
n=2000 |
69 |
Correct |
15 ms |
24268 KB |
n=2000 |
70 |
Correct |
14 ms |
24260 KB |
n=2000 |
71 |
Correct |
14 ms |
24276 KB |
n=2000 |
72 |
Correct |
14 ms |
24268 KB |
n=2000 |
73 |
Correct |
14 ms |
24268 KB |
n=2000 |
74 |
Correct |
14 ms |
24192 KB |
n=1844 |
75 |
Correct |
14 ms |
24200 KB |
n=2000 |
76 |
Correct |
15 ms |
24224 KB |
n=2000 |
77 |
Correct |
17 ms |
24268 KB |
n=2000 |
78 |
Correct |
16 ms |
24296 KB |
n=2000 |
79 |
Correct |
14 ms |
24284 KB |
n=2000 |
80 |
Correct |
15 ms |
24324 KB |
n=2000 |
81 |
Correct |
15 ms |
24268 KB |
n=2000 |
82 |
Correct |
14 ms |
24268 KB |
n=2000 |
83 |
Correct |
15 ms |
24348 KB |
n=2000 |
84 |
Correct |
15 ms |
24268 KB |
n=2000 |
85 |
Correct |
15 ms |
24324 KB |
n=2000 |
86 |
Correct |
15 ms |
24316 KB |
n=2000 |
87 |
Correct |
14 ms |
24268 KB |
n=2000 |
88 |
Correct |
14 ms |
24324 KB |
n=2000 |
89 |
Correct |
15 ms |
24396 KB |
n=2000 |
90 |
Correct |
15 ms |
24396 KB |
n=2000 |
91 |
Correct |
14 ms |
24284 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23756 KB |
n=5 |
2 |
Correct |
11 ms |
23772 KB |
n=100 |
3 |
Correct |
12 ms |
23808 KB |
n=100 |
4 |
Correct |
13 ms |
23700 KB |
n=100 |
5 |
Correct |
14 ms |
23820 KB |
n=100 |
6 |
Correct |
16 ms |
23756 KB |
n=100 |
7 |
Correct |
13 ms |
23724 KB |
n=100 |
8 |
Correct |
12 ms |
23828 KB |
n=100 |
9 |
Correct |
12 ms |
23824 KB |
n=100 |
10 |
Correct |
12 ms |
23756 KB |
n=100 |
11 |
Correct |
14 ms |
23808 KB |
n=100 |
12 |
Correct |
14 ms |
23804 KB |
n=100 |
13 |
Correct |
12 ms |
23784 KB |
n=100 |
14 |
Correct |
12 ms |
23824 KB |
n=100 |
15 |
Correct |
14 ms |
23744 KB |
n=100 |
16 |
Correct |
12 ms |
23712 KB |
n=100 |
17 |
Correct |
12 ms |
23756 KB |
n=100 |
18 |
Correct |
13 ms |
23756 KB |
n=100 |
19 |
Correct |
12 ms |
23756 KB |
n=100 |
20 |
Correct |
12 ms |
23756 KB |
n=100 |
21 |
Correct |
12 ms |
23792 KB |
n=100 |
22 |
Correct |
11 ms |
23704 KB |
n=100 |
23 |
Correct |
11 ms |
23756 KB |
n=100 |
24 |
Correct |
12 ms |
23820 KB |
n=100 |
25 |
Correct |
12 ms |
23744 KB |
n=100 |
26 |
Correct |
12 ms |
23752 KB |
n=12 |
27 |
Correct |
12 ms |
23756 KB |
n=100 |
28 |
Correct |
12 ms |
23868 KB |
n=500 |
29 |
Correct |
12 ms |
23940 KB |
n=500 |
30 |
Correct |
13 ms |
23920 KB |
n=500 |
31 |
Correct |
12 ms |
23808 KB |
n=500 |
32 |
Correct |
12 ms |
23884 KB |
n=500 |
33 |
Correct |
12 ms |
23884 KB |
n=500 |
34 |
Correct |
13 ms |
23808 KB |
n=500 |
35 |
Correct |
13 ms |
23884 KB |
n=500 |
36 |
Correct |
13 ms |
23808 KB |
n=500 |
37 |
Correct |
13 ms |
23808 KB |
n=500 |
38 |
Correct |
13 ms |
23884 KB |
n=500 |
39 |
Correct |
12 ms |
23816 KB |
n=500 |
40 |
Correct |
12 ms |
23820 KB |
n=500 |
41 |
Correct |
13 ms |
23820 KB |
n=500 |
42 |
Correct |
12 ms |
23884 KB |
n=500 |
43 |
Correct |
12 ms |
23852 KB |
n=500 |
44 |
Correct |
12 ms |
23816 KB |
n=500 |
45 |
Correct |
12 ms |
23808 KB |
n=500 |
46 |
Correct |
12 ms |
23884 KB |
n=500 |
47 |
Correct |
13 ms |
23944 KB |
n=500 |
48 |
Correct |
13 ms |
23884 KB |
n=500 |
49 |
Correct |
13 ms |
23884 KB |
n=500 |
50 |
Correct |
12 ms |
23916 KB |
n=500 |
51 |
Correct |
13 ms |
23884 KB |
n=500 |
52 |
Correct |
14 ms |
23936 KB |
n=500 |
53 |
Correct |
15 ms |
23908 KB |
n=500 |
54 |
Correct |
12 ms |
23900 KB |
n=500 |
55 |
Correct |
12 ms |
23892 KB |
n=278 |
56 |
Correct |
13 ms |
23884 KB |
n=500 |
57 |
Correct |
12 ms |
23944 KB |
n=500 |
58 |
Correct |
13 ms |
23884 KB |
n=500 |
59 |
Correct |
16 ms |
24260 KB |
n=2000 |
60 |
Correct |
14 ms |
24324 KB |
n=2000 |
61 |
Correct |
15 ms |
24244 KB |
n=2000 |
62 |
Correct |
15 ms |
24188 KB |
n=2000 |
63 |
Correct |
15 ms |
24268 KB |
n=2000 |
64 |
Correct |
15 ms |
24328 KB |
n=2000 |
65 |
Correct |
15 ms |
24224 KB |
n=2000 |
66 |
Correct |
14 ms |
24348 KB |
n=2000 |
67 |
Correct |
15 ms |
24196 KB |
n=2000 |
68 |
Correct |
19 ms |
24324 KB |
n=2000 |
69 |
Correct |
15 ms |
24268 KB |
n=2000 |
70 |
Correct |
14 ms |
24260 KB |
n=2000 |
71 |
Correct |
14 ms |
24276 KB |
n=2000 |
72 |
Correct |
14 ms |
24268 KB |
n=2000 |
73 |
Correct |
14 ms |
24268 KB |
n=2000 |
74 |
Correct |
14 ms |
24192 KB |
n=1844 |
75 |
Correct |
14 ms |
24200 KB |
n=2000 |
76 |
Correct |
15 ms |
24224 KB |
n=2000 |
77 |
Correct |
17 ms |
24268 KB |
n=2000 |
78 |
Correct |
16 ms |
24296 KB |
n=2000 |
79 |
Correct |
14 ms |
24284 KB |
n=2000 |
80 |
Correct |
15 ms |
24324 KB |
n=2000 |
81 |
Correct |
15 ms |
24268 KB |
n=2000 |
82 |
Correct |
14 ms |
24268 KB |
n=2000 |
83 |
Correct |
15 ms |
24348 KB |
n=2000 |
84 |
Correct |
15 ms |
24268 KB |
n=2000 |
85 |
Correct |
15 ms |
24324 KB |
n=2000 |
86 |
Correct |
15 ms |
24316 KB |
n=2000 |
87 |
Correct |
14 ms |
24268 KB |
n=2000 |
88 |
Correct |
14 ms |
24324 KB |
n=2000 |
89 |
Correct |
15 ms |
24396 KB |
n=2000 |
90 |
Correct |
15 ms |
24396 KB |
n=2000 |
91 |
Correct |
14 ms |
24284 KB |
n=2000 |
92 |
Correct |
621 ms |
74480 KB |
n=200000 |
93 |
Correct |
912 ms |
80172 KB |
n=200000 |
94 |
Correct |
895 ms |
84628 KB |
n=200000 |
95 |
Correct |
643 ms |
74384 KB |
n=200000 |
96 |
Correct |
620 ms |
74368 KB |
n=200000 |
97 |
Correct |
924 ms |
79020 KB |
n=200000 |
98 |
Correct |
619 ms |
74388 KB |
n=200000 |
99 |
Correct |
766 ms |
74496 KB |
n=200000 |
100 |
Correct |
650 ms |
74448 KB |
n=200000 |
101 |
Correct |
913 ms |
86308 KB |
n=200000 |
102 |
Correct |
405 ms |
75520 KB |
n=200000 |
103 |
Correct |
393 ms |
75492 KB |
n=200000 |
104 |
Correct |
376 ms |
75528 KB |
n=200000 |
105 |
Correct |
390 ms |
75936 KB |
n=200000 |
106 |
Correct |
409 ms |
75872 KB |
n=200000 |
107 |
Correct |
374 ms |
76084 KB |
n=200000 |
108 |
Correct |
691 ms |
74356 KB |
n=200000 |
109 |
Correct |
697 ms |
74556 KB |
n=200000 |
110 |
Correct |
685 ms |
74416 KB |
n=200000 |
111 |
Correct |
651 ms |
73772 KB |
n=200000 |
112 |
Correct |
856 ms |
84932 KB |
n=200000 |
113 |
Correct |
934 ms |
79088 KB |
n=200000 |
114 |
Correct |
658 ms |
73808 KB |
n=200000 |
115 |
Correct |
939 ms |
76240 KB |
n=200000 |
116 |
Correct |
571 ms |
74492 KB |
n=200000 |
117 |
Correct |
854 ms |
85540 KB |
n=200000 |
118 |
Correct |
897 ms |
77576 KB |
n=200000 |
119 |
Correct |
646 ms |
74692 KB |
n=200000 |
120 |
Correct |
806 ms |
85316 KB |
n=200000 |
121 |
Correct |
858 ms |
85360 KB |
n=200000 |
122 |
Correct |
818 ms |
85600 KB |
n=200000 |
123 |
Correct |
406 ms |
75640 KB |
n=200000 |
124 |
Correct |
199 ms |
38648 KB |
n=25264 |