#include "bits/stdc++.h"
using namespace std;
#define int long long
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define endl "\n"
#define pb push_back
/*
dont get stuck on one approach
write stuff on paper
edge cases(n=1?)
look for : dp,bs,bf,observations...
implement and debug smarter
*/
const int N = 2e5;
const int LOG = 20;
vector<int> v[N];
int lift[N][LOG];
int depth[N];
void dfs(int c,int p,int d){
depth[c]=d;
lift[c][0]=p;
for(int i=1;i<LOG;i++) lift[c][i]=lift[lift[c][i-1]][i-1];
for(int x:v[c]){
if(x==p) continue;
dfs(x,c,d+1);
}
}
int lca(int a,int b){
if(depth[a]<depth[b]) swap(a,b);
int x = depth[a] - depth[b];
for(int i=0;i<LOG;i++) if(x>>i&1) a=lift[a][i];
for(int i=LOG-1;i>=0;i--){
if(lift[a][i]!=lift[b][i]){
a=lift[a][i];
b=lift[b][i];
}
}
return lift[a][0];
}
void solve(){
int n,m,q;
cin >> n >> m >> q;
for(int i=1;i<n;i++){
int a,b;
cin >> a >> b;
v[a].pb(b);
v[b].pb(a);
}
dfs(1,0,0);
int ar[m+5];
set<int> s[n+5];
set<int> freq[n+5];
for(int i=1;i<=m;i++){
cin >> ar[i];
if(i>=2) s[lca(ar[i],ar[i-1])].insert(i);
freq[ar[i]].insert(i);
}
while(q--){
int op;
cin >> op;
if(op==1){
int ind,u;
cin >> ind >> u;
if(ind>=2) s[lca(ar[ind],ar[ind-1])].erase(ind);
if(ind+1<=n) s[lca(ar[ind],ar[ind+1])].erase(ind+1);
freq[ar[ind]].erase(ind);
ar[ind]=u;
freq[ar[ind]].insert(ind);
if(ind>=2) s[lca(ar[ind],ar[ind-1])].insert(ind);
if(ind+1<=n) s[lca(ar[ind],ar[ind+1])].insert(ind+1);
}
else{
int l,r,u;
cin >> l >> r >> u;
auto it = freq[u].lower_bound(l);
if(it!=freq[u].end() && (*it)<=r){
cout << (*it) << " " << (*it) << endl;
continue;
}
it = s[u].upper_bound(l);
if(it!=s[u].end() && (*it)<=r){
cout << (*it)-1 << " " << (*it) << endl;
continue;
}
cout << -1 << " " << -1 << endl;
}
}
}
int32_t main(){
cin.tie(0);
ios::sync_with_stdio(0);
int t=1;//cin >> t;
while(t--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
9052 KB |
n=5 |
2 |
Incorrect |
2 ms |
9128 KB |
Wrong range. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
9052 KB |
n=5 |
2 |
Incorrect |
2 ms |
9128 KB |
Wrong range. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
9052 KB |
n=5 |
2 |
Incorrect |
2 ms |
9128 KB |
Wrong range. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
9052 KB |
n=5 |
2 |
Incorrect |
2 ms |
9128 KB |
Wrong range. |
3 |
Halted |
0 ms |
0 KB |
- |