#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define xx first
#define yy second
#define srt(a) sort(a.begin(),a.end());
#define srtg(a,int) sort(a.begin(),a.end(),greater<int>())
#define lb(a,x) lower_bound(a.begin(),a.end(),x)
#define up(a,x) upper_bound(a.begin(),a.end(),x)
#define fnd(a,x) find(a.begin(),a.end(),x)
#define vstart auto startt=chrono::system_clock::now()
#define vend auto endd=chrono::system_clock::now()
#define vvreme chrono::duration<double> vremee=endd-startt
#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef string str;
const int maxn=2e5+10;
const int logg=21;
int n,m;
int niz[maxn];
vector<int> g[maxn];
pii vreme[maxn];
int vr=0;
int lift[maxn][logg];
set<int> nesto[maxn];
set<int> svi[maxn];
void dfs(int cvor,int prosli){
vreme[cvor].xx=vr++;
lift[cvor][0]=prosli;
for(int i=1;i<logg;i++){
if(lift[cvor][i-1]==-1) lift[cvor][i]=-1;
else lift[cvor][i]=lift[lift[cvor][i-1]][i-1];
}
for(int i:g[cvor]){
if(i==prosli) continue;
dfs(i,cvor);
}
vreme[cvor].yy=vr++;
}
bool iznad(int a,int b){
if(a==-1) return true;
if(vreme[a].xx<=vreme[b].xx && vreme[b].yy<=vreme[a].yy) return true;
return false;
}
int lca(int a,int b){
for(int i=logg-1;i>=0;i--){
if(!iznad(lift[a][i],b)){
a=lift[a][i];
}
}
return (iznad(a,b) ? a:lift[a][0]);
}
void skloni(int a){
if(a<0 || a>=m-1) return;
nesto[lca(niz[a],niz[a+1])].erase(a);
}
void dodaj(int a){
if(a<0 || a>=m-1) return;
nesto[lca(niz[a],niz[a+1])].emplace(a);
}
void solve(){
int q;
cin>>n>>m>>q;
for(int i=0;i<n-1;i++){
int a,b;
cin>>a>>b;
g[a].pb(b);
g[b].pb(a);
}
dfs(1,-1);
for(int i=0;i<m;i++) cin>>niz[i];
for(int i=0;i<m;i++){
dodaj(i);
svi[niz[i]].emplace(i);
}
for(int i=0;i<q;i++){
int t;
cin>>t;
if(t==1){
int t,v;
cin>>t>>v;
t--;
svi[niz[t]].erase(t);
svi[v].emplace(t);
skloni(t-1);
skloni(t);
niz[t]=v;
dodaj(t-1);
dodaj(t);
}else{
int l,r,v;
cin>>l>>r>>v;
l--,r--;
auto it=nesto[v].lower_bound(l);
auto it2=svi[v].lower_bound(l);
if((it==nesto[v].end() || *it>=r)&&
(it2==svi[v].end() || *it2>r)){
cout<<"-1 -1\n";
}else{
if(it!=nesto[v].end() && *it<r)
cout<<*it+1<<" "<<*it+2<<"\n";
else
cout<<*it2+1<<" "<<*it2+1<<"\n";
}
}
}
}
int main(){
ios;
int t=1;
//cin>>t;
while(t--) solve();
return 0;
}
/*
5 4 4
1 2
3 1
3 4
5 3
4 5 2 3
2 1 3 1
1 3 5
2 3 4 5
2 1 3 1
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23796 KB |
n=5 |
2 |
Correct |
15 ms |
23772 KB |
n=100 |
3 |
Correct |
14 ms |
23756 KB |
n=100 |
4 |
Correct |
15 ms |
23756 KB |
n=100 |
5 |
Correct |
17 ms |
23844 KB |
n=100 |
6 |
Correct |
14 ms |
23816 KB |
n=100 |
7 |
Correct |
15 ms |
23792 KB |
n=100 |
8 |
Correct |
15 ms |
23756 KB |
n=100 |
9 |
Correct |
16 ms |
23756 KB |
n=100 |
10 |
Correct |
15 ms |
23756 KB |
n=100 |
11 |
Correct |
14 ms |
23828 KB |
n=100 |
12 |
Correct |
15 ms |
23724 KB |
n=100 |
13 |
Correct |
14 ms |
23820 KB |
n=100 |
14 |
Correct |
15 ms |
23756 KB |
n=100 |
15 |
Correct |
14 ms |
23820 KB |
n=100 |
16 |
Correct |
18 ms |
23812 KB |
n=100 |
17 |
Correct |
14 ms |
23748 KB |
n=100 |
18 |
Correct |
16 ms |
23852 KB |
n=100 |
19 |
Correct |
15 ms |
23752 KB |
n=100 |
20 |
Correct |
13 ms |
23756 KB |
n=100 |
21 |
Correct |
17 ms |
23836 KB |
n=100 |
22 |
Correct |
15 ms |
23812 KB |
n=100 |
23 |
Correct |
17 ms |
23756 KB |
n=100 |
24 |
Correct |
18 ms |
23756 KB |
n=100 |
25 |
Correct |
16 ms |
23756 KB |
n=100 |
26 |
Correct |
16 ms |
23756 KB |
n=12 |
27 |
Correct |
14 ms |
23828 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23796 KB |
n=5 |
2 |
Correct |
15 ms |
23772 KB |
n=100 |
3 |
Correct |
14 ms |
23756 KB |
n=100 |
4 |
Correct |
15 ms |
23756 KB |
n=100 |
5 |
Correct |
17 ms |
23844 KB |
n=100 |
6 |
Correct |
14 ms |
23816 KB |
n=100 |
7 |
Correct |
15 ms |
23792 KB |
n=100 |
8 |
Correct |
15 ms |
23756 KB |
n=100 |
9 |
Correct |
16 ms |
23756 KB |
n=100 |
10 |
Correct |
15 ms |
23756 KB |
n=100 |
11 |
Correct |
14 ms |
23828 KB |
n=100 |
12 |
Correct |
15 ms |
23724 KB |
n=100 |
13 |
Correct |
14 ms |
23820 KB |
n=100 |
14 |
Correct |
15 ms |
23756 KB |
n=100 |
15 |
Correct |
14 ms |
23820 KB |
n=100 |
16 |
Correct |
18 ms |
23812 KB |
n=100 |
17 |
Correct |
14 ms |
23748 KB |
n=100 |
18 |
Correct |
16 ms |
23852 KB |
n=100 |
19 |
Correct |
15 ms |
23752 KB |
n=100 |
20 |
Correct |
13 ms |
23756 KB |
n=100 |
21 |
Correct |
17 ms |
23836 KB |
n=100 |
22 |
Correct |
15 ms |
23812 KB |
n=100 |
23 |
Correct |
17 ms |
23756 KB |
n=100 |
24 |
Correct |
18 ms |
23756 KB |
n=100 |
25 |
Correct |
16 ms |
23756 KB |
n=100 |
26 |
Correct |
16 ms |
23756 KB |
n=12 |
27 |
Correct |
14 ms |
23828 KB |
n=100 |
28 |
Correct |
17 ms |
23896 KB |
n=500 |
29 |
Correct |
18 ms |
23884 KB |
n=500 |
30 |
Correct |
15 ms |
23904 KB |
n=500 |
31 |
Correct |
17 ms |
23884 KB |
n=500 |
32 |
Correct |
16 ms |
23880 KB |
n=500 |
33 |
Correct |
18 ms |
23884 KB |
n=500 |
34 |
Correct |
15 ms |
23884 KB |
n=500 |
35 |
Correct |
17 ms |
23972 KB |
n=500 |
36 |
Correct |
16 ms |
23888 KB |
n=500 |
37 |
Correct |
14 ms |
23888 KB |
n=500 |
38 |
Correct |
16 ms |
23944 KB |
n=500 |
39 |
Correct |
16 ms |
23884 KB |
n=500 |
40 |
Correct |
15 ms |
23828 KB |
n=500 |
41 |
Correct |
15 ms |
23916 KB |
n=500 |
42 |
Correct |
22 ms |
23912 KB |
n=500 |
43 |
Correct |
16 ms |
23884 KB |
n=500 |
44 |
Correct |
17 ms |
23936 KB |
n=500 |
45 |
Correct |
18 ms |
23912 KB |
n=500 |
46 |
Correct |
16 ms |
23960 KB |
n=500 |
47 |
Correct |
18 ms |
23936 KB |
n=500 |
48 |
Correct |
16 ms |
23832 KB |
n=500 |
49 |
Correct |
17 ms |
23952 KB |
n=500 |
50 |
Correct |
17 ms |
23920 KB |
n=500 |
51 |
Correct |
17 ms |
24016 KB |
n=500 |
52 |
Correct |
16 ms |
23976 KB |
n=500 |
53 |
Correct |
17 ms |
23884 KB |
n=500 |
54 |
Correct |
21 ms |
23944 KB |
n=500 |
55 |
Correct |
22 ms |
23884 KB |
n=278 |
56 |
Correct |
14 ms |
23928 KB |
n=500 |
57 |
Correct |
20 ms |
23956 KB |
n=500 |
58 |
Correct |
17 ms |
23828 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23796 KB |
n=5 |
2 |
Correct |
15 ms |
23772 KB |
n=100 |
3 |
Correct |
14 ms |
23756 KB |
n=100 |
4 |
Correct |
15 ms |
23756 KB |
n=100 |
5 |
Correct |
17 ms |
23844 KB |
n=100 |
6 |
Correct |
14 ms |
23816 KB |
n=100 |
7 |
Correct |
15 ms |
23792 KB |
n=100 |
8 |
Correct |
15 ms |
23756 KB |
n=100 |
9 |
Correct |
16 ms |
23756 KB |
n=100 |
10 |
Correct |
15 ms |
23756 KB |
n=100 |
11 |
Correct |
14 ms |
23828 KB |
n=100 |
12 |
Correct |
15 ms |
23724 KB |
n=100 |
13 |
Correct |
14 ms |
23820 KB |
n=100 |
14 |
Correct |
15 ms |
23756 KB |
n=100 |
15 |
Correct |
14 ms |
23820 KB |
n=100 |
16 |
Correct |
18 ms |
23812 KB |
n=100 |
17 |
Correct |
14 ms |
23748 KB |
n=100 |
18 |
Correct |
16 ms |
23852 KB |
n=100 |
19 |
Correct |
15 ms |
23752 KB |
n=100 |
20 |
Correct |
13 ms |
23756 KB |
n=100 |
21 |
Correct |
17 ms |
23836 KB |
n=100 |
22 |
Correct |
15 ms |
23812 KB |
n=100 |
23 |
Correct |
17 ms |
23756 KB |
n=100 |
24 |
Correct |
18 ms |
23756 KB |
n=100 |
25 |
Correct |
16 ms |
23756 KB |
n=100 |
26 |
Correct |
16 ms |
23756 KB |
n=12 |
27 |
Correct |
14 ms |
23828 KB |
n=100 |
28 |
Correct |
17 ms |
23896 KB |
n=500 |
29 |
Correct |
18 ms |
23884 KB |
n=500 |
30 |
Correct |
15 ms |
23904 KB |
n=500 |
31 |
Correct |
17 ms |
23884 KB |
n=500 |
32 |
Correct |
16 ms |
23880 KB |
n=500 |
33 |
Correct |
18 ms |
23884 KB |
n=500 |
34 |
Correct |
15 ms |
23884 KB |
n=500 |
35 |
Correct |
17 ms |
23972 KB |
n=500 |
36 |
Correct |
16 ms |
23888 KB |
n=500 |
37 |
Correct |
14 ms |
23888 KB |
n=500 |
38 |
Correct |
16 ms |
23944 KB |
n=500 |
39 |
Correct |
16 ms |
23884 KB |
n=500 |
40 |
Correct |
15 ms |
23828 KB |
n=500 |
41 |
Correct |
15 ms |
23916 KB |
n=500 |
42 |
Correct |
22 ms |
23912 KB |
n=500 |
43 |
Correct |
16 ms |
23884 KB |
n=500 |
44 |
Correct |
17 ms |
23936 KB |
n=500 |
45 |
Correct |
18 ms |
23912 KB |
n=500 |
46 |
Correct |
16 ms |
23960 KB |
n=500 |
47 |
Correct |
18 ms |
23936 KB |
n=500 |
48 |
Correct |
16 ms |
23832 KB |
n=500 |
49 |
Correct |
17 ms |
23952 KB |
n=500 |
50 |
Correct |
17 ms |
23920 KB |
n=500 |
51 |
Correct |
17 ms |
24016 KB |
n=500 |
52 |
Correct |
16 ms |
23976 KB |
n=500 |
53 |
Correct |
17 ms |
23884 KB |
n=500 |
54 |
Correct |
21 ms |
23944 KB |
n=500 |
55 |
Correct |
22 ms |
23884 KB |
n=278 |
56 |
Correct |
14 ms |
23928 KB |
n=500 |
57 |
Correct |
20 ms |
23956 KB |
n=500 |
58 |
Correct |
17 ms |
23828 KB |
n=500 |
59 |
Correct |
21 ms |
24268 KB |
n=2000 |
60 |
Correct |
21 ms |
24364 KB |
n=2000 |
61 |
Correct |
19 ms |
24396 KB |
n=2000 |
62 |
Correct |
19 ms |
24268 KB |
n=2000 |
63 |
Correct |
20 ms |
24308 KB |
n=2000 |
64 |
Correct |
20 ms |
24332 KB |
n=2000 |
65 |
Correct |
18 ms |
24268 KB |
n=2000 |
66 |
Correct |
20 ms |
24344 KB |
n=2000 |
67 |
Correct |
17 ms |
24268 KB |
n=2000 |
68 |
Correct |
19 ms |
24300 KB |
n=2000 |
69 |
Correct |
18 ms |
24268 KB |
n=2000 |
70 |
Correct |
18 ms |
24336 KB |
n=2000 |
71 |
Correct |
20 ms |
24268 KB |
n=2000 |
72 |
Correct |
16 ms |
24268 KB |
n=2000 |
73 |
Correct |
18 ms |
24276 KB |
n=2000 |
74 |
Correct |
17 ms |
24268 KB |
n=1844 |
75 |
Correct |
16 ms |
24272 KB |
n=2000 |
76 |
Correct |
27 ms |
24308 KB |
n=2000 |
77 |
Correct |
22 ms |
24288 KB |
n=2000 |
78 |
Correct |
21 ms |
24224 KB |
n=2000 |
79 |
Correct |
18 ms |
24320 KB |
n=2000 |
80 |
Correct |
26 ms |
24396 KB |
n=2000 |
81 |
Correct |
22 ms |
24316 KB |
n=2000 |
82 |
Correct |
18 ms |
24328 KB |
n=2000 |
83 |
Correct |
27 ms |
24336 KB |
n=2000 |
84 |
Correct |
25 ms |
24268 KB |
n=2000 |
85 |
Correct |
22 ms |
24268 KB |
n=2000 |
86 |
Correct |
19 ms |
24340 KB |
n=2000 |
87 |
Correct |
26 ms |
24276 KB |
n=2000 |
88 |
Correct |
18 ms |
24344 KB |
n=2000 |
89 |
Correct |
20 ms |
24340 KB |
n=2000 |
90 |
Correct |
18 ms |
24336 KB |
n=2000 |
91 |
Correct |
25 ms |
24216 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23796 KB |
n=5 |
2 |
Correct |
15 ms |
23772 KB |
n=100 |
3 |
Correct |
14 ms |
23756 KB |
n=100 |
4 |
Correct |
15 ms |
23756 KB |
n=100 |
5 |
Correct |
17 ms |
23844 KB |
n=100 |
6 |
Correct |
14 ms |
23816 KB |
n=100 |
7 |
Correct |
15 ms |
23792 KB |
n=100 |
8 |
Correct |
15 ms |
23756 KB |
n=100 |
9 |
Correct |
16 ms |
23756 KB |
n=100 |
10 |
Correct |
15 ms |
23756 KB |
n=100 |
11 |
Correct |
14 ms |
23828 KB |
n=100 |
12 |
Correct |
15 ms |
23724 KB |
n=100 |
13 |
Correct |
14 ms |
23820 KB |
n=100 |
14 |
Correct |
15 ms |
23756 KB |
n=100 |
15 |
Correct |
14 ms |
23820 KB |
n=100 |
16 |
Correct |
18 ms |
23812 KB |
n=100 |
17 |
Correct |
14 ms |
23748 KB |
n=100 |
18 |
Correct |
16 ms |
23852 KB |
n=100 |
19 |
Correct |
15 ms |
23752 KB |
n=100 |
20 |
Correct |
13 ms |
23756 KB |
n=100 |
21 |
Correct |
17 ms |
23836 KB |
n=100 |
22 |
Correct |
15 ms |
23812 KB |
n=100 |
23 |
Correct |
17 ms |
23756 KB |
n=100 |
24 |
Correct |
18 ms |
23756 KB |
n=100 |
25 |
Correct |
16 ms |
23756 KB |
n=100 |
26 |
Correct |
16 ms |
23756 KB |
n=12 |
27 |
Correct |
14 ms |
23828 KB |
n=100 |
28 |
Correct |
17 ms |
23896 KB |
n=500 |
29 |
Correct |
18 ms |
23884 KB |
n=500 |
30 |
Correct |
15 ms |
23904 KB |
n=500 |
31 |
Correct |
17 ms |
23884 KB |
n=500 |
32 |
Correct |
16 ms |
23880 KB |
n=500 |
33 |
Correct |
18 ms |
23884 KB |
n=500 |
34 |
Correct |
15 ms |
23884 KB |
n=500 |
35 |
Correct |
17 ms |
23972 KB |
n=500 |
36 |
Correct |
16 ms |
23888 KB |
n=500 |
37 |
Correct |
14 ms |
23888 KB |
n=500 |
38 |
Correct |
16 ms |
23944 KB |
n=500 |
39 |
Correct |
16 ms |
23884 KB |
n=500 |
40 |
Correct |
15 ms |
23828 KB |
n=500 |
41 |
Correct |
15 ms |
23916 KB |
n=500 |
42 |
Correct |
22 ms |
23912 KB |
n=500 |
43 |
Correct |
16 ms |
23884 KB |
n=500 |
44 |
Correct |
17 ms |
23936 KB |
n=500 |
45 |
Correct |
18 ms |
23912 KB |
n=500 |
46 |
Correct |
16 ms |
23960 KB |
n=500 |
47 |
Correct |
18 ms |
23936 KB |
n=500 |
48 |
Correct |
16 ms |
23832 KB |
n=500 |
49 |
Correct |
17 ms |
23952 KB |
n=500 |
50 |
Correct |
17 ms |
23920 KB |
n=500 |
51 |
Correct |
17 ms |
24016 KB |
n=500 |
52 |
Correct |
16 ms |
23976 KB |
n=500 |
53 |
Correct |
17 ms |
23884 KB |
n=500 |
54 |
Correct |
21 ms |
23944 KB |
n=500 |
55 |
Correct |
22 ms |
23884 KB |
n=278 |
56 |
Correct |
14 ms |
23928 KB |
n=500 |
57 |
Correct |
20 ms |
23956 KB |
n=500 |
58 |
Correct |
17 ms |
23828 KB |
n=500 |
59 |
Correct |
21 ms |
24268 KB |
n=2000 |
60 |
Correct |
21 ms |
24364 KB |
n=2000 |
61 |
Correct |
19 ms |
24396 KB |
n=2000 |
62 |
Correct |
19 ms |
24268 KB |
n=2000 |
63 |
Correct |
20 ms |
24308 KB |
n=2000 |
64 |
Correct |
20 ms |
24332 KB |
n=2000 |
65 |
Correct |
18 ms |
24268 KB |
n=2000 |
66 |
Correct |
20 ms |
24344 KB |
n=2000 |
67 |
Correct |
17 ms |
24268 KB |
n=2000 |
68 |
Correct |
19 ms |
24300 KB |
n=2000 |
69 |
Correct |
18 ms |
24268 KB |
n=2000 |
70 |
Correct |
18 ms |
24336 KB |
n=2000 |
71 |
Correct |
20 ms |
24268 KB |
n=2000 |
72 |
Correct |
16 ms |
24268 KB |
n=2000 |
73 |
Correct |
18 ms |
24276 KB |
n=2000 |
74 |
Correct |
17 ms |
24268 KB |
n=1844 |
75 |
Correct |
16 ms |
24272 KB |
n=2000 |
76 |
Correct |
27 ms |
24308 KB |
n=2000 |
77 |
Correct |
22 ms |
24288 KB |
n=2000 |
78 |
Correct |
21 ms |
24224 KB |
n=2000 |
79 |
Correct |
18 ms |
24320 KB |
n=2000 |
80 |
Correct |
26 ms |
24396 KB |
n=2000 |
81 |
Correct |
22 ms |
24316 KB |
n=2000 |
82 |
Correct |
18 ms |
24328 KB |
n=2000 |
83 |
Correct |
27 ms |
24336 KB |
n=2000 |
84 |
Correct |
25 ms |
24268 KB |
n=2000 |
85 |
Correct |
22 ms |
24268 KB |
n=2000 |
86 |
Correct |
19 ms |
24340 KB |
n=2000 |
87 |
Correct |
26 ms |
24276 KB |
n=2000 |
88 |
Correct |
18 ms |
24344 KB |
n=2000 |
89 |
Correct |
20 ms |
24340 KB |
n=2000 |
90 |
Correct |
18 ms |
24336 KB |
n=2000 |
91 |
Correct |
25 ms |
24216 KB |
n=2000 |
92 |
Correct |
968 ms |
75508 KB |
n=200000 |
93 |
Correct |
1466 ms |
80680 KB |
n=200000 |
94 |
Correct |
1456 ms |
85176 KB |
n=200000 |
95 |
Correct |
892 ms |
75372 KB |
n=200000 |
96 |
Correct |
928 ms |
75324 KB |
n=200000 |
97 |
Correct |
1720 ms |
79432 KB |
n=200000 |
98 |
Correct |
924 ms |
75320 KB |
n=200000 |
99 |
Correct |
1070 ms |
74816 KB |
n=200000 |
100 |
Correct |
918 ms |
75416 KB |
n=200000 |
101 |
Correct |
1300 ms |
86732 KB |
n=200000 |
102 |
Correct |
584 ms |
76444 KB |
n=200000 |
103 |
Correct |
526 ms |
76360 KB |
n=200000 |
104 |
Correct |
562 ms |
76356 KB |
n=200000 |
105 |
Correct |
554 ms |
76132 KB |
n=200000 |
106 |
Correct |
557 ms |
76084 KB |
n=200000 |
107 |
Correct |
581 ms |
76084 KB |
n=200000 |
108 |
Correct |
996 ms |
75008 KB |
n=200000 |
109 |
Correct |
938 ms |
75100 KB |
n=200000 |
110 |
Correct |
995 ms |
75064 KB |
n=200000 |
111 |
Correct |
1008 ms |
75256 KB |
n=200000 |
112 |
Correct |
1464 ms |
85424 KB |
n=200000 |
113 |
Correct |
1536 ms |
79408 KB |
n=200000 |
114 |
Correct |
896 ms |
75316 KB |
n=200000 |
115 |
Correct |
1635 ms |
76660 KB |
n=200000 |
116 |
Correct |
859 ms |
75144 KB |
n=200000 |
117 |
Correct |
1300 ms |
86032 KB |
n=200000 |
118 |
Correct |
1533 ms |
77960 KB |
n=200000 |
119 |
Correct |
816 ms |
75272 KB |
n=200000 |
120 |
Correct |
1221 ms |
86556 KB |
n=200000 |
121 |
Correct |
1237 ms |
86808 KB |
n=200000 |
122 |
Correct |
1287 ms |
87120 KB |
n=200000 |
123 |
Correct |
537 ms |
75708 KB |
n=200000 |
124 |
Correct |
283 ms |
39360 KB |
n=25264 |