#include <bits/stdc++.h>
using namespace std;
const int N=200005;
const int LG=log2(N)+3;
vector<int> g[N];
int anc[N][LG];
int n,m,q,l;
int in[N],out[N],timer;
void dfs(int v,int par=0){
in[v]=timer++;
anc[v][0]=par;
for (int i=1;i<=l;i++){
anc[v][i]=anc[anc[v][i-1]][i-1];
}
for (auto to:g[v]){
if (to==par)continue;
dfs(to,v);
}
out[v]=timer++;
}
bool is_anc(int a,int b){
if (b==0 || a==b)return true;
if (in[a]>in[b] && in[a]<out[b])return true;
return false;
}
int lca(int a,int b){
if (is_anc(a,b)) return b;
if (is_anc(b,a)) return a;
for (int i=l;i>=0;i--)
if (!is_anc(b,anc[a][i]))
a=anc[a][i];
return anc[a][0];
}
int a[N];
set<int> sl[N],pr[N];
set<int>::iterator it;
int main(){
ios_base::sync_with_stdio(false);
//freopen("input.txt","r",stdin);
cin>>n>>m>>q;
l=0;
while ((1<<l)<=n)l++;
for (int i=0;i<n-1;i++){
int a,b;
cin>>a>>b;
g[a].push_back(b);
g[b].push_back(a);
}
dfs(1);
for (int i=1;i<=m;i++){
cin>>a[i];
sl[a[i]].insert(i);
if (i!=1){
//cout<<lca(a[i],a[i-1])<<" "<<i-1<<endl;
pr[lca(a[i],a[i-1])].insert(i-1);
}
}
for (int i=0;i<q;i++){
int type;
cin>>type;
if (type==1){
int ind,val;
cin>>ind>>val;
sl[a[ind]].erase(sl[a[ind]].find(ind));
sl[val].insert(ind);
if (ind!=1){
int oldval=lca(a[ind],a[ind-1]),newval=lca(val,a[ind-1]);
pr[oldval].erase(pr[oldval].find(ind-1));
pr[newval].insert(ind-1);
}
if (ind!=m){
int oldval=lca(a[ind],a[ind+1]),newval=lca(val,a[ind+1]);
pr[oldval].erase(pr[oldval].find(ind+1));
pr[newval].insert(ind+1);
}
a[ind]=val;
}
else{
int l,r,v;
cin>>l>>r>>v;
if (sl[v].size()){
it=sl[v].lower_bound(l);
if (it!=sl[v].end() && *it<=r){
cout<<*it<<" "<<*it<<endl;
continue;
}
}
if (pr[v].size()){
it=pr[v].lower_bound(l);
if (it!=pr[v].end() && *it<r){
//cout<<*it<<endl;
cout<<*it<<" "<<*it+1<<endl;
continue;
}
}
cout<<-1<<" "<<-1<<endl;
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
82 ms |
47736 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
82 ms |
47736 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
82 ms |
47736 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
82 ms |
47736 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |