//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 ll 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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
27484 KB |
n=5 |
2 |
Correct |
5 ms |
27360 KB |
n=100 |
3 |
Correct |
5 ms |
27484 KB |
n=100 |
4 |
Correct |
5 ms |
27484 KB |
n=100 |
5 |
Correct |
5 ms |
27484 KB |
n=100 |
6 |
Correct |
5 ms |
27484 KB |
n=100 |
7 |
Correct |
5 ms |
27484 KB |
n=100 |
8 |
Correct |
5 ms |
27484 KB |
n=100 |
9 |
Correct |
5 ms |
27480 KB |
n=100 |
10 |
Correct |
5 ms |
27484 KB |
n=100 |
11 |
Correct |
5 ms |
27484 KB |
n=100 |
12 |
Correct |
5 ms |
27484 KB |
n=100 |
13 |
Correct |
5 ms |
27484 KB |
n=100 |
14 |
Correct |
6 ms |
27484 KB |
n=100 |
15 |
Correct |
5 ms |
27484 KB |
n=100 |
16 |
Correct |
5 ms |
27484 KB |
n=100 |
17 |
Correct |
5 ms |
27484 KB |
n=100 |
18 |
Correct |
5 ms |
27548 KB |
n=100 |
19 |
Correct |
5 ms |
27484 KB |
n=100 |
20 |
Correct |
5 ms |
27484 KB |
n=100 |
21 |
Correct |
5 ms |
27484 KB |
n=100 |
22 |
Correct |
5 ms |
27484 KB |
n=100 |
23 |
Correct |
5 ms |
27552 KB |
n=100 |
24 |
Correct |
5 ms |
27480 KB |
n=100 |
25 |
Correct |
5 ms |
27484 KB |
n=100 |
26 |
Correct |
5 ms |
27480 KB |
n=12 |
27 |
Correct |
5 ms |
27736 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
27484 KB |
n=5 |
2 |
Correct |
5 ms |
27360 KB |
n=100 |
3 |
Correct |
5 ms |
27484 KB |
n=100 |
4 |
Correct |
5 ms |
27484 KB |
n=100 |
5 |
Correct |
5 ms |
27484 KB |
n=100 |
6 |
Correct |
5 ms |
27484 KB |
n=100 |
7 |
Correct |
5 ms |
27484 KB |
n=100 |
8 |
Correct |
5 ms |
27484 KB |
n=100 |
9 |
Correct |
5 ms |
27480 KB |
n=100 |
10 |
Correct |
5 ms |
27484 KB |
n=100 |
11 |
Correct |
5 ms |
27484 KB |
n=100 |
12 |
Correct |
5 ms |
27484 KB |
n=100 |
13 |
Correct |
5 ms |
27484 KB |
n=100 |
14 |
Correct |
6 ms |
27484 KB |
n=100 |
15 |
Correct |
5 ms |
27484 KB |
n=100 |
16 |
Correct |
5 ms |
27484 KB |
n=100 |
17 |
Correct |
5 ms |
27484 KB |
n=100 |
18 |
Correct |
5 ms |
27548 KB |
n=100 |
19 |
Correct |
5 ms |
27484 KB |
n=100 |
20 |
Correct |
5 ms |
27484 KB |
n=100 |
21 |
Correct |
5 ms |
27484 KB |
n=100 |
22 |
Correct |
5 ms |
27484 KB |
n=100 |
23 |
Correct |
5 ms |
27552 KB |
n=100 |
24 |
Correct |
5 ms |
27480 KB |
n=100 |
25 |
Correct |
5 ms |
27484 KB |
n=100 |
26 |
Correct |
5 ms |
27480 KB |
n=12 |
27 |
Correct |
5 ms |
27736 KB |
n=100 |
28 |
Correct |
6 ms |
27484 KB |
n=500 |
29 |
Correct |
6 ms |
27576 KB |
n=500 |
30 |
Correct |
6 ms |
27484 KB |
n=500 |
31 |
Correct |
5 ms |
27480 KB |
n=500 |
32 |
Correct |
6 ms |
27484 KB |
n=500 |
33 |
Correct |
6 ms |
27484 KB |
n=500 |
34 |
Correct |
6 ms |
27652 KB |
n=500 |
35 |
Correct |
5 ms |
27484 KB |
n=500 |
36 |
Correct |
5 ms |
27484 KB |
n=500 |
37 |
Correct |
5 ms |
27484 KB |
n=500 |
38 |
Correct |
7 ms |
27484 KB |
n=500 |
39 |
Correct |
6 ms |
27484 KB |
n=500 |
40 |
Correct |
5 ms |
27568 KB |
n=500 |
41 |
Correct |
5 ms |
27548 KB |
n=500 |
42 |
Correct |
6 ms |
27480 KB |
n=500 |
43 |
Correct |
6 ms |
27480 KB |
n=500 |
44 |
Correct |
6 ms |
27484 KB |
n=500 |
45 |
Correct |
6 ms |
27648 KB |
n=500 |
46 |
Correct |
6 ms |
27484 KB |
n=500 |
47 |
Correct |
5 ms |
27484 KB |
n=500 |
48 |
Correct |
6 ms |
27480 KB |
n=500 |
49 |
Correct |
5 ms |
27484 KB |
n=500 |
50 |
Correct |
6 ms |
27484 KB |
n=500 |
51 |
Correct |
5 ms |
27484 KB |
n=500 |
52 |
Correct |
6 ms |
27612 KB |
n=500 |
53 |
Correct |
6 ms |
27484 KB |
n=500 |
54 |
Correct |
5 ms |
27480 KB |
n=500 |
55 |
Correct |
5 ms |
27484 KB |
n=278 |
56 |
Correct |
6 ms |
27484 KB |
n=500 |
57 |
Correct |
6 ms |
27480 KB |
n=500 |
58 |
Correct |
6 ms |
27736 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
27484 KB |
n=5 |
2 |
Correct |
5 ms |
27360 KB |
n=100 |
3 |
Correct |
5 ms |
27484 KB |
n=100 |
4 |
Correct |
5 ms |
27484 KB |
n=100 |
5 |
Correct |
5 ms |
27484 KB |
n=100 |
6 |
Correct |
5 ms |
27484 KB |
n=100 |
7 |
Correct |
5 ms |
27484 KB |
n=100 |
8 |
Correct |
5 ms |
27484 KB |
n=100 |
9 |
Correct |
5 ms |
27480 KB |
n=100 |
10 |
Correct |
5 ms |
27484 KB |
n=100 |
11 |
Correct |
5 ms |
27484 KB |
n=100 |
12 |
Correct |
5 ms |
27484 KB |
n=100 |
13 |
Correct |
5 ms |
27484 KB |
n=100 |
14 |
Correct |
6 ms |
27484 KB |
n=100 |
15 |
Correct |
5 ms |
27484 KB |
n=100 |
16 |
Correct |
5 ms |
27484 KB |
n=100 |
17 |
Correct |
5 ms |
27484 KB |
n=100 |
18 |
Correct |
5 ms |
27548 KB |
n=100 |
19 |
Correct |
5 ms |
27484 KB |
n=100 |
20 |
Correct |
5 ms |
27484 KB |
n=100 |
21 |
Correct |
5 ms |
27484 KB |
n=100 |
22 |
Correct |
5 ms |
27484 KB |
n=100 |
23 |
Correct |
5 ms |
27552 KB |
n=100 |
24 |
Correct |
5 ms |
27480 KB |
n=100 |
25 |
Correct |
5 ms |
27484 KB |
n=100 |
26 |
Correct |
5 ms |
27480 KB |
n=12 |
27 |
Correct |
5 ms |
27736 KB |
n=100 |
28 |
Correct |
6 ms |
27484 KB |
n=500 |
29 |
Correct |
6 ms |
27576 KB |
n=500 |
30 |
Correct |
6 ms |
27484 KB |
n=500 |
31 |
Correct |
5 ms |
27480 KB |
n=500 |
32 |
Correct |
6 ms |
27484 KB |
n=500 |
33 |
Correct |
6 ms |
27484 KB |
n=500 |
34 |
Correct |
6 ms |
27652 KB |
n=500 |
35 |
Correct |
5 ms |
27484 KB |
n=500 |
36 |
Correct |
5 ms |
27484 KB |
n=500 |
37 |
Correct |
5 ms |
27484 KB |
n=500 |
38 |
Correct |
7 ms |
27484 KB |
n=500 |
39 |
Correct |
6 ms |
27484 KB |
n=500 |
40 |
Correct |
5 ms |
27568 KB |
n=500 |
41 |
Correct |
5 ms |
27548 KB |
n=500 |
42 |
Correct |
6 ms |
27480 KB |
n=500 |
43 |
Correct |
6 ms |
27480 KB |
n=500 |
44 |
Correct |
6 ms |
27484 KB |
n=500 |
45 |
Correct |
6 ms |
27648 KB |
n=500 |
46 |
Correct |
6 ms |
27484 KB |
n=500 |
47 |
Correct |
5 ms |
27484 KB |
n=500 |
48 |
Correct |
6 ms |
27480 KB |
n=500 |
49 |
Correct |
5 ms |
27484 KB |
n=500 |
50 |
Correct |
6 ms |
27484 KB |
n=500 |
51 |
Correct |
5 ms |
27484 KB |
n=500 |
52 |
Correct |
6 ms |
27612 KB |
n=500 |
53 |
Correct |
6 ms |
27484 KB |
n=500 |
54 |
Correct |
5 ms |
27480 KB |
n=500 |
55 |
Correct |
5 ms |
27484 KB |
n=278 |
56 |
Correct |
6 ms |
27484 KB |
n=500 |
57 |
Correct |
6 ms |
27480 KB |
n=500 |
58 |
Correct |
6 ms |
27736 KB |
n=500 |
59 |
Correct |
8 ms |
27736 KB |
n=2000 |
60 |
Correct |
7 ms |
27992 KB |
n=2000 |
61 |
Correct |
7 ms |
27740 KB |
n=2000 |
62 |
Correct |
7 ms |
27860 KB |
n=2000 |
63 |
Correct |
8 ms |
27788 KB |
n=2000 |
64 |
Correct |
7 ms |
27740 KB |
n=2000 |
65 |
Correct |
8 ms |
27844 KB |
n=2000 |
66 |
Correct |
7 ms |
27736 KB |
n=2000 |
67 |
Correct |
8 ms |
27636 KB |
n=2000 |
68 |
Correct |
7 ms |
27740 KB |
n=2000 |
69 |
Correct |
7 ms |
27736 KB |
n=2000 |
70 |
Correct |
7 ms |
27740 KB |
n=2000 |
71 |
Correct |
7 ms |
27740 KB |
n=2000 |
72 |
Correct |
7 ms |
27736 KB |
n=2000 |
73 |
Correct |
8 ms |
27740 KB |
n=2000 |
74 |
Correct |
7 ms |
27740 KB |
n=1844 |
75 |
Correct |
7 ms |
27736 KB |
n=2000 |
76 |
Correct |
8 ms |
27740 KB |
n=2000 |
77 |
Correct |
8 ms |
27740 KB |
n=2000 |
78 |
Correct |
8 ms |
27740 KB |
n=2000 |
79 |
Correct |
8 ms |
27740 KB |
n=2000 |
80 |
Correct |
7 ms |
27908 KB |
n=2000 |
81 |
Correct |
7 ms |
27740 KB |
n=2000 |
82 |
Correct |
8 ms |
27740 KB |
n=2000 |
83 |
Correct |
7 ms |
27740 KB |
n=2000 |
84 |
Correct |
8 ms |
27740 KB |
n=2000 |
85 |
Correct |
8 ms |
27740 KB |
n=2000 |
86 |
Correct |
8 ms |
27792 KB |
n=2000 |
87 |
Correct |
8 ms |
27740 KB |
n=2000 |
88 |
Correct |
7 ms |
27740 KB |
n=2000 |
89 |
Correct |
7 ms |
27740 KB |
n=2000 |
90 |
Correct |
7 ms |
27740 KB |
n=2000 |
91 |
Correct |
7 ms |
27736 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
27484 KB |
n=5 |
2 |
Correct |
5 ms |
27360 KB |
n=100 |
3 |
Correct |
5 ms |
27484 KB |
n=100 |
4 |
Correct |
5 ms |
27484 KB |
n=100 |
5 |
Correct |
5 ms |
27484 KB |
n=100 |
6 |
Correct |
5 ms |
27484 KB |
n=100 |
7 |
Correct |
5 ms |
27484 KB |
n=100 |
8 |
Correct |
5 ms |
27484 KB |
n=100 |
9 |
Correct |
5 ms |
27480 KB |
n=100 |
10 |
Correct |
5 ms |
27484 KB |
n=100 |
11 |
Correct |
5 ms |
27484 KB |
n=100 |
12 |
Correct |
5 ms |
27484 KB |
n=100 |
13 |
Correct |
5 ms |
27484 KB |
n=100 |
14 |
Correct |
6 ms |
27484 KB |
n=100 |
15 |
Correct |
5 ms |
27484 KB |
n=100 |
16 |
Correct |
5 ms |
27484 KB |
n=100 |
17 |
Correct |
5 ms |
27484 KB |
n=100 |
18 |
Correct |
5 ms |
27548 KB |
n=100 |
19 |
Correct |
5 ms |
27484 KB |
n=100 |
20 |
Correct |
5 ms |
27484 KB |
n=100 |
21 |
Correct |
5 ms |
27484 KB |
n=100 |
22 |
Correct |
5 ms |
27484 KB |
n=100 |
23 |
Correct |
5 ms |
27552 KB |
n=100 |
24 |
Correct |
5 ms |
27480 KB |
n=100 |
25 |
Correct |
5 ms |
27484 KB |
n=100 |
26 |
Correct |
5 ms |
27480 KB |
n=12 |
27 |
Correct |
5 ms |
27736 KB |
n=100 |
28 |
Correct |
6 ms |
27484 KB |
n=500 |
29 |
Correct |
6 ms |
27576 KB |
n=500 |
30 |
Correct |
6 ms |
27484 KB |
n=500 |
31 |
Correct |
5 ms |
27480 KB |
n=500 |
32 |
Correct |
6 ms |
27484 KB |
n=500 |
33 |
Correct |
6 ms |
27484 KB |
n=500 |
34 |
Correct |
6 ms |
27652 KB |
n=500 |
35 |
Correct |
5 ms |
27484 KB |
n=500 |
36 |
Correct |
5 ms |
27484 KB |
n=500 |
37 |
Correct |
5 ms |
27484 KB |
n=500 |
38 |
Correct |
7 ms |
27484 KB |
n=500 |
39 |
Correct |
6 ms |
27484 KB |
n=500 |
40 |
Correct |
5 ms |
27568 KB |
n=500 |
41 |
Correct |
5 ms |
27548 KB |
n=500 |
42 |
Correct |
6 ms |
27480 KB |
n=500 |
43 |
Correct |
6 ms |
27480 KB |
n=500 |
44 |
Correct |
6 ms |
27484 KB |
n=500 |
45 |
Correct |
6 ms |
27648 KB |
n=500 |
46 |
Correct |
6 ms |
27484 KB |
n=500 |
47 |
Correct |
5 ms |
27484 KB |
n=500 |
48 |
Correct |
6 ms |
27480 KB |
n=500 |
49 |
Correct |
5 ms |
27484 KB |
n=500 |
50 |
Correct |
6 ms |
27484 KB |
n=500 |
51 |
Correct |
5 ms |
27484 KB |
n=500 |
52 |
Correct |
6 ms |
27612 KB |
n=500 |
53 |
Correct |
6 ms |
27484 KB |
n=500 |
54 |
Correct |
5 ms |
27480 KB |
n=500 |
55 |
Correct |
5 ms |
27484 KB |
n=278 |
56 |
Correct |
6 ms |
27484 KB |
n=500 |
57 |
Correct |
6 ms |
27480 KB |
n=500 |
58 |
Correct |
6 ms |
27736 KB |
n=500 |
59 |
Correct |
8 ms |
27736 KB |
n=2000 |
60 |
Correct |
7 ms |
27992 KB |
n=2000 |
61 |
Correct |
7 ms |
27740 KB |
n=2000 |
62 |
Correct |
7 ms |
27860 KB |
n=2000 |
63 |
Correct |
8 ms |
27788 KB |
n=2000 |
64 |
Correct |
7 ms |
27740 KB |
n=2000 |
65 |
Correct |
8 ms |
27844 KB |
n=2000 |
66 |
Correct |
7 ms |
27736 KB |
n=2000 |
67 |
Correct |
8 ms |
27636 KB |
n=2000 |
68 |
Correct |
7 ms |
27740 KB |
n=2000 |
69 |
Correct |
7 ms |
27736 KB |
n=2000 |
70 |
Correct |
7 ms |
27740 KB |
n=2000 |
71 |
Correct |
7 ms |
27740 KB |
n=2000 |
72 |
Correct |
7 ms |
27736 KB |
n=2000 |
73 |
Correct |
8 ms |
27740 KB |
n=2000 |
74 |
Correct |
7 ms |
27740 KB |
n=1844 |
75 |
Correct |
7 ms |
27736 KB |
n=2000 |
76 |
Correct |
8 ms |
27740 KB |
n=2000 |
77 |
Correct |
8 ms |
27740 KB |
n=2000 |
78 |
Correct |
8 ms |
27740 KB |
n=2000 |
79 |
Correct |
8 ms |
27740 KB |
n=2000 |
80 |
Correct |
7 ms |
27908 KB |
n=2000 |
81 |
Correct |
7 ms |
27740 KB |
n=2000 |
82 |
Correct |
8 ms |
27740 KB |
n=2000 |
83 |
Correct |
7 ms |
27740 KB |
n=2000 |
84 |
Correct |
8 ms |
27740 KB |
n=2000 |
85 |
Correct |
8 ms |
27740 KB |
n=2000 |
86 |
Correct |
8 ms |
27792 KB |
n=2000 |
87 |
Correct |
8 ms |
27740 KB |
n=2000 |
88 |
Correct |
7 ms |
27740 KB |
n=2000 |
89 |
Correct |
7 ms |
27740 KB |
n=2000 |
90 |
Correct |
7 ms |
27740 KB |
n=2000 |
91 |
Correct |
7 ms |
27736 KB |
n=2000 |
92 |
Correct |
512 ms |
68900 KB |
n=200000 |
93 |
Correct |
570 ms |
72556 KB |
n=200000 |
94 |
Correct |
383 ms |
76116 KB |
n=200000 |
95 |
Correct |
501 ms |
68776 KB |
n=200000 |
96 |
Correct |
483 ms |
68876 KB |
n=200000 |
97 |
Correct |
573 ms |
71828 KB |
n=200000 |
98 |
Correct |
500 ms |
69224 KB |
n=200000 |
99 |
Correct |
560 ms |
68508 KB |
n=200000 |
100 |
Correct |
502 ms |
68808 KB |
n=200000 |
101 |
Correct |
371 ms |
77308 KB |
n=200000 |
102 |
Correct |
299 ms |
69644 KB |
n=200000 |
103 |
Correct |
304 ms |
69736 KB |
n=200000 |
104 |
Correct |
290 ms |
69720 KB |
n=200000 |
105 |
Correct |
303 ms |
69548 KB |
n=200000 |
106 |
Correct |
305 ms |
69472 KB |
n=200000 |
107 |
Correct |
293 ms |
69472 KB |
n=200000 |
108 |
Correct |
512 ms |
68284 KB |
n=200000 |
109 |
Correct |
515 ms |
68332 KB |
n=200000 |
110 |
Correct |
506 ms |
68420 KB |
n=200000 |
111 |
Correct |
513 ms |
68644 KB |
n=200000 |
112 |
Correct |
354 ms |
76192 KB |
n=200000 |
113 |
Correct |
565 ms |
71832 KB |
n=200000 |
114 |
Correct |
511 ms |
68556 KB |
n=200000 |
115 |
Correct |
668 ms |
69652 KB |
n=200000 |
116 |
Correct |
490 ms |
68580 KB |
n=200000 |
117 |
Correct |
346 ms |
76552 KB |
n=200000 |
118 |
Correct |
626 ms |
70552 KB |
n=200000 |
119 |
Correct |
480 ms |
68452 KB |
n=200000 |
120 |
Correct |
320 ms |
76896 KB |
n=200000 |
121 |
Correct |
298 ms |
76880 KB |
n=200000 |
122 |
Correct |
302 ms |
77328 KB |
n=200000 |
123 |
Correct |
303 ms |
69204 KB |
n=200000 |
124 |
Correct |
85 ms |
40244 KB |
n=25264 |