// 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[n+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 |
11 ms |
23780 KB |
n=100 |
3 |
Correct |
12 ms |
23804 KB |
n=100 |
4 |
Correct |
12 ms |
23808 KB |
n=100 |
5 |
Correct |
13 ms |
23756 KB |
n=100 |
6 |
Correct |
11 ms |
23756 KB |
n=100 |
7 |
Correct |
12 ms |
23788 KB |
n=100 |
8 |
Correct |
11 ms |
23800 KB |
n=100 |
9 |
Correct |
13 ms |
23772 KB |
n=100 |
10 |
Correct |
13 ms |
23756 KB |
n=100 |
11 |
Correct |
12 ms |
23756 KB |
n=100 |
12 |
Correct |
13 ms |
23748 KB |
n=100 |
13 |
Correct |
12 ms |
23756 KB |
n=100 |
14 |
Correct |
13 ms |
23748 KB |
n=100 |
15 |
Correct |
15 ms |
23744 KB |
n=100 |
16 |
Correct |
13 ms |
23720 KB |
n=100 |
17 |
Correct |
12 ms |
23756 KB |
n=100 |
18 |
Correct |
12 ms |
23800 KB |
n=100 |
19 |
Correct |
12 ms |
23756 KB |
n=100 |
20 |
Correct |
12 ms |
23772 KB |
n=100 |
21 |
Correct |
13 ms |
23796 KB |
n=100 |
22 |
Correct |
12 ms |
23792 KB |
n=100 |
23 |
Correct |
12 ms |
23884 KB |
n=100 |
24 |
Correct |
13 ms |
23756 KB |
n=100 |
25 |
Correct |
13 ms |
23724 KB |
n=100 |
26 |
Runtime error |
33 ms |
47956 KB |
Execution killed with signal 11 |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23756 KB |
n=5 |
2 |
Correct |
11 ms |
23780 KB |
n=100 |
3 |
Correct |
12 ms |
23804 KB |
n=100 |
4 |
Correct |
12 ms |
23808 KB |
n=100 |
5 |
Correct |
13 ms |
23756 KB |
n=100 |
6 |
Correct |
11 ms |
23756 KB |
n=100 |
7 |
Correct |
12 ms |
23788 KB |
n=100 |
8 |
Correct |
11 ms |
23800 KB |
n=100 |
9 |
Correct |
13 ms |
23772 KB |
n=100 |
10 |
Correct |
13 ms |
23756 KB |
n=100 |
11 |
Correct |
12 ms |
23756 KB |
n=100 |
12 |
Correct |
13 ms |
23748 KB |
n=100 |
13 |
Correct |
12 ms |
23756 KB |
n=100 |
14 |
Correct |
13 ms |
23748 KB |
n=100 |
15 |
Correct |
15 ms |
23744 KB |
n=100 |
16 |
Correct |
13 ms |
23720 KB |
n=100 |
17 |
Correct |
12 ms |
23756 KB |
n=100 |
18 |
Correct |
12 ms |
23800 KB |
n=100 |
19 |
Correct |
12 ms |
23756 KB |
n=100 |
20 |
Correct |
12 ms |
23772 KB |
n=100 |
21 |
Correct |
13 ms |
23796 KB |
n=100 |
22 |
Correct |
12 ms |
23792 KB |
n=100 |
23 |
Correct |
12 ms |
23884 KB |
n=100 |
24 |
Correct |
13 ms |
23756 KB |
n=100 |
25 |
Correct |
13 ms |
23724 KB |
n=100 |
26 |
Runtime error |
33 ms |
47956 KB |
Execution killed with signal 11 |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23756 KB |
n=5 |
2 |
Correct |
11 ms |
23780 KB |
n=100 |
3 |
Correct |
12 ms |
23804 KB |
n=100 |
4 |
Correct |
12 ms |
23808 KB |
n=100 |
5 |
Correct |
13 ms |
23756 KB |
n=100 |
6 |
Correct |
11 ms |
23756 KB |
n=100 |
7 |
Correct |
12 ms |
23788 KB |
n=100 |
8 |
Correct |
11 ms |
23800 KB |
n=100 |
9 |
Correct |
13 ms |
23772 KB |
n=100 |
10 |
Correct |
13 ms |
23756 KB |
n=100 |
11 |
Correct |
12 ms |
23756 KB |
n=100 |
12 |
Correct |
13 ms |
23748 KB |
n=100 |
13 |
Correct |
12 ms |
23756 KB |
n=100 |
14 |
Correct |
13 ms |
23748 KB |
n=100 |
15 |
Correct |
15 ms |
23744 KB |
n=100 |
16 |
Correct |
13 ms |
23720 KB |
n=100 |
17 |
Correct |
12 ms |
23756 KB |
n=100 |
18 |
Correct |
12 ms |
23800 KB |
n=100 |
19 |
Correct |
12 ms |
23756 KB |
n=100 |
20 |
Correct |
12 ms |
23772 KB |
n=100 |
21 |
Correct |
13 ms |
23796 KB |
n=100 |
22 |
Correct |
12 ms |
23792 KB |
n=100 |
23 |
Correct |
12 ms |
23884 KB |
n=100 |
24 |
Correct |
13 ms |
23756 KB |
n=100 |
25 |
Correct |
13 ms |
23724 KB |
n=100 |
26 |
Runtime error |
33 ms |
47956 KB |
Execution killed with signal 11 |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23756 KB |
n=5 |
2 |
Correct |
11 ms |
23780 KB |
n=100 |
3 |
Correct |
12 ms |
23804 KB |
n=100 |
4 |
Correct |
12 ms |
23808 KB |
n=100 |
5 |
Correct |
13 ms |
23756 KB |
n=100 |
6 |
Correct |
11 ms |
23756 KB |
n=100 |
7 |
Correct |
12 ms |
23788 KB |
n=100 |
8 |
Correct |
11 ms |
23800 KB |
n=100 |
9 |
Correct |
13 ms |
23772 KB |
n=100 |
10 |
Correct |
13 ms |
23756 KB |
n=100 |
11 |
Correct |
12 ms |
23756 KB |
n=100 |
12 |
Correct |
13 ms |
23748 KB |
n=100 |
13 |
Correct |
12 ms |
23756 KB |
n=100 |
14 |
Correct |
13 ms |
23748 KB |
n=100 |
15 |
Correct |
15 ms |
23744 KB |
n=100 |
16 |
Correct |
13 ms |
23720 KB |
n=100 |
17 |
Correct |
12 ms |
23756 KB |
n=100 |
18 |
Correct |
12 ms |
23800 KB |
n=100 |
19 |
Correct |
12 ms |
23756 KB |
n=100 |
20 |
Correct |
12 ms |
23772 KB |
n=100 |
21 |
Correct |
13 ms |
23796 KB |
n=100 |
22 |
Correct |
12 ms |
23792 KB |
n=100 |
23 |
Correct |
12 ms |
23884 KB |
n=100 |
24 |
Correct |
13 ms |
23756 KB |
n=100 |
25 |
Correct |
13 ms |
23724 KB |
n=100 |
26 |
Runtime error |
33 ms |
47956 KB |
Execution killed with signal 11 |
27 |
Halted |
0 ms |
0 KB |
- |