#include<bits/stdc++.h>
using namespace std;
#define jizz ios_base::sync_with_stdio(false);cin.tie(NULL);
typedef long long ll;
typedef pair<int,int> pii;
#define F first
#define S second
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define mkp make_pair
const int MAXN=2E5+10;
vector<int> G[MAXN];
set<int> st[MAXN];
int n, m, q, arr[2*MAXN], anc[20][MAXN], dep[MAXN];
void dfs(int x, int f){
anc[0][x]=f;
dep[x]=dep[f]+1;
for(auto i:G[x]){
if(i==f) continue;
dfs(i,x);
}
}
int lca(int u, int v){
if(dep[u]<dep[v]) swap(u,v);
int b=dep[u]-dep[v];
for(int c=0;b>0;c++){
if(b%2){
u=anc[c][u];
}
b/=2;
}
if(u==v) return u;
for(int i=__lg(n)+1;i>=0;i--){
if(anc[i][u]!=anc[i][v]){
u=anc[i][u];
v=anc[i][v];
}
}
return anc[0][u];
}
int main(){ jizz
cin>>n>>m>>q;
for(int i=0;i<n-1;i++){
int a, b;
cin>>a>>b;
G[a].pb(b);
G[b].pb(a);
}
dfs(1,0);
for(int i=1;(1<<i)<=n;i++){
for(int j=1;j<=n;j++){
anc[i][j]=anc[i-1][anc[i-1][j]];
}
}
for(int i=0;i<m;i++){
cin>>arr[2*i];
}
for(int i=0;i<m-1;i++){
arr[2*i+1]=lca(arr[2*i],arr[2*i+2]);
}
for(int i=0;i<2*m-1;i++){
st[arr[i]].insert(i);
}
for(int i=0;i<q;i++){
int type;
cin>>type;
if(type==1){
int pos, v;
cin>>pos>>v;
int p=2*(pos-1);
st[arr[p]].erase(p);
arr[p]=v;
st[arr[p]].insert(p);
if(p>0){
st[arr[p-1]].erase(p-1);
int c=lca(arr[p-2],v);
arr[p-1]=c;
st[arr[p-1]].insert(p-1);
}
if(p<2*(m-1)){
st[arr[p+1]].erase(p+1);
int c=lca(v,arr[p+2]);
arr[p+1]=c;
st[arr[p+1]].insert(p+1);
}
} else if(type==2){
int l, r, v;
cin>>l>>r>>v;
l=2*(l-1), r=2*(r-1);
auto p=st[v].lower_bound(l);
if(p==st[v].end()) cout<<"-1 -1\n";
else if((*p)>r) cout<<"-1 -1\n";
else if((*p)%2) cout<<(*p)/2+1<<" "<<(*p)/2+2<<"\n";
else cout<<(*p)/2+1<<" "<<(*p)/2+1<<"\n";
}
}
return 0;
}
/*
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 |
10 ms |
14444 KB |
n=5 |
2 |
Correct |
10 ms |
14444 KB |
n=100 |
3 |
Correct |
10 ms |
14444 KB |
n=100 |
4 |
Correct |
10 ms |
14464 KB |
n=100 |
5 |
Correct |
11 ms |
14444 KB |
n=100 |
6 |
Correct |
10 ms |
14444 KB |
n=100 |
7 |
Correct |
10 ms |
14464 KB |
n=100 |
8 |
Correct |
10 ms |
14584 KB |
n=100 |
9 |
Correct |
10 ms |
14444 KB |
n=100 |
10 |
Correct |
10 ms |
14444 KB |
n=100 |
11 |
Correct |
10 ms |
14444 KB |
n=100 |
12 |
Correct |
10 ms |
14444 KB |
n=100 |
13 |
Correct |
10 ms |
14464 KB |
n=100 |
14 |
Correct |
10 ms |
14444 KB |
n=100 |
15 |
Correct |
10 ms |
14444 KB |
n=100 |
16 |
Correct |
10 ms |
14444 KB |
n=100 |
17 |
Correct |
10 ms |
14444 KB |
n=100 |
18 |
Correct |
10 ms |
14444 KB |
n=100 |
19 |
Correct |
10 ms |
14444 KB |
n=100 |
20 |
Correct |
10 ms |
14548 KB |
n=100 |
21 |
Correct |
10 ms |
14444 KB |
n=100 |
22 |
Correct |
14 ms |
14444 KB |
n=100 |
23 |
Correct |
10 ms |
14444 KB |
n=100 |
24 |
Correct |
10 ms |
14444 KB |
n=100 |
25 |
Correct |
11 ms |
14444 KB |
n=100 |
26 |
Correct |
10 ms |
14464 KB |
n=12 |
27 |
Correct |
10 ms |
14444 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
14444 KB |
n=5 |
2 |
Correct |
10 ms |
14444 KB |
n=100 |
3 |
Correct |
10 ms |
14444 KB |
n=100 |
4 |
Correct |
10 ms |
14464 KB |
n=100 |
5 |
Correct |
11 ms |
14444 KB |
n=100 |
6 |
Correct |
10 ms |
14444 KB |
n=100 |
7 |
Correct |
10 ms |
14464 KB |
n=100 |
8 |
Correct |
10 ms |
14584 KB |
n=100 |
9 |
Correct |
10 ms |
14444 KB |
n=100 |
10 |
Correct |
10 ms |
14444 KB |
n=100 |
11 |
Correct |
10 ms |
14444 KB |
n=100 |
12 |
Correct |
10 ms |
14444 KB |
n=100 |
13 |
Correct |
10 ms |
14464 KB |
n=100 |
14 |
Correct |
10 ms |
14444 KB |
n=100 |
15 |
Correct |
10 ms |
14444 KB |
n=100 |
16 |
Correct |
10 ms |
14444 KB |
n=100 |
17 |
Correct |
10 ms |
14444 KB |
n=100 |
18 |
Correct |
10 ms |
14444 KB |
n=100 |
19 |
Correct |
10 ms |
14444 KB |
n=100 |
20 |
Correct |
10 ms |
14548 KB |
n=100 |
21 |
Correct |
10 ms |
14444 KB |
n=100 |
22 |
Correct |
14 ms |
14444 KB |
n=100 |
23 |
Correct |
10 ms |
14444 KB |
n=100 |
24 |
Correct |
10 ms |
14444 KB |
n=100 |
25 |
Correct |
11 ms |
14444 KB |
n=100 |
26 |
Correct |
10 ms |
14464 KB |
n=12 |
27 |
Correct |
10 ms |
14444 KB |
n=100 |
28 |
Correct |
11 ms |
14700 KB |
n=500 |
29 |
Correct |
11 ms |
14572 KB |
n=500 |
30 |
Correct |
11 ms |
14572 KB |
n=500 |
31 |
Correct |
11 ms |
14572 KB |
n=500 |
32 |
Correct |
11 ms |
14572 KB |
n=500 |
33 |
Correct |
11 ms |
14572 KB |
n=500 |
34 |
Correct |
11 ms |
14572 KB |
n=500 |
35 |
Correct |
11 ms |
14572 KB |
n=500 |
36 |
Correct |
10 ms |
14572 KB |
n=500 |
37 |
Correct |
11 ms |
14592 KB |
n=500 |
38 |
Correct |
11 ms |
14572 KB |
n=500 |
39 |
Correct |
11 ms |
14572 KB |
n=500 |
40 |
Correct |
10 ms |
14592 KB |
n=500 |
41 |
Correct |
10 ms |
14572 KB |
n=500 |
42 |
Correct |
11 ms |
14572 KB |
n=500 |
43 |
Correct |
11 ms |
14572 KB |
n=500 |
44 |
Correct |
11 ms |
14572 KB |
n=500 |
45 |
Correct |
11 ms |
14572 KB |
n=500 |
46 |
Correct |
11 ms |
14572 KB |
n=500 |
47 |
Correct |
13 ms |
14572 KB |
n=500 |
48 |
Correct |
11 ms |
14572 KB |
n=500 |
49 |
Correct |
11 ms |
14572 KB |
n=500 |
50 |
Correct |
11 ms |
14604 KB |
n=500 |
51 |
Correct |
11 ms |
14572 KB |
n=500 |
52 |
Correct |
11 ms |
14572 KB |
n=500 |
53 |
Correct |
11 ms |
14572 KB |
n=500 |
54 |
Correct |
12 ms |
14572 KB |
n=500 |
55 |
Correct |
11 ms |
14572 KB |
n=278 |
56 |
Correct |
11 ms |
14572 KB |
n=500 |
57 |
Correct |
10 ms |
14572 KB |
n=500 |
58 |
Correct |
11 ms |
14572 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
14444 KB |
n=5 |
2 |
Correct |
10 ms |
14444 KB |
n=100 |
3 |
Correct |
10 ms |
14444 KB |
n=100 |
4 |
Correct |
10 ms |
14464 KB |
n=100 |
5 |
Correct |
11 ms |
14444 KB |
n=100 |
6 |
Correct |
10 ms |
14444 KB |
n=100 |
7 |
Correct |
10 ms |
14464 KB |
n=100 |
8 |
Correct |
10 ms |
14584 KB |
n=100 |
9 |
Correct |
10 ms |
14444 KB |
n=100 |
10 |
Correct |
10 ms |
14444 KB |
n=100 |
11 |
Correct |
10 ms |
14444 KB |
n=100 |
12 |
Correct |
10 ms |
14444 KB |
n=100 |
13 |
Correct |
10 ms |
14464 KB |
n=100 |
14 |
Correct |
10 ms |
14444 KB |
n=100 |
15 |
Correct |
10 ms |
14444 KB |
n=100 |
16 |
Correct |
10 ms |
14444 KB |
n=100 |
17 |
Correct |
10 ms |
14444 KB |
n=100 |
18 |
Correct |
10 ms |
14444 KB |
n=100 |
19 |
Correct |
10 ms |
14444 KB |
n=100 |
20 |
Correct |
10 ms |
14548 KB |
n=100 |
21 |
Correct |
10 ms |
14444 KB |
n=100 |
22 |
Correct |
14 ms |
14444 KB |
n=100 |
23 |
Correct |
10 ms |
14444 KB |
n=100 |
24 |
Correct |
10 ms |
14444 KB |
n=100 |
25 |
Correct |
11 ms |
14444 KB |
n=100 |
26 |
Correct |
10 ms |
14464 KB |
n=12 |
27 |
Correct |
10 ms |
14444 KB |
n=100 |
28 |
Correct |
11 ms |
14700 KB |
n=500 |
29 |
Correct |
11 ms |
14572 KB |
n=500 |
30 |
Correct |
11 ms |
14572 KB |
n=500 |
31 |
Correct |
11 ms |
14572 KB |
n=500 |
32 |
Correct |
11 ms |
14572 KB |
n=500 |
33 |
Correct |
11 ms |
14572 KB |
n=500 |
34 |
Correct |
11 ms |
14572 KB |
n=500 |
35 |
Correct |
11 ms |
14572 KB |
n=500 |
36 |
Correct |
10 ms |
14572 KB |
n=500 |
37 |
Correct |
11 ms |
14592 KB |
n=500 |
38 |
Correct |
11 ms |
14572 KB |
n=500 |
39 |
Correct |
11 ms |
14572 KB |
n=500 |
40 |
Correct |
10 ms |
14592 KB |
n=500 |
41 |
Correct |
10 ms |
14572 KB |
n=500 |
42 |
Correct |
11 ms |
14572 KB |
n=500 |
43 |
Correct |
11 ms |
14572 KB |
n=500 |
44 |
Correct |
11 ms |
14572 KB |
n=500 |
45 |
Correct |
11 ms |
14572 KB |
n=500 |
46 |
Correct |
11 ms |
14572 KB |
n=500 |
47 |
Correct |
13 ms |
14572 KB |
n=500 |
48 |
Correct |
11 ms |
14572 KB |
n=500 |
49 |
Correct |
11 ms |
14572 KB |
n=500 |
50 |
Correct |
11 ms |
14604 KB |
n=500 |
51 |
Correct |
11 ms |
14572 KB |
n=500 |
52 |
Correct |
11 ms |
14572 KB |
n=500 |
53 |
Correct |
11 ms |
14572 KB |
n=500 |
54 |
Correct |
12 ms |
14572 KB |
n=500 |
55 |
Correct |
11 ms |
14572 KB |
n=278 |
56 |
Correct |
11 ms |
14572 KB |
n=500 |
57 |
Correct |
10 ms |
14572 KB |
n=500 |
58 |
Correct |
11 ms |
14572 KB |
n=500 |
59 |
Correct |
13 ms |
14828 KB |
n=2000 |
60 |
Correct |
16 ms |
14956 KB |
n=2000 |
61 |
Correct |
13 ms |
14956 KB |
n=2000 |
62 |
Correct |
13 ms |
14956 KB |
n=2000 |
63 |
Correct |
13 ms |
14828 KB |
n=2000 |
64 |
Correct |
13 ms |
14956 KB |
n=2000 |
65 |
Correct |
13 ms |
14828 KB |
n=2000 |
66 |
Correct |
15 ms |
14956 KB |
n=2000 |
67 |
Correct |
14 ms |
14828 KB |
n=2000 |
68 |
Correct |
13 ms |
14956 KB |
n=2000 |
69 |
Correct |
12 ms |
14828 KB |
n=2000 |
70 |
Correct |
13 ms |
14828 KB |
n=2000 |
71 |
Correct |
13 ms |
14828 KB |
n=2000 |
72 |
Correct |
12 ms |
14828 KB |
n=2000 |
73 |
Correct |
12 ms |
14828 KB |
n=2000 |
74 |
Correct |
13 ms |
14828 KB |
n=1844 |
75 |
Correct |
15 ms |
14828 KB |
n=2000 |
76 |
Correct |
14 ms |
14828 KB |
n=2000 |
77 |
Correct |
15 ms |
14828 KB |
n=2000 |
78 |
Correct |
15 ms |
14828 KB |
n=2000 |
79 |
Correct |
15 ms |
14976 KB |
n=2000 |
80 |
Correct |
13 ms |
14956 KB |
n=2000 |
81 |
Correct |
13 ms |
14956 KB |
n=2000 |
82 |
Correct |
14 ms |
14828 KB |
n=2000 |
83 |
Correct |
13 ms |
14956 KB |
n=2000 |
84 |
Correct |
13 ms |
14828 KB |
n=2000 |
85 |
Correct |
13 ms |
14956 KB |
n=2000 |
86 |
Correct |
13 ms |
14956 KB |
n=2000 |
87 |
Correct |
13 ms |
14828 KB |
n=2000 |
88 |
Correct |
13 ms |
14956 KB |
n=2000 |
89 |
Correct |
13 ms |
14956 KB |
n=2000 |
90 |
Correct |
13 ms |
14956 KB |
n=2000 |
91 |
Correct |
13 ms |
14828 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
14444 KB |
n=5 |
2 |
Correct |
10 ms |
14444 KB |
n=100 |
3 |
Correct |
10 ms |
14444 KB |
n=100 |
4 |
Correct |
10 ms |
14464 KB |
n=100 |
5 |
Correct |
11 ms |
14444 KB |
n=100 |
6 |
Correct |
10 ms |
14444 KB |
n=100 |
7 |
Correct |
10 ms |
14464 KB |
n=100 |
8 |
Correct |
10 ms |
14584 KB |
n=100 |
9 |
Correct |
10 ms |
14444 KB |
n=100 |
10 |
Correct |
10 ms |
14444 KB |
n=100 |
11 |
Correct |
10 ms |
14444 KB |
n=100 |
12 |
Correct |
10 ms |
14444 KB |
n=100 |
13 |
Correct |
10 ms |
14464 KB |
n=100 |
14 |
Correct |
10 ms |
14444 KB |
n=100 |
15 |
Correct |
10 ms |
14444 KB |
n=100 |
16 |
Correct |
10 ms |
14444 KB |
n=100 |
17 |
Correct |
10 ms |
14444 KB |
n=100 |
18 |
Correct |
10 ms |
14444 KB |
n=100 |
19 |
Correct |
10 ms |
14444 KB |
n=100 |
20 |
Correct |
10 ms |
14548 KB |
n=100 |
21 |
Correct |
10 ms |
14444 KB |
n=100 |
22 |
Correct |
14 ms |
14444 KB |
n=100 |
23 |
Correct |
10 ms |
14444 KB |
n=100 |
24 |
Correct |
10 ms |
14444 KB |
n=100 |
25 |
Correct |
11 ms |
14444 KB |
n=100 |
26 |
Correct |
10 ms |
14464 KB |
n=12 |
27 |
Correct |
10 ms |
14444 KB |
n=100 |
28 |
Correct |
11 ms |
14700 KB |
n=500 |
29 |
Correct |
11 ms |
14572 KB |
n=500 |
30 |
Correct |
11 ms |
14572 KB |
n=500 |
31 |
Correct |
11 ms |
14572 KB |
n=500 |
32 |
Correct |
11 ms |
14572 KB |
n=500 |
33 |
Correct |
11 ms |
14572 KB |
n=500 |
34 |
Correct |
11 ms |
14572 KB |
n=500 |
35 |
Correct |
11 ms |
14572 KB |
n=500 |
36 |
Correct |
10 ms |
14572 KB |
n=500 |
37 |
Correct |
11 ms |
14592 KB |
n=500 |
38 |
Correct |
11 ms |
14572 KB |
n=500 |
39 |
Correct |
11 ms |
14572 KB |
n=500 |
40 |
Correct |
10 ms |
14592 KB |
n=500 |
41 |
Correct |
10 ms |
14572 KB |
n=500 |
42 |
Correct |
11 ms |
14572 KB |
n=500 |
43 |
Correct |
11 ms |
14572 KB |
n=500 |
44 |
Correct |
11 ms |
14572 KB |
n=500 |
45 |
Correct |
11 ms |
14572 KB |
n=500 |
46 |
Correct |
11 ms |
14572 KB |
n=500 |
47 |
Correct |
13 ms |
14572 KB |
n=500 |
48 |
Correct |
11 ms |
14572 KB |
n=500 |
49 |
Correct |
11 ms |
14572 KB |
n=500 |
50 |
Correct |
11 ms |
14604 KB |
n=500 |
51 |
Correct |
11 ms |
14572 KB |
n=500 |
52 |
Correct |
11 ms |
14572 KB |
n=500 |
53 |
Correct |
11 ms |
14572 KB |
n=500 |
54 |
Correct |
12 ms |
14572 KB |
n=500 |
55 |
Correct |
11 ms |
14572 KB |
n=278 |
56 |
Correct |
11 ms |
14572 KB |
n=500 |
57 |
Correct |
10 ms |
14572 KB |
n=500 |
58 |
Correct |
11 ms |
14572 KB |
n=500 |
59 |
Correct |
13 ms |
14828 KB |
n=2000 |
60 |
Correct |
16 ms |
14956 KB |
n=2000 |
61 |
Correct |
13 ms |
14956 KB |
n=2000 |
62 |
Correct |
13 ms |
14956 KB |
n=2000 |
63 |
Correct |
13 ms |
14828 KB |
n=2000 |
64 |
Correct |
13 ms |
14956 KB |
n=2000 |
65 |
Correct |
13 ms |
14828 KB |
n=2000 |
66 |
Correct |
15 ms |
14956 KB |
n=2000 |
67 |
Correct |
14 ms |
14828 KB |
n=2000 |
68 |
Correct |
13 ms |
14956 KB |
n=2000 |
69 |
Correct |
12 ms |
14828 KB |
n=2000 |
70 |
Correct |
13 ms |
14828 KB |
n=2000 |
71 |
Correct |
13 ms |
14828 KB |
n=2000 |
72 |
Correct |
12 ms |
14828 KB |
n=2000 |
73 |
Correct |
12 ms |
14828 KB |
n=2000 |
74 |
Correct |
13 ms |
14828 KB |
n=1844 |
75 |
Correct |
15 ms |
14828 KB |
n=2000 |
76 |
Correct |
14 ms |
14828 KB |
n=2000 |
77 |
Correct |
15 ms |
14828 KB |
n=2000 |
78 |
Correct |
15 ms |
14828 KB |
n=2000 |
79 |
Correct |
15 ms |
14976 KB |
n=2000 |
80 |
Correct |
13 ms |
14956 KB |
n=2000 |
81 |
Correct |
13 ms |
14956 KB |
n=2000 |
82 |
Correct |
14 ms |
14828 KB |
n=2000 |
83 |
Correct |
13 ms |
14956 KB |
n=2000 |
84 |
Correct |
13 ms |
14828 KB |
n=2000 |
85 |
Correct |
13 ms |
14956 KB |
n=2000 |
86 |
Correct |
13 ms |
14956 KB |
n=2000 |
87 |
Correct |
13 ms |
14828 KB |
n=2000 |
88 |
Correct |
13 ms |
14956 KB |
n=2000 |
89 |
Correct |
13 ms |
14956 KB |
n=2000 |
90 |
Correct |
13 ms |
14956 KB |
n=2000 |
91 |
Correct |
13 ms |
14828 KB |
n=2000 |
92 |
Correct |
828 ms |
58092 KB |
n=200000 |
93 |
Correct |
891 ms |
63852 KB |
n=200000 |
94 |
Correct |
853 ms |
66924 KB |
n=200000 |
95 |
Correct |
809 ms |
59872 KB |
n=200000 |
96 |
Correct |
809 ms |
59744 KB |
n=200000 |
97 |
Correct |
955 ms |
62916 KB |
n=200000 |
98 |
Correct |
805 ms |
59872 KB |
n=200000 |
99 |
Correct |
1048 ms |
59260 KB |
n=200000 |
100 |
Correct |
858 ms |
59748 KB |
n=200000 |
101 |
Correct |
820 ms |
68076 KB |
n=200000 |
102 |
Correct |
487 ms |
60780 KB |
n=200000 |
103 |
Correct |
499 ms |
60832 KB |
n=200000 |
104 |
Correct |
473 ms |
60780 KB |
n=200000 |
105 |
Correct |
485 ms |
60396 KB |
n=200000 |
106 |
Correct |
506 ms |
60524 KB |
n=200000 |
107 |
Correct |
483 ms |
60524 KB |
n=200000 |
108 |
Correct |
901 ms |
59244 KB |
n=200000 |
109 |
Correct |
912 ms |
58600 KB |
n=200000 |
110 |
Correct |
908 ms |
58732 KB |
n=200000 |
111 |
Correct |
834 ms |
59008 KB |
n=200000 |
112 |
Correct |
845 ms |
66412 KB |
n=200000 |
113 |
Correct |
899 ms |
61932 KB |
n=200000 |
114 |
Correct |
830 ms |
58976 KB |
n=200000 |
115 |
Correct |
1080 ms |
59924 KB |
n=200000 |
116 |
Correct |
786 ms |
58836 KB |
n=200000 |
117 |
Correct |
772 ms |
66792 KB |
n=200000 |
118 |
Correct |
957 ms |
60652 KB |
n=200000 |
119 |
Correct |
777 ms |
58628 KB |
n=200000 |
120 |
Correct |
737 ms |
67052 KB |
n=200000 |
121 |
Correct |
756 ms |
67052 KB |
n=200000 |
122 |
Correct |
774 ms |
67652 KB |
n=200000 |
123 |
Correct |
468 ms |
59244 KB |
n=200000 |
124 |
Correct |
183 ms |
28652 KB |
n=25264 |