#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long
#define pb push_back
#define pii pair<int,int>
#define sz size()
#define all(v) v.begin(),v.end()
#define fi first
#define se second
const int N = 2e5;
const int mod = 998244353;
const int INF = 1e9;
const int di[]={1,-1,0,0};
const int dj[]={0,0,1,-1};
int n,m,q;
int a[N+1];
vector<int> g[N+1];
int tin[N+1],tout[N+1];
int up[N+1][20],timer=1;
set<int> st[N+1],sgl[N+1];
void dfs(int v,int pr){
tin[v]=timer++;
up[v][0]=pr;
for(int i = 1; i < 20; i++){
up[v][i]=up[up[v][i-1]][i-1];
}
for(auto i: g[v]){
if(i!=pr)
dfs(i,v);
}
tout[v]=timer++;
}
bool check(int a,int b){
return tin[a]<=tin[b] && tout[b]<=tout[a];
}
int lca(int a,int b){
if(check(a,b))
return a;
if(check(b,a))
return b;
for(int i = 19; i >= 0; i--){
if(!check(up[a][i],b))
a=up[a][i];
}
return up[a][0];
}
void solve() {
cin>>n>>m>>q;
for(int i = 1; i <= n-1; i++){
int x,y;
cin>>x>>y;
g[x].pb(y);
g[y].pb(x);
}
for(int i = 1; i <= m; i++){
cin>>a[i];
}
dfs(1,1);
for(int i = 1; i <= m-1; i++){
int x=lca(a[i],a[i+1]);
st[x].insert(i);
}
for(int i = 1; i <= m; i++){
sgl[a[i]].insert(i);
}
while(q--){
int type;
cin>>type;
if(type==1){
int pos,v;
cin>>pos>>v;
sgl[a[pos]].erase(pos);
if(pos<m)
st[lca(a[pos],a[pos+1])].erase(pos);
if(pos>1)
st[lca(a[pos],a[pos-1])].erase(pos-1);
a[pos]=v;
sgl[a[pos]].insert(pos);
if(pos<m)
st[lca(a[pos],a[pos+1])].insert(pos);
if(pos>1)
st[lca(a[pos],a[pos-1])].insert(pos-1);
}
else{
int l,r,v;
cin>>l>>r>>v;
if(l==r){
if(a[l]==v)
cout<<l<<" "<<r<<"\n";
else
cout<<"-1 -1\n";
continue;
}
auto p=st[v].lower_bound(l);
auto s=sgl[v].lower_bound(l);
if(p!=st[v].end() && (*p)<=r-1)
cout<<(*p)<<" "<<(*p)+1<<"\n";
else if(s!=sgl[v].end() && (*s)<=r)
cout<<(*s)<<" "<<(*s)<<"\n";
else
cout<<"-1 -1\n";
}
}
}
int main() {
//freopen("cowrun.in","r",stdin);
//freopen("cowrun.out","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t=1;
//cin>>t;
while(t--) {
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |