This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define int long long
#define endl '\n'
void fopn(string name){
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
const int INF=1e18,mod=1e9+7;
int n,m,q;
int p[200005][21],depth[200005];
vector<int> g[200005];
void dfs(int x, int par){
p[x][0]=par;
depth[x]=depth[par]+1;
for(auto it: g[x]){
if(it==par) continue;
dfs(it,x);
}
}
int lca(int a, int b){
if(depth[a]<depth[b]) swap(a,b);
int k=depth[a]-depth[b];
for(int i=20;i>=0;i--){
if(k&(1<<i))
a=p[a][i];
}
if(a==b) return a;
for(int i=20;i>=0;i--){
if(p[a][i]!=p[b][i]){
a=p[a][i];
b=p[b][i];
}
}
return p[a][0];
}
int ar[200005];
set<int> a[200005],b[200005];
void solve(){
cin>>n>>m>>q;
for(int i=1;i<n;i++){
int a,b;
cin>>a>>b;
g[a].pb(b);
g[b].pb(a);
}
dfs(1,1);
for(int l=1;l<21;l++){
for(int i=1;i<=n;i++){
p[i][l]=p[p[i][l-1]][l-1];
}
}
for(int i=1;i<=m;i++){
cin>>ar[i];
a[ar[i]].insert(i);
if(i>1)
b[lca(ar[i],ar[i-1])].insert(i-1);
}
while(q--){
int t;
cin>>t;
if(t==1){
int p,v;cin>>p>>v;
a[ar[p]].erase(p);
a[v].insert(p);
if(p>1){
b[lca(ar[p],ar[p-1])].erase(p-1);
b[lca(v,ar[p-1])].insert(p-1);
}
if(p<m){
b[lca(ar[p],ar[p+1])].erase(p);
b[lca(v,ar[p+1])].insert(p);
}
ar[p]=v;
}
else{
int l,r,v;
cin>>l>>r>>v;
auto it = a[v].lower_bound(l);
if(it!=a[v].end() && *it<=r){
cout<<*it<<' '<<*it<<endl;
}
else{
it=b[v].lower_bound(l);
if(it!=b[v].end() && *it<r){
cout<<*it<<' '<<*it+1<<endl;
}
else{
cout<<"-1 -1\n";
}
}
}
}
}
main(){
ios;
int T=1;
//cin>>T;
while(T--){
solve();
}
}
Compilation message (stderr)
treearray.cpp:101:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
101 | main(){
| ^~~~
treearray.cpp: In function 'void fopn(std::string)':
treearray.cpp:12:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | freopen((name+".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
treearray.cpp:13:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | freopen((name+".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |