#include "bits/stdc++.h"
using namespace std;
#define int long long
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define endl "\n"
#define pb push_back
/*
dont get stuck on one approach
write stuff on paper
edge cases(n=1?)
look for : dp,bs,bf,observations...
implement and debug smarter
*/
const int N = 2e5 + 25;
const int LOG = 25;
vector<int> v[N];
int lift[N][LOG];
int depth[N];
void dfs(int c,int p,int d){
depth[c]=d;
lift[c][0]=p;
for(int i=1;i<LOG;i++) lift[c][i]=lift[lift[c][i-1]][i-1];
for(int x:v[c]){
if(x==p) continue;
dfs(x,c,d+1);
}
}
int lca(int a,int b){
if(depth[a]<depth[b]) swap(a,b);
int x = depth[a] - depth[b];
assert(x>=0);
for(int i=0;i<LOG;i++) if(x&(1LL<<i)) a=lift[a][i];
if(a==b) return a;
for(int i=LOG-1;i>=0;i--){
if(lift[a][i]!=lift[b][i]){
a=lift[a][i];
b=lift[b][i];
}
}
return lift[a][0];
}
void solve(){
int n,m,q;
cin >> n >> m >> q;
for(int i=1;i<n;i++){
int a,b;
cin >> a >> b;
v[a].pb(b);
v[b].pb(a);
}
dfs(1,1,0);
int ar[m+5];
set<int> s[n+5];
set<int> freq[n+5];
for(int i=1;i<=m;i++){
cin >> ar[i];
if(i>1) s[lca(ar[i],ar[i-1])].insert(i);
freq[ar[i]].insert(i);
}
while(q--){
int op;
cin >> op;
if(op==1){
int ind,u;
cin >> ind >> u;
if(ind>1) s[lca(ar[ind],ar[ind-1])].erase(ind);
if(ind<n) s[lca(ar[ind],ar[ind+1])].erase(ind+1);
freq[ar[ind]].erase(ind);
ar[ind]=u;
freq[ar[ind]].insert(ind);
if(ind>1) s[lca(ar[ind],ar[ind-1])].insert(ind);
if(ind<n) s[lca(ar[ind],ar[ind+1])].insert(ind+1);
}
else{
int l,r,u;
cin >> l >> r >> u;
auto it = freq[u].lower_bound(l);
if(it!=freq[u].end() && (*it)<=r && (*it)>=l){
cout << (*it) << " " << (*it) << endl;
continue;
}
auto it2 = s[u].upper_bound(l);
if(it2!=s[u].end() && (*it2)<=r && (*it2) > l){
cout << (*it2)-1 << " " << (*it2) << endl;
continue;
}
cout << -1 << " " << -1 << endl;
}
}
}
int32_t main(){
cin.tie(0);
ios::sync_with_stdio(0);
int t=1;//cin >> t;
while(t--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8540 KB |
n=5 |
2 |
Correct |
2 ms |
8760 KB |
n=100 |
3 |
Correct |
2 ms |
8540 KB |
n=100 |
4 |
Correct |
2 ms |
8540 KB |
n=100 |
5 |
Correct |
2 ms |
8540 KB |
n=100 |
6 |
Correct |
2 ms |
8540 KB |
n=100 |
7 |
Correct |
2 ms |
8540 KB |
n=100 |
8 |
Correct |
2 ms |
8540 KB |
n=100 |
9 |
Correct |
1 ms |
8540 KB |
n=100 |
10 |
Correct |
2 ms |
8540 KB |
n=100 |
11 |
Correct |
2 ms |
8536 KB |
n=100 |
12 |
Correct |
2 ms |
8792 KB |
n=100 |
13 |
Correct |
2 ms |
8540 KB |
n=100 |
14 |
Correct |
1 ms |
8540 KB |
n=100 |
15 |
Correct |
2 ms |
8752 KB |
n=100 |
16 |
Correct |
2 ms |
8536 KB |
n=100 |
17 |
Correct |
2 ms |
8540 KB |
n=100 |
18 |
Correct |
2 ms |
8536 KB |
n=100 |
19 |
Correct |
2 ms |
8536 KB |
n=100 |
20 |
Correct |
2 ms |
8540 KB |
n=100 |
21 |
Correct |
2 ms |
8540 KB |
n=100 |
22 |
Correct |
2 ms |
8540 KB |
n=100 |
23 |
Correct |
2 ms |
8540 KB |
n=100 |
24 |
Correct |
2 ms |
8540 KB |
n=100 |
25 |
Correct |
1 ms |
8540 KB |
n=100 |
26 |
Correct |
2 ms |
8540 KB |
n=12 |
27 |
Correct |
2 ms |
8540 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8540 KB |
n=5 |
2 |
Correct |
2 ms |
8760 KB |
n=100 |
3 |
Correct |
2 ms |
8540 KB |
n=100 |
4 |
Correct |
2 ms |
8540 KB |
n=100 |
5 |
Correct |
2 ms |
8540 KB |
n=100 |
6 |
Correct |
2 ms |
8540 KB |
n=100 |
7 |
Correct |
2 ms |
8540 KB |
n=100 |
8 |
Correct |
2 ms |
8540 KB |
n=100 |
9 |
Correct |
1 ms |
8540 KB |
n=100 |
10 |
Correct |
2 ms |
8540 KB |
n=100 |
11 |
Correct |
2 ms |
8536 KB |
n=100 |
12 |
Correct |
2 ms |
8792 KB |
n=100 |
13 |
Correct |
2 ms |
8540 KB |
n=100 |
14 |
Correct |
1 ms |
8540 KB |
n=100 |
15 |
Correct |
2 ms |
8752 KB |
n=100 |
16 |
Correct |
2 ms |
8536 KB |
n=100 |
17 |
Correct |
2 ms |
8540 KB |
n=100 |
18 |
Correct |
2 ms |
8536 KB |
n=100 |
19 |
Correct |
2 ms |
8536 KB |
n=100 |
20 |
Correct |
2 ms |
8540 KB |
n=100 |
21 |
Correct |
2 ms |
8540 KB |
n=100 |
22 |
Correct |
2 ms |
8540 KB |
n=100 |
23 |
Correct |
2 ms |
8540 KB |
n=100 |
24 |
Correct |
2 ms |
8540 KB |
n=100 |
25 |
Correct |
1 ms |
8540 KB |
n=100 |
26 |
Correct |
2 ms |
8540 KB |
n=12 |
27 |
Correct |
2 ms |
8540 KB |
n=100 |
28 |
Correct |
2 ms |
8792 KB |
n=500 |
29 |
Correct |
2 ms |
8796 KB |
n=500 |
30 |
Correct |
2 ms |
8884 KB |
n=500 |
31 |
Correct |
2 ms |
8952 KB |
n=500 |
32 |
Correct |
2 ms |
8796 KB |
n=500 |
33 |
Correct |
2 ms |
8792 KB |
n=500 |
34 |
Correct |
2 ms |
8792 KB |
n=500 |
35 |
Correct |
2 ms |
8796 KB |
n=500 |
36 |
Correct |
2 ms |
8796 KB |
n=500 |
37 |
Correct |
2 ms |
8796 KB |
n=500 |
38 |
Correct |
2 ms |
8796 KB |
n=500 |
39 |
Correct |
2 ms |
8792 KB |
n=500 |
40 |
Correct |
2 ms |
8796 KB |
n=500 |
41 |
Correct |
2 ms |
8796 KB |
n=500 |
42 |
Correct |
2 ms |
8796 KB |
n=500 |
43 |
Correct |
2 ms |
8792 KB |
n=500 |
44 |
Correct |
2 ms |
8796 KB |
n=500 |
45 |
Correct |
2 ms |
8796 KB |
n=500 |
46 |
Correct |
2 ms |
8768 KB |
n=500 |
47 |
Correct |
2 ms |
8796 KB |
n=500 |
48 |
Correct |
2 ms |
8792 KB |
n=500 |
49 |
Correct |
2 ms |
8792 KB |
n=500 |
50 |
Correct |
2 ms |
8792 KB |
n=500 |
51 |
Correct |
2 ms |
8792 KB |
n=500 |
52 |
Correct |
2 ms |
8796 KB |
n=500 |
53 |
Correct |
2 ms |
8888 KB |
n=500 |
54 |
Correct |
2 ms |
8796 KB |
n=500 |
55 |
Correct |
2 ms |
8796 KB |
n=278 |
56 |
Correct |
2 ms |
8796 KB |
n=500 |
57 |
Correct |
2 ms |
8796 KB |
n=500 |
58 |
Correct |
2 ms |
9048 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8540 KB |
n=5 |
2 |
Correct |
2 ms |
8760 KB |
n=100 |
3 |
Correct |
2 ms |
8540 KB |
n=100 |
4 |
Correct |
2 ms |
8540 KB |
n=100 |
5 |
Correct |
2 ms |
8540 KB |
n=100 |
6 |
Correct |
2 ms |
8540 KB |
n=100 |
7 |
Correct |
2 ms |
8540 KB |
n=100 |
8 |
Correct |
2 ms |
8540 KB |
n=100 |
9 |
Correct |
1 ms |
8540 KB |
n=100 |
10 |
Correct |
2 ms |
8540 KB |
n=100 |
11 |
Correct |
2 ms |
8536 KB |
n=100 |
12 |
Correct |
2 ms |
8792 KB |
n=100 |
13 |
Correct |
2 ms |
8540 KB |
n=100 |
14 |
Correct |
1 ms |
8540 KB |
n=100 |
15 |
Correct |
2 ms |
8752 KB |
n=100 |
16 |
Correct |
2 ms |
8536 KB |
n=100 |
17 |
Correct |
2 ms |
8540 KB |
n=100 |
18 |
Correct |
2 ms |
8536 KB |
n=100 |
19 |
Correct |
2 ms |
8536 KB |
n=100 |
20 |
Correct |
2 ms |
8540 KB |
n=100 |
21 |
Correct |
2 ms |
8540 KB |
n=100 |
22 |
Correct |
2 ms |
8540 KB |
n=100 |
23 |
Correct |
2 ms |
8540 KB |
n=100 |
24 |
Correct |
2 ms |
8540 KB |
n=100 |
25 |
Correct |
1 ms |
8540 KB |
n=100 |
26 |
Correct |
2 ms |
8540 KB |
n=12 |
27 |
Correct |
2 ms |
8540 KB |
n=100 |
28 |
Correct |
2 ms |
8792 KB |
n=500 |
29 |
Correct |
2 ms |
8796 KB |
n=500 |
30 |
Correct |
2 ms |
8884 KB |
n=500 |
31 |
Correct |
2 ms |
8952 KB |
n=500 |
32 |
Correct |
2 ms |
8796 KB |
n=500 |
33 |
Correct |
2 ms |
8792 KB |
n=500 |
34 |
Correct |
2 ms |
8792 KB |
n=500 |
35 |
Correct |
2 ms |
8796 KB |
n=500 |
36 |
Correct |
2 ms |
8796 KB |
n=500 |
37 |
Correct |
2 ms |
8796 KB |
n=500 |
38 |
Correct |
2 ms |
8796 KB |
n=500 |
39 |
Correct |
2 ms |
8792 KB |
n=500 |
40 |
Correct |
2 ms |
8796 KB |
n=500 |
41 |
Correct |
2 ms |
8796 KB |
n=500 |
42 |
Correct |
2 ms |
8796 KB |
n=500 |
43 |
Correct |
2 ms |
8792 KB |
n=500 |
44 |
Correct |
2 ms |
8796 KB |
n=500 |
45 |
Correct |
2 ms |
8796 KB |
n=500 |
46 |
Correct |
2 ms |
8768 KB |
n=500 |
47 |
Correct |
2 ms |
8796 KB |
n=500 |
48 |
Correct |
2 ms |
8792 KB |
n=500 |
49 |
Correct |
2 ms |
8792 KB |
n=500 |
50 |
Correct |
2 ms |
8792 KB |
n=500 |
51 |
Correct |
2 ms |
8792 KB |
n=500 |
52 |
Correct |
2 ms |
8796 KB |
n=500 |
53 |
Correct |
2 ms |
8888 KB |
n=500 |
54 |
Correct |
2 ms |
8796 KB |
n=500 |
55 |
Correct |
2 ms |
8796 KB |
n=278 |
56 |
Correct |
2 ms |
8796 KB |
n=500 |
57 |
Correct |
2 ms |
8796 KB |
n=500 |
58 |
Correct |
2 ms |
9048 KB |
n=500 |
59 |
Correct |
4 ms |
9308 KB |
n=2000 |
60 |
Correct |
4 ms |
9052 KB |
n=2000 |
61 |
Correct |
4 ms |
9052 KB |
n=2000 |
62 |
Correct |
4 ms |
9052 KB |
n=2000 |
63 |
Correct |
4 ms |
9560 KB |
n=2000 |
64 |
Correct |
4 ms |
9304 KB |
n=2000 |
65 |
Correct |
4 ms |
9308 KB |
n=2000 |
66 |
Correct |
4 ms |
9052 KB |
n=2000 |
67 |
Correct |
4 ms |
9304 KB |
n=2000 |
68 |
Correct |
4 ms |
9052 KB |
n=2000 |
69 |
Correct |
5 ms |
9308 KB |
n=2000 |
70 |
Correct |
3 ms |
9280 KB |
n=2000 |
71 |
Correct |
4 ms |
9308 KB |
n=2000 |
72 |
Correct |
4 ms |
9276 KB |
n=2000 |
73 |
Correct |
4 ms |
9304 KB |
n=2000 |
74 |
Correct |
4 ms |
9052 KB |
n=1844 |
75 |
Correct |
5 ms |
9304 KB |
n=2000 |
76 |
Correct |
5 ms |
9308 KB |
n=2000 |
77 |
Correct |
4 ms |
9052 KB |
n=2000 |
78 |
Correct |
5 ms |
9304 KB |
n=2000 |
79 |
Correct |
5 ms |
9052 KB |
n=2000 |
80 |
Correct |
4 ms |
9048 KB |
n=2000 |
81 |
Correct |
4 ms |
9048 KB |
n=2000 |
82 |
Correct |
5 ms |
9292 KB |
n=2000 |
83 |
Correct |
4 ms |
9052 KB |
n=2000 |
84 |
Correct |
4 ms |
9308 KB |
n=2000 |
85 |
Correct |
4 ms |
9052 KB |
n=2000 |
86 |
Correct |
4 ms |
9048 KB |
n=2000 |
87 |
Correct |
4 ms |
9140 KB |
n=2000 |
88 |
Correct |
4 ms |
9052 KB |
n=2000 |
89 |
Correct |
4 ms |
9120 KB |
n=2000 |
90 |
Correct |
4 ms |
9052 KB |
n=2000 |
91 |
Correct |
4 ms |
9308 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8540 KB |
n=5 |
2 |
Correct |
2 ms |
8760 KB |
n=100 |
3 |
Correct |
2 ms |
8540 KB |
n=100 |
4 |
Correct |
2 ms |
8540 KB |
n=100 |
5 |
Correct |
2 ms |
8540 KB |
n=100 |
6 |
Correct |
2 ms |
8540 KB |
n=100 |
7 |
Correct |
2 ms |
8540 KB |
n=100 |
8 |
Correct |
2 ms |
8540 KB |
n=100 |
9 |
Correct |
1 ms |
8540 KB |
n=100 |
10 |
Correct |
2 ms |
8540 KB |
n=100 |
11 |
Correct |
2 ms |
8536 KB |
n=100 |
12 |
Correct |
2 ms |
8792 KB |
n=100 |
13 |
Correct |
2 ms |
8540 KB |
n=100 |
14 |
Correct |
1 ms |
8540 KB |
n=100 |
15 |
Correct |
2 ms |
8752 KB |
n=100 |
16 |
Correct |
2 ms |
8536 KB |
n=100 |
17 |
Correct |
2 ms |
8540 KB |
n=100 |
18 |
Correct |
2 ms |
8536 KB |
n=100 |
19 |
Correct |
2 ms |
8536 KB |
n=100 |
20 |
Correct |
2 ms |
8540 KB |
n=100 |
21 |
Correct |
2 ms |
8540 KB |
n=100 |
22 |
Correct |
2 ms |
8540 KB |
n=100 |
23 |
Correct |
2 ms |
8540 KB |
n=100 |
24 |
Correct |
2 ms |
8540 KB |
n=100 |
25 |
Correct |
1 ms |
8540 KB |
n=100 |
26 |
Correct |
2 ms |
8540 KB |
n=12 |
27 |
Correct |
2 ms |
8540 KB |
n=100 |
28 |
Correct |
2 ms |
8792 KB |
n=500 |
29 |
Correct |
2 ms |
8796 KB |
n=500 |
30 |
Correct |
2 ms |
8884 KB |
n=500 |
31 |
Correct |
2 ms |
8952 KB |
n=500 |
32 |
Correct |
2 ms |
8796 KB |
n=500 |
33 |
Correct |
2 ms |
8792 KB |
n=500 |
34 |
Correct |
2 ms |
8792 KB |
n=500 |
35 |
Correct |
2 ms |
8796 KB |
n=500 |
36 |
Correct |
2 ms |
8796 KB |
n=500 |
37 |
Correct |
2 ms |
8796 KB |
n=500 |
38 |
Correct |
2 ms |
8796 KB |
n=500 |
39 |
Correct |
2 ms |
8792 KB |
n=500 |
40 |
Correct |
2 ms |
8796 KB |
n=500 |
41 |
Correct |
2 ms |
8796 KB |
n=500 |
42 |
Correct |
2 ms |
8796 KB |
n=500 |
43 |
Correct |
2 ms |
8792 KB |
n=500 |
44 |
Correct |
2 ms |
8796 KB |
n=500 |
45 |
Correct |
2 ms |
8796 KB |
n=500 |
46 |
Correct |
2 ms |
8768 KB |
n=500 |
47 |
Correct |
2 ms |
8796 KB |
n=500 |
48 |
Correct |
2 ms |
8792 KB |
n=500 |
49 |
Correct |
2 ms |
8792 KB |
n=500 |
50 |
Correct |
2 ms |
8792 KB |
n=500 |
51 |
Correct |
2 ms |
8792 KB |
n=500 |
52 |
Correct |
2 ms |
8796 KB |
n=500 |
53 |
Correct |
2 ms |
8888 KB |
n=500 |
54 |
Correct |
2 ms |
8796 KB |
n=500 |
55 |
Correct |
2 ms |
8796 KB |
n=278 |
56 |
Correct |
2 ms |
8796 KB |
n=500 |
57 |
Correct |
2 ms |
8796 KB |
n=500 |
58 |
Correct |
2 ms |
9048 KB |
n=500 |
59 |
Correct |
4 ms |
9308 KB |
n=2000 |
60 |
Correct |
4 ms |
9052 KB |
n=2000 |
61 |
Correct |
4 ms |
9052 KB |
n=2000 |
62 |
Correct |
4 ms |
9052 KB |
n=2000 |
63 |
Correct |
4 ms |
9560 KB |
n=2000 |
64 |
Correct |
4 ms |
9304 KB |
n=2000 |
65 |
Correct |
4 ms |
9308 KB |
n=2000 |
66 |
Correct |
4 ms |
9052 KB |
n=2000 |
67 |
Correct |
4 ms |
9304 KB |
n=2000 |
68 |
Correct |
4 ms |
9052 KB |
n=2000 |
69 |
Correct |
5 ms |
9308 KB |
n=2000 |
70 |
Correct |
3 ms |
9280 KB |
n=2000 |
71 |
Correct |
4 ms |
9308 KB |
n=2000 |
72 |
Correct |
4 ms |
9276 KB |
n=2000 |
73 |
Correct |
4 ms |
9304 KB |
n=2000 |
74 |
Correct |
4 ms |
9052 KB |
n=1844 |
75 |
Correct |
5 ms |
9304 KB |
n=2000 |
76 |
Correct |
5 ms |
9308 KB |
n=2000 |
77 |
Correct |
4 ms |
9052 KB |
n=2000 |
78 |
Correct |
5 ms |
9304 KB |
n=2000 |
79 |
Correct |
5 ms |
9052 KB |
n=2000 |
80 |
Correct |
4 ms |
9048 KB |
n=2000 |
81 |
Correct |
4 ms |
9048 KB |
n=2000 |
82 |
Correct |
5 ms |
9292 KB |
n=2000 |
83 |
Correct |
4 ms |
9052 KB |
n=2000 |
84 |
Correct |
4 ms |
9308 KB |
n=2000 |
85 |
Correct |
4 ms |
9052 KB |
n=2000 |
86 |
Correct |
4 ms |
9048 KB |
n=2000 |
87 |
Correct |
4 ms |
9140 KB |
n=2000 |
88 |
Correct |
4 ms |
9052 KB |
n=2000 |
89 |
Correct |
4 ms |
9120 KB |
n=2000 |
90 |
Correct |
4 ms |
9052 KB |
n=2000 |
91 |
Correct |
4 ms |
9308 KB |
n=2000 |
92 |
Correct |
671 ms |
100496 KB |
n=200000 |
93 |
Correct |
939 ms |
100696 KB |
n=200000 |
94 |
Correct |
897 ms |
100312 KB |
n=200000 |
95 |
Correct |
646 ms |
100452 KB |
n=200000 |
96 |
Correct |
614 ms |
100288 KB |
n=200000 |
97 |
Correct |
951 ms |
101088 KB |
n=200000 |
98 |
Correct |
652 ms |
100188 KB |
n=200000 |
99 |
Correct |
810 ms |
100636 KB |
n=200000 |
100 |
Correct |
623 ms |
100288 KB |
n=200000 |
101 |
Correct |
904 ms |
100040 KB |
n=200000 |
102 |
Correct |
405 ms |
101660 KB |
n=200000 |
103 |
Correct |
401 ms |
101552 KB |
n=200000 |
104 |
Correct |
402 ms |
101716 KB |
n=200000 |
105 |
Correct |
414 ms |
102164 KB |
n=200000 |
106 |
Correct |
378 ms |
102160 KB |
n=200000 |
107 |
Correct |
425 ms |
102152 KB |
n=200000 |
108 |
Correct |
704 ms |
100584 KB |
n=200000 |
109 |
Correct |
750 ms |
100592 KB |
n=200000 |
110 |
Correct |
763 ms |
100436 KB |
n=200000 |
111 |
Correct |
637 ms |
99688 KB |
n=200000 |
112 |
Correct |
900 ms |
100280 KB |
n=200000 |
113 |
Correct |
968 ms |
101008 KB |
n=200000 |
114 |
Correct |
639 ms |
99660 KB |
n=200000 |
115 |
Correct |
1006 ms |
101120 KB |
n=200000 |
116 |
Correct |
637 ms |
100276 KB |
n=200000 |
117 |
Correct |
900 ms |
99948 KB |
n=200000 |
118 |
Correct |
957 ms |
100516 KB |
n=200000 |
119 |
Correct |
619 ms |
100556 KB |
n=200000 |
120 |
Correct |
845 ms |
98692 KB |
n=200000 |
121 |
Correct |
829 ms |
98792 KB |
n=200000 |
122 |
Correct |
852 ms |
99128 KB |
n=200000 |
123 |
Correct |
402 ms |
101960 KB |
n=200000 |
124 |
Incorrect |
123 ms |
29776 KB |
Wrong range. |
125 |
Halted |
0 ms |
0 KB |
- |