//gm --- akezhon
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define int long long
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define tm (tl+tr)/2
#define TL v+v, tl, tm
#define TR v+v+1, tm+1, tr
#define DA l <= tl && tr <= r
#define NET r < tl || tr < l
#define double long double
using namespace std;
const int N=2e5+7;
const int M=1e9+7;
const int inf=1e9;
vector <int> g[N];
int tin[N], tout[N], timer;
int up[N][20];
int n, m, q;
int a[N];
void dfs(int v=1, int p=1){
tin[v] = ++timer;
up[v][0] = p;
for(int i=1; i <= 18; i++)up[v][i] = up[up[v][i-1]][i-1];
for(int to : g[v]){
if(to != p)dfs(to, v);
}
tout[v] = timer;
}
bool is(int a, int b){
return tin[a] <= tin[b] && tout[b] <= tout[a];
}
int lca(int a, int b){
if(is(a, b))return a;
if(is(b, a))return b;
for(int i=18; i >= 0; i--){
if(!is(up[a][i], b))a=up[a][i];
}
return up[a][0];
}
set <int> pos1[N], pos2[N];
void AlemAmenov(){
cin >> n >> m >> q;
for(int i=1; i < n; i++){
int x, y;
cin >> x >> y;
g[x].pb(y);
g[y].pb(x);
}
dfs();
for(int i=1; i <= m; i++){
cin >> a[i];
pos1[a[i]].insert(i);
if(1 < i)pos2[lca(a[i], a[i-1])].insert(i-1);
}
while(q--){
int t, pos, l, r, v;
cin >> t;
if(t == 1){
cin >> pos >> v;
pos1[a[pos]].erase(pos);
pos1[v].insert(pos);
if(1 < pos){
pos2[lca(a[pos-1], a[pos])].erase(pos-1);
pos2[lca(a[pos-1], v)].insert(pos-1);
}
if(pos < m){
pos2[lca(a[pos+1], a[pos])].erase(pos);
pos2[lca(a[pos+1], v)].insert(pos);
}
a[pos] = v;
}
else {
cin >> l >> r >> v;
pos = *pos1[v].lower_bound(l);
if(l <= pos && pos <= r)cout << pos << ' ' << pos << '\n';
else {
pos = *pos2[v].lower_bound(l);
if(l <= pos && pos < r)cout << pos << ' ' << pos+1 << '\n';
else cout << "-1 -1\n";
}
}
}
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen("promote.in", "r", stdin);
// freopen("promote.out", "w", stdout);
int RealName=1;
// cin >> RealName;
// int C=0;
while(RealName--){
// cout << "Case " << ++C << ":\n";
AlemAmenov();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
26968 KB |
n=5 |
2 |
Correct |
5 ms |
26972 KB |
n=100 |
3 |
Correct |
6 ms |
26972 KB |
n=100 |
4 |
Correct |
6 ms |
27076 KB |
n=100 |
5 |
Correct |
5 ms |
26972 KB |
n=100 |
6 |
Correct |
5 ms |
26892 KB |
n=100 |
7 |
Correct |
6 ms |
26972 KB |
n=100 |
8 |
Correct |
6 ms |
26972 KB |
n=100 |
9 |
Correct |
6 ms |
26972 KB |
n=100 |
10 |
Correct |
5 ms |
26972 KB |
n=100 |
11 |
Correct |
6 ms |
26972 KB |
n=100 |
12 |
Correct |
6 ms |
26972 KB |
n=100 |
13 |
Correct |
6 ms |
27144 KB |
n=100 |
14 |
Correct |
5 ms |
26972 KB |
n=100 |
15 |
Correct |
5 ms |
26972 KB |
n=100 |
16 |
Correct |
6 ms |
26972 KB |
n=100 |
17 |
Correct |
5 ms |
26972 KB |
n=100 |
18 |
Correct |
6 ms |
26972 KB |
n=100 |
19 |
Correct |
6 ms |
26972 KB |
n=100 |
20 |
Correct |
6 ms |
26972 KB |
n=100 |
21 |
Correct |
6 ms |
26972 KB |
n=100 |
22 |
Correct |
6 ms |
26968 KB |
n=100 |
23 |
Correct |
6 ms |
26972 KB |
n=100 |
24 |
Correct |
6 ms |
26972 KB |
n=100 |
25 |
Correct |
6 ms |
26972 KB |
n=100 |
26 |
Correct |
6 ms |
26972 KB |
n=12 |
27 |
Correct |
5 ms |
26972 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
26968 KB |
n=5 |
2 |
Correct |
5 ms |
26972 KB |
n=100 |
3 |
Correct |
6 ms |
26972 KB |
n=100 |
4 |
Correct |
6 ms |
27076 KB |
n=100 |
5 |
Correct |
5 ms |
26972 KB |
n=100 |
6 |
Correct |
5 ms |
26892 KB |
n=100 |
7 |
Correct |
6 ms |
26972 KB |
n=100 |
8 |
Correct |
6 ms |
26972 KB |
n=100 |
9 |
Correct |
6 ms |
26972 KB |
n=100 |
10 |
Correct |
5 ms |
26972 KB |
n=100 |
11 |
Correct |
6 ms |
26972 KB |
n=100 |
12 |
Correct |
6 ms |
26972 KB |
n=100 |
13 |
Correct |
6 ms |
27144 KB |
n=100 |
14 |
Correct |
5 ms |
26972 KB |
n=100 |
15 |
Correct |
5 ms |
26972 KB |
n=100 |
16 |
Correct |
6 ms |
26972 KB |
n=100 |
17 |
Correct |
5 ms |
26972 KB |
n=100 |
18 |
Correct |
6 ms |
26972 KB |
n=100 |
19 |
Correct |
6 ms |
26972 KB |
n=100 |
20 |
Correct |
6 ms |
26972 KB |
n=100 |
21 |
Correct |
6 ms |
26972 KB |
n=100 |
22 |
Correct |
6 ms |
26968 KB |
n=100 |
23 |
Correct |
6 ms |
26972 KB |
n=100 |
24 |
Correct |
6 ms |
26972 KB |
n=100 |
25 |
Correct |
6 ms |
26972 KB |
n=100 |
26 |
Correct |
6 ms |
26972 KB |
n=12 |
27 |
Correct |
5 ms |
26972 KB |
n=100 |
28 |
Correct |
6 ms |
26968 KB |
n=500 |
29 |
Correct |
7 ms |
26972 KB |
n=500 |
30 |
Correct |
6 ms |
26972 KB |
n=500 |
31 |
Correct |
6 ms |
27168 KB |
n=500 |
32 |
Correct |
6 ms |
26972 KB |
n=500 |
33 |
Correct |
6 ms |
26972 KB |
n=500 |
34 |
Correct |
6 ms |
26972 KB |
n=500 |
35 |
Correct |
6 ms |
26968 KB |
n=500 |
36 |
Correct |
6 ms |
27204 KB |
n=500 |
37 |
Correct |
7 ms |
26972 KB |
n=500 |
38 |
Correct |
6 ms |
26972 KB |
n=500 |
39 |
Correct |
6 ms |
26972 KB |
n=500 |
40 |
Correct |
6 ms |
27136 KB |
n=500 |
41 |
Correct |
6 ms |
26968 KB |
n=500 |
42 |
Correct |
6 ms |
26968 KB |
n=500 |
43 |
Correct |
6 ms |
26972 KB |
n=500 |
44 |
Correct |
6 ms |
26972 KB |
n=500 |
45 |
Correct |
6 ms |
26972 KB |
n=500 |
46 |
Correct |
6 ms |
26972 KB |
n=500 |
47 |
Correct |
6 ms |
26968 KB |
n=500 |
48 |
Correct |
6 ms |
26968 KB |
n=500 |
49 |
Correct |
6 ms |
26972 KB |
n=500 |
50 |
Correct |
6 ms |
26972 KB |
n=500 |
51 |
Correct |
6 ms |
27224 KB |
n=500 |
52 |
Correct |
6 ms |
26972 KB |
n=500 |
53 |
Correct |
6 ms |
26972 KB |
n=500 |
54 |
Correct |
6 ms |
26972 KB |
n=500 |
55 |
Correct |
6 ms |
26968 KB |
n=278 |
56 |
Correct |
6 ms |
26968 KB |
n=500 |
57 |
Correct |
6 ms |
26972 KB |
n=500 |
58 |
Correct |
6 ms |
26972 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
26968 KB |
n=5 |
2 |
Correct |
5 ms |
26972 KB |
n=100 |
3 |
Correct |
6 ms |
26972 KB |
n=100 |
4 |
Correct |
6 ms |
27076 KB |
n=100 |
5 |
Correct |
5 ms |
26972 KB |
n=100 |
6 |
Correct |
5 ms |
26892 KB |
n=100 |
7 |
Correct |
6 ms |
26972 KB |
n=100 |
8 |
Correct |
6 ms |
26972 KB |
n=100 |
9 |
Correct |
6 ms |
26972 KB |
n=100 |
10 |
Correct |
5 ms |
26972 KB |
n=100 |
11 |
Correct |
6 ms |
26972 KB |
n=100 |
12 |
Correct |
6 ms |
26972 KB |
n=100 |
13 |
Correct |
6 ms |
27144 KB |
n=100 |
14 |
Correct |
5 ms |
26972 KB |
n=100 |
15 |
Correct |
5 ms |
26972 KB |
n=100 |
16 |
Correct |
6 ms |
26972 KB |
n=100 |
17 |
Correct |
5 ms |
26972 KB |
n=100 |
18 |
Correct |
6 ms |
26972 KB |
n=100 |
19 |
Correct |
6 ms |
26972 KB |
n=100 |
20 |
Correct |
6 ms |
26972 KB |
n=100 |
21 |
Correct |
6 ms |
26972 KB |
n=100 |
22 |
Correct |
6 ms |
26968 KB |
n=100 |
23 |
Correct |
6 ms |
26972 KB |
n=100 |
24 |
Correct |
6 ms |
26972 KB |
n=100 |
25 |
Correct |
6 ms |
26972 KB |
n=100 |
26 |
Correct |
6 ms |
26972 KB |
n=12 |
27 |
Correct |
5 ms |
26972 KB |
n=100 |
28 |
Correct |
6 ms |
26968 KB |
n=500 |
29 |
Correct |
7 ms |
26972 KB |
n=500 |
30 |
Correct |
6 ms |
26972 KB |
n=500 |
31 |
Correct |
6 ms |
27168 KB |
n=500 |
32 |
Correct |
6 ms |
26972 KB |
n=500 |
33 |
Correct |
6 ms |
26972 KB |
n=500 |
34 |
Correct |
6 ms |
26972 KB |
n=500 |
35 |
Correct |
6 ms |
26968 KB |
n=500 |
36 |
Correct |
6 ms |
27204 KB |
n=500 |
37 |
Correct |
7 ms |
26972 KB |
n=500 |
38 |
Correct |
6 ms |
26972 KB |
n=500 |
39 |
Correct |
6 ms |
26972 KB |
n=500 |
40 |
Correct |
6 ms |
27136 KB |
n=500 |
41 |
Correct |
6 ms |
26968 KB |
n=500 |
42 |
Correct |
6 ms |
26968 KB |
n=500 |
43 |
Correct |
6 ms |
26972 KB |
n=500 |
44 |
Correct |
6 ms |
26972 KB |
n=500 |
45 |
Correct |
6 ms |
26972 KB |
n=500 |
46 |
Correct |
6 ms |
26972 KB |
n=500 |
47 |
Correct |
6 ms |
26968 KB |
n=500 |
48 |
Correct |
6 ms |
26968 KB |
n=500 |
49 |
Correct |
6 ms |
26972 KB |
n=500 |
50 |
Correct |
6 ms |
26972 KB |
n=500 |
51 |
Correct |
6 ms |
27224 KB |
n=500 |
52 |
Correct |
6 ms |
26972 KB |
n=500 |
53 |
Correct |
6 ms |
26972 KB |
n=500 |
54 |
Correct |
6 ms |
26972 KB |
n=500 |
55 |
Correct |
6 ms |
26968 KB |
n=278 |
56 |
Correct |
6 ms |
26968 KB |
n=500 |
57 |
Correct |
6 ms |
26972 KB |
n=500 |
58 |
Correct |
6 ms |
26972 KB |
n=500 |
59 |
Correct |
8 ms |
27228 KB |
n=2000 |
60 |
Correct |
7 ms |
27284 KB |
n=2000 |
61 |
Correct |
8 ms |
27456 KB |
n=2000 |
62 |
Correct |
8 ms |
27392 KB |
n=2000 |
63 |
Correct |
8 ms |
27228 KB |
n=2000 |
64 |
Correct |
10 ms |
27224 KB |
n=2000 |
65 |
Correct |
8 ms |
27224 KB |
n=2000 |
66 |
Correct |
9 ms |
27484 KB |
n=2000 |
67 |
Correct |
8 ms |
27320 KB |
n=2000 |
68 |
Correct |
8 ms |
27228 KB |
n=2000 |
69 |
Correct |
7 ms |
27224 KB |
n=2000 |
70 |
Correct |
7 ms |
27228 KB |
n=2000 |
71 |
Correct |
7 ms |
27228 KB |
n=2000 |
72 |
Correct |
7 ms |
27228 KB |
n=2000 |
73 |
Correct |
7 ms |
27228 KB |
n=2000 |
74 |
Correct |
8 ms |
27228 KB |
n=1844 |
75 |
Correct |
8 ms |
27228 KB |
n=2000 |
76 |
Correct |
8 ms |
27228 KB |
n=2000 |
77 |
Correct |
8 ms |
27228 KB |
n=2000 |
78 |
Correct |
8 ms |
27228 KB |
n=2000 |
79 |
Correct |
8 ms |
27228 KB |
n=2000 |
80 |
Correct |
7 ms |
27484 KB |
n=2000 |
81 |
Correct |
8 ms |
27228 KB |
n=2000 |
82 |
Correct |
8 ms |
27228 KB |
n=2000 |
83 |
Correct |
8 ms |
27228 KB |
n=2000 |
84 |
Correct |
8 ms |
27224 KB |
n=2000 |
85 |
Correct |
8 ms |
27228 KB |
n=2000 |
86 |
Correct |
8 ms |
27484 KB |
n=2000 |
87 |
Correct |
8 ms |
27224 KB |
n=2000 |
88 |
Correct |
7 ms |
27480 KB |
n=2000 |
89 |
Correct |
7 ms |
27484 KB |
n=2000 |
90 |
Correct |
7 ms |
27632 KB |
n=2000 |
91 |
Correct |
7 ms |
27224 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
26968 KB |
n=5 |
2 |
Correct |
5 ms |
26972 KB |
n=100 |
3 |
Correct |
6 ms |
26972 KB |
n=100 |
4 |
Correct |
6 ms |
27076 KB |
n=100 |
5 |
Correct |
5 ms |
26972 KB |
n=100 |
6 |
Correct |
5 ms |
26892 KB |
n=100 |
7 |
Correct |
6 ms |
26972 KB |
n=100 |
8 |
Correct |
6 ms |
26972 KB |
n=100 |
9 |
Correct |
6 ms |
26972 KB |
n=100 |
10 |
Correct |
5 ms |
26972 KB |
n=100 |
11 |
Correct |
6 ms |
26972 KB |
n=100 |
12 |
Correct |
6 ms |
26972 KB |
n=100 |
13 |
Correct |
6 ms |
27144 KB |
n=100 |
14 |
Correct |
5 ms |
26972 KB |
n=100 |
15 |
Correct |
5 ms |
26972 KB |
n=100 |
16 |
Correct |
6 ms |
26972 KB |
n=100 |
17 |
Correct |
5 ms |
26972 KB |
n=100 |
18 |
Correct |
6 ms |
26972 KB |
n=100 |
19 |
Correct |
6 ms |
26972 KB |
n=100 |
20 |
Correct |
6 ms |
26972 KB |
n=100 |
21 |
Correct |
6 ms |
26972 KB |
n=100 |
22 |
Correct |
6 ms |
26968 KB |
n=100 |
23 |
Correct |
6 ms |
26972 KB |
n=100 |
24 |
Correct |
6 ms |
26972 KB |
n=100 |
25 |
Correct |
6 ms |
26972 KB |
n=100 |
26 |
Correct |
6 ms |
26972 KB |
n=12 |
27 |
Correct |
5 ms |
26972 KB |
n=100 |
28 |
Correct |
6 ms |
26968 KB |
n=500 |
29 |
Correct |
7 ms |
26972 KB |
n=500 |
30 |
Correct |
6 ms |
26972 KB |
n=500 |
31 |
Correct |
6 ms |
27168 KB |
n=500 |
32 |
Correct |
6 ms |
26972 KB |
n=500 |
33 |
Correct |
6 ms |
26972 KB |
n=500 |
34 |
Correct |
6 ms |
26972 KB |
n=500 |
35 |
Correct |
6 ms |
26968 KB |
n=500 |
36 |
Correct |
6 ms |
27204 KB |
n=500 |
37 |
Correct |
7 ms |
26972 KB |
n=500 |
38 |
Correct |
6 ms |
26972 KB |
n=500 |
39 |
Correct |
6 ms |
26972 KB |
n=500 |
40 |
Correct |
6 ms |
27136 KB |
n=500 |
41 |
Correct |
6 ms |
26968 KB |
n=500 |
42 |
Correct |
6 ms |
26968 KB |
n=500 |
43 |
Correct |
6 ms |
26972 KB |
n=500 |
44 |
Correct |
6 ms |
26972 KB |
n=500 |
45 |
Correct |
6 ms |
26972 KB |
n=500 |
46 |
Correct |
6 ms |
26972 KB |
n=500 |
47 |
Correct |
6 ms |
26968 KB |
n=500 |
48 |
Correct |
6 ms |
26968 KB |
n=500 |
49 |
Correct |
6 ms |
26972 KB |
n=500 |
50 |
Correct |
6 ms |
26972 KB |
n=500 |
51 |
Correct |
6 ms |
27224 KB |
n=500 |
52 |
Correct |
6 ms |
26972 KB |
n=500 |
53 |
Correct |
6 ms |
26972 KB |
n=500 |
54 |
Correct |
6 ms |
26972 KB |
n=500 |
55 |
Correct |
6 ms |
26968 KB |
n=278 |
56 |
Correct |
6 ms |
26968 KB |
n=500 |
57 |
Correct |
6 ms |
26972 KB |
n=500 |
58 |
Correct |
6 ms |
26972 KB |
n=500 |
59 |
Correct |
8 ms |
27228 KB |
n=2000 |
60 |
Correct |
7 ms |
27284 KB |
n=2000 |
61 |
Correct |
8 ms |
27456 KB |
n=2000 |
62 |
Correct |
8 ms |
27392 KB |
n=2000 |
63 |
Correct |
8 ms |
27228 KB |
n=2000 |
64 |
Correct |
10 ms |
27224 KB |
n=2000 |
65 |
Correct |
8 ms |
27224 KB |
n=2000 |
66 |
Correct |
9 ms |
27484 KB |
n=2000 |
67 |
Correct |
8 ms |
27320 KB |
n=2000 |
68 |
Correct |
8 ms |
27228 KB |
n=2000 |
69 |
Correct |
7 ms |
27224 KB |
n=2000 |
70 |
Correct |
7 ms |
27228 KB |
n=2000 |
71 |
Correct |
7 ms |
27228 KB |
n=2000 |
72 |
Correct |
7 ms |
27228 KB |
n=2000 |
73 |
Correct |
7 ms |
27228 KB |
n=2000 |
74 |
Correct |
8 ms |
27228 KB |
n=1844 |
75 |
Correct |
8 ms |
27228 KB |
n=2000 |
76 |
Correct |
8 ms |
27228 KB |
n=2000 |
77 |
Correct |
8 ms |
27228 KB |
n=2000 |
78 |
Correct |
8 ms |
27228 KB |
n=2000 |
79 |
Correct |
8 ms |
27228 KB |
n=2000 |
80 |
Correct |
7 ms |
27484 KB |
n=2000 |
81 |
Correct |
8 ms |
27228 KB |
n=2000 |
82 |
Correct |
8 ms |
27228 KB |
n=2000 |
83 |
Correct |
8 ms |
27228 KB |
n=2000 |
84 |
Correct |
8 ms |
27224 KB |
n=2000 |
85 |
Correct |
8 ms |
27228 KB |
n=2000 |
86 |
Correct |
8 ms |
27484 KB |
n=2000 |
87 |
Correct |
8 ms |
27224 KB |
n=2000 |
88 |
Correct |
7 ms |
27480 KB |
n=2000 |
89 |
Correct |
7 ms |
27484 KB |
n=2000 |
90 |
Correct |
7 ms |
27632 KB |
n=2000 |
91 |
Correct |
7 ms |
27224 KB |
n=2000 |
92 |
Correct |
549 ms |
87656 KB |
n=200000 |
93 |
Correct |
609 ms |
91476 KB |
n=200000 |
94 |
Correct |
415 ms |
94292 KB |
n=200000 |
95 |
Correct |
533 ms |
87744 KB |
n=200000 |
96 |
Correct |
518 ms |
87576 KB |
n=200000 |
97 |
Correct |
658 ms |
90452 KB |
n=200000 |
98 |
Correct |
528 ms |
87516 KB |
n=200000 |
99 |
Correct |
606 ms |
87256 KB |
n=200000 |
100 |
Correct |
535 ms |
87528 KB |
n=200000 |
101 |
Correct |
362 ms |
95060 KB |
n=200000 |
102 |
Correct |
316 ms |
88660 KB |
n=200000 |
103 |
Correct |
309 ms |
88576 KB |
n=200000 |
104 |
Correct |
348 ms |
88808 KB |
n=200000 |
105 |
Correct |
318 ms |
88548 KB |
n=200000 |
106 |
Correct |
315 ms |
88404 KB |
n=200000 |
107 |
Correct |
316 ms |
88400 KB |
n=200000 |
108 |
Correct |
540 ms |
87372 KB |
n=200000 |
109 |
Correct |
537 ms |
87344 KB |
n=200000 |
110 |
Correct |
535 ms |
87360 KB |
n=200000 |
111 |
Correct |
531 ms |
87412 KB |
n=200000 |
112 |
Correct |
393 ms |
94548 KB |
n=200000 |
113 |
Correct |
659 ms |
90376 KB |
n=200000 |
114 |
Correct |
535 ms |
87484 KB |
n=200000 |
115 |
Correct |
788 ms |
88468 KB |
n=200000 |
116 |
Correct |
516 ms |
87232 KB |
n=200000 |
117 |
Correct |
386 ms |
94548 KB |
n=200000 |
118 |
Correct |
713 ms |
89316 KB |
n=200000 |
119 |
Correct |
513 ms |
87156 KB |
n=200000 |
120 |
Correct |
322 ms |
94804 KB |
n=200000 |
121 |
Correct |
322 ms |
94836 KB |
n=200000 |
122 |
Correct |
333 ms |
95580 KB |
n=200000 |
123 |
Correct |
327 ms |
88188 KB |
n=200000 |
124 |
Correct |
94 ms |
42072 KB |
n=25264 |