#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<pii,pii>
#define vi vector<int>
#define pb push_back
//#define p push
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-lopps")
using namespace std;
#define int long long
const int mod=9901,mxn=3*1e5+5,inf=1e18,lg=30,minf=-1e18;
vector<int>adj[mxn+10];
int h[mxn+10],up[mxn+10][lg+5],v[mxn+10],d[mxn+10];
set<pii>t,t2;
void dfs(int cur,int p){for(auto i:adj[cur])if(i!=p)h[i]=h[cur]+1,up[i][0]=cur,dfs(i,cur);}
int lca(int a,int b){
if(h[a]<h[b])swap(a,b);
int k=h[a]-h[b];
for(int i=0;i<=lg;i++)if(k&(1<<i))a=up[a][i];
if(a==b)return a;
for(int i=lg;i>=0;i--)if(up[a][i]!=up[b][i])a=up[a][i],b=up[b][i];
return up[a][0];
}
void update(int pos,int val,int lval){
auto it=t.lb({lval,pos});
t.erase(it);
t.insert({val,pos});
}
pii qry(int val,int l,int r){
auto it=t.lb({val,l});
if(it==t.end()||((*it).f!=val))return {-1,-1};
if((*it).s>=r)return {-1,-1};
return {((*it).s+1),((*it).s+2)};
}
int32_t main(){
fastio
int n,m,q;cin>>n>>m>>q;
for(int i=0;i<n-1;i++){
int a,b;cin>>a>>b;
adj[a].pb(b);
adj[b].pb(a);
}
dfs(1,-1);
for(int i=1;i<=lg;i++)for(int j=1;j<=n;j++)up[j][i]=up[up[j][i-1]][i-1];
for(int i=0;i<m;i++)cin>>v[i],t2.insert({v[i],i});
for(int i=0;i<m-1;i++)d[i]=lca(v[i],v[i+1]),t.insert({d[i],i});
int a;
while(q--){
int ty;cin>>ty;
if(ty==1){
int pos,val;cin>>pos>>val;
pos--;
auto it=t2.lb({v[pos],pos});
t2.erase(it);
t2.insert({val,pos});
v[pos]=val;
if(pos<m-1){
a=lca(v[pos],v[pos+1]);
update(pos,a,d[pos]);
d[pos]=a;
}
if(pos>0){
a=lca(v[pos-1],v[pos]);
update(pos-1,a,d[pos-1]);
d[pos-1]=a;
}
}
else{
int l,r,ver;cin>>l>>r>>ver;
l--,r--;
auto it=t2.lb({ver,l});
if((*it).f==ver&&(*it).s<=r){
cout<<(*it).s+1<<' '<<(*it).s+1<<'\n';
continue;
}
pii tmp=qry(ver,l,r);
cout<<tmp.f<<" "<<tmp.s<<'\n';
}
}
}
Compilation message
treearray.cpp:30:40: warning: bad option '-funroll-lopps' to pragma 'optimize' [-Wpragmas]
30 | #pragma GCC optimize ("03,unroll-lopps")
| ^
treearray.cpp:37:23: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
37 | void dfs(int cur,int p){for(auto i:adj[cur])if(i!=p)h[i]=h[cur]+1,up[i][0]=cur,dfs(i,cur);}
| ^
treearray.cpp:38:20: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
38 | int lca(int a,int b){
| ^
treearray.cpp:46:37: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
46 | void update(int pos,int val,int lval){
| ^
treearray.cpp:51:28: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
51 | pii qry(int val,int l,int r){
| ^
treearray.cpp:57:14: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
57 | int32_t main(){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12380 KB |
n=5 |
2 |
Correct |
3 ms |
12432 KB |
n=100 |
3 |
Correct |
3 ms |
12380 KB |
n=100 |
4 |
Correct |
3 ms |
12380 KB |
n=100 |
5 |
Correct |
3 ms |
12380 KB |
n=100 |
6 |
Correct |
3 ms |
12380 KB |
n=100 |
7 |
Correct |
3 ms |
12380 KB |
n=100 |
8 |
Correct |
3 ms |
12376 KB |
n=100 |
9 |
Correct |
3 ms |
12380 KB |
n=100 |
10 |
Correct |
4 ms |
12380 KB |
n=100 |
11 |
Correct |
3 ms |
12376 KB |
n=100 |
12 |
Correct |
3 ms |
12380 KB |
n=100 |
13 |
Correct |
3 ms |
12376 KB |
n=100 |
14 |
Correct |
3 ms |
12380 KB |
n=100 |
15 |
Correct |
3 ms |
12380 KB |
n=100 |
16 |
Correct |
3 ms |
12380 KB |
n=100 |
17 |
Correct |
3 ms |
12380 KB |
n=100 |
18 |
Correct |
4 ms |
12524 KB |
n=100 |
19 |
Correct |
3 ms |
12376 KB |
n=100 |
20 |
Correct |
3 ms |
12380 KB |
n=100 |
21 |
Correct |
3 ms |
12380 KB |
n=100 |
22 |
Correct |
2 ms |
12380 KB |
n=100 |
23 |
Correct |
3 ms |
12380 KB |
n=100 |
24 |
Correct |
3 ms |
12436 KB |
n=100 |
25 |
Correct |
3 ms |
12380 KB |
n=100 |
26 |
Correct |
3 ms |
12380 KB |
n=12 |
27 |
Correct |
3 ms |
12380 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12380 KB |
n=5 |
2 |
Correct |
3 ms |
12432 KB |
n=100 |
3 |
Correct |
3 ms |
12380 KB |
n=100 |
4 |
Correct |
3 ms |
12380 KB |
n=100 |
5 |
Correct |
3 ms |
12380 KB |
n=100 |
6 |
Correct |
3 ms |
12380 KB |
n=100 |
7 |
Correct |
3 ms |
12380 KB |
n=100 |
8 |
Correct |
3 ms |
12376 KB |
n=100 |
9 |
Correct |
3 ms |
12380 KB |
n=100 |
10 |
Correct |
4 ms |
12380 KB |
n=100 |
11 |
Correct |
3 ms |
12376 KB |
n=100 |
12 |
Correct |
3 ms |
12380 KB |
n=100 |
13 |
Correct |
3 ms |
12376 KB |
n=100 |
14 |
Correct |
3 ms |
12380 KB |
n=100 |
15 |
Correct |
3 ms |
12380 KB |
n=100 |
16 |
Correct |
3 ms |
12380 KB |
n=100 |
17 |
Correct |
3 ms |
12380 KB |
n=100 |
18 |
Correct |
4 ms |
12524 KB |
n=100 |
19 |
Correct |
3 ms |
12376 KB |
n=100 |
20 |
Correct |
3 ms |
12380 KB |
n=100 |
21 |
Correct |
3 ms |
12380 KB |
n=100 |
22 |
Correct |
2 ms |
12380 KB |
n=100 |
23 |
Correct |
3 ms |
12380 KB |
n=100 |
24 |
Correct |
3 ms |
12436 KB |
n=100 |
25 |
Correct |
3 ms |
12380 KB |
n=100 |
26 |
Correct |
3 ms |
12380 KB |
n=12 |
27 |
Correct |
3 ms |
12380 KB |
n=100 |
28 |
Correct |
3 ms |
12380 KB |
n=500 |
29 |
Correct |
3 ms |
12380 KB |
n=500 |
30 |
Correct |
3 ms |
12380 KB |
n=500 |
31 |
Correct |
3 ms |
12380 KB |
n=500 |
32 |
Correct |
3 ms |
12376 KB |
n=500 |
33 |
Correct |
3 ms |
12380 KB |
n=500 |
34 |
Correct |
3 ms |
12444 KB |
n=500 |
35 |
Correct |
3 ms |
12380 KB |
n=500 |
36 |
Correct |
3 ms |
12472 KB |
n=500 |
37 |
Correct |
3 ms |
12380 KB |
n=500 |
38 |
Correct |
3 ms |
12380 KB |
n=500 |
39 |
Correct |
3 ms |
12376 KB |
n=500 |
40 |
Correct |
3 ms |
12376 KB |
n=500 |
41 |
Correct |
3 ms |
12380 KB |
n=500 |
42 |
Correct |
4 ms |
12380 KB |
n=500 |
43 |
Correct |
3 ms |
12380 KB |
n=500 |
44 |
Correct |
3 ms |
12440 KB |
n=500 |
45 |
Correct |
4 ms |
12380 KB |
n=500 |
46 |
Correct |
3 ms |
12380 KB |
n=500 |
47 |
Correct |
3 ms |
12380 KB |
n=500 |
48 |
Correct |
3 ms |
12380 KB |
n=500 |
49 |
Correct |
3 ms |
12380 KB |
n=500 |
50 |
Correct |
4 ms |
12380 KB |
n=500 |
51 |
Incorrect |
4 ms |
12380 KB |
Wrong output format. |
52 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12380 KB |
n=5 |
2 |
Correct |
3 ms |
12432 KB |
n=100 |
3 |
Correct |
3 ms |
12380 KB |
n=100 |
4 |
Correct |
3 ms |
12380 KB |
n=100 |
5 |
Correct |
3 ms |
12380 KB |
n=100 |
6 |
Correct |
3 ms |
12380 KB |
n=100 |
7 |
Correct |
3 ms |
12380 KB |
n=100 |
8 |
Correct |
3 ms |
12376 KB |
n=100 |
9 |
Correct |
3 ms |
12380 KB |
n=100 |
10 |
Correct |
4 ms |
12380 KB |
n=100 |
11 |
Correct |
3 ms |
12376 KB |
n=100 |
12 |
Correct |
3 ms |
12380 KB |
n=100 |
13 |
Correct |
3 ms |
12376 KB |
n=100 |
14 |
Correct |
3 ms |
12380 KB |
n=100 |
15 |
Correct |
3 ms |
12380 KB |
n=100 |
16 |
Correct |
3 ms |
12380 KB |
n=100 |
17 |
Correct |
3 ms |
12380 KB |
n=100 |
18 |
Correct |
4 ms |
12524 KB |
n=100 |
19 |
Correct |
3 ms |
12376 KB |
n=100 |
20 |
Correct |
3 ms |
12380 KB |
n=100 |
21 |
Correct |
3 ms |
12380 KB |
n=100 |
22 |
Correct |
2 ms |
12380 KB |
n=100 |
23 |
Correct |
3 ms |
12380 KB |
n=100 |
24 |
Correct |
3 ms |
12436 KB |
n=100 |
25 |
Correct |
3 ms |
12380 KB |
n=100 |
26 |
Correct |
3 ms |
12380 KB |
n=12 |
27 |
Correct |
3 ms |
12380 KB |
n=100 |
28 |
Correct |
3 ms |
12380 KB |
n=500 |
29 |
Correct |
3 ms |
12380 KB |
n=500 |
30 |
Correct |
3 ms |
12380 KB |
n=500 |
31 |
Correct |
3 ms |
12380 KB |
n=500 |
32 |
Correct |
3 ms |
12376 KB |
n=500 |
33 |
Correct |
3 ms |
12380 KB |
n=500 |
34 |
Correct |
3 ms |
12444 KB |
n=500 |
35 |
Correct |
3 ms |
12380 KB |
n=500 |
36 |
Correct |
3 ms |
12472 KB |
n=500 |
37 |
Correct |
3 ms |
12380 KB |
n=500 |
38 |
Correct |
3 ms |
12380 KB |
n=500 |
39 |
Correct |
3 ms |
12376 KB |
n=500 |
40 |
Correct |
3 ms |
12376 KB |
n=500 |
41 |
Correct |
3 ms |
12380 KB |
n=500 |
42 |
Correct |
4 ms |
12380 KB |
n=500 |
43 |
Correct |
3 ms |
12380 KB |
n=500 |
44 |
Correct |
3 ms |
12440 KB |
n=500 |
45 |
Correct |
4 ms |
12380 KB |
n=500 |
46 |
Correct |
3 ms |
12380 KB |
n=500 |
47 |
Correct |
3 ms |
12380 KB |
n=500 |
48 |
Correct |
3 ms |
12380 KB |
n=500 |
49 |
Correct |
3 ms |
12380 KB |
n=500 |
50 |
Correct |
4 ms |
12380 KB |
n=500 |
51 |
Incorrect |
4 ms |
12380 KB |
Wrong output format. |
52 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12380 KB |
n=5 |
2 |
Correct |
3 ms |
12432 KB |
n=100 |
3 |
Correct |
3 ms |
12380 KB |
n=100 |
4 |
Correct |
3 ms |
12380 KB |
n=100 |
5 |
Correct |
3 ms |
12380 KB |
n=100 |
6 |
Correct |
3 ms |
12380 KB |
n=100 |
7 |
Correct |
3 ms |
12380 KB |
n=100 |
8 |
Correct |
3 ms |
12376 KB |
n=100 |
9 |
Correct |
3 ms |
12380 KB |
n=100 |
10 |
Correct |
4 ms |
12380 KB |
n=100 |
11 |
Correct |
3 ms |
12376 KB |
n=100 |
12 |
Correct |
3 ms |
12380 KB |
n=100 |
13 |
Correct |
3 ms |
12376 KB |
n=100 |
14 |
Correct |
3 ms |
12380 KB |
n=100 |
15 |
Correct |
3 ms |
12380 KB |
n=100 |
16 |
Correct |
3 ms |
12380 KB |
n=100 |
17 |
Correct |
3 ms |
12380 KB |
n=100 |
18 |
Correct |
4 ms |
12524 KB |
n=100 |
19 |
Correct |
3 ms |
12376 KB |
n=100 |
20 |
Correct |
3 ms |
12380 KB |
n=100 |
21 |
Correct |
3 ms |
12380 KB |
n=100 |
22 |
Correct |
2 ms |
12380 KB |
n=100 |
23 |
Correct |
3 ms |
12380 KB |
n=100 |
24 |
Correct |
3 ms |
12436 KB |
n=100 |
25 |
Correct |
3 ms |
12380 KB |
n=100 |
26 |
Correct |
3 ms |
12380 KB |
n=12 |
27 |
Correct |
3 ms |
12380 KB |
n=100 |
28 |
Correct |
3 ms |
12380 KB |
n=500 |
29 |
Correct |
3 ms |
12380 KB |
n=500 |
30 |
Correct |
3 ms |
12380 KB |
n=500 |
31 |
Correct |
3 ms |
12380 KB |
n=500 |
32 |
Correct |
3 ms |
12376 KB |
n=500 |
33 |
Correct |
3 ms |
12380 KB |
n=500 |
34 |
Correct |
3 ms |
12444 KB |
n=500 |
35 |
Correct |
3 ms |
12380 KB |
n=500 |
36 |
Correct |
3 ms |
12472 KB |
n=500 |
37 |
Correct |
3 ms |
12380 KB |
n=500 |
38 |
Correct |
3 ms |
12380 KB |
n=500 |
39 |
Correct |
3 ms |
12376 KB |
n=500 |
40 |
Correct |
3 ms |
12376 KB |
n=500 |
41 |
Correct |
3 ms |
12380 KB |
n=500 |
42 |
Correct |
4 ms |
12380 KB |
n=500 |
43 |
Correct |
3 ms |
12380 KB |
n=500 |
44 |
Correct |
3 ms |
12440 KB |
n=500 |
45 |
Correct |
4 ms |
12380 KB |
n=500 |
46 |
Correct |
3 ms |
12380 KB |
n=500 |
47 |
Correct |
3 ms |
12380 KB |
n=500 |
48 |
Correct |
3 ms |
12380 KB |
n=500 |
49 |
Correct |
3 ms |
12380 KB |
n=500 |
50 |
Correct |
4 ms |
12380 KB |
n=500 |
51 |
Incorrect |
4 ms |
12380 KB |
Wrong output format. |
52 |
Halted |
0 ms |
0 KB |
- |