#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = 200000;
const int MXLOG = 18;
int par[MAXN+5][MXLOG+1];
vector <int> graf[MAXN+5];
int in[MAXN+5];
int out[MAXN+5];
int tjm;
void dfs(int v, int p){
par[v][0] = p;
in[v] = ++tjm;
for(int j=1; j<=MXLOG; j++) par[v][j] = par[par[v][j-1]][j-1];
for(auto c : graf[v]) if(c != p) dfs(c, v);
out[v] = tjm;
}
int val[MAXN+5];
bool is_parent(int a, int b){
return (a == 0) || (in[a] <= in[b] && out[b] <= out[a]);
}
int lca(int a, int b){
if(is_parent(a, b)) return a;
for(int j=MXLOG; j>=0; j--){
if(!is_parent(par[a][j], b)) a = par[a][j];
}
return par[a][0];
}
set <int> p1[MAXN+5];
set <int> p2[MAXN+5];
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
int n, m, q;
cin >> n >> m >> q;
for(int i=1; i<n; i++){
int a, b;
cin >> a >> b;
graf[a].push_back(b);
graf[b].push_back(a);
}
dfs(1, 0);
for(int i=1; i<=m; i++){
cin >> val[i];
p1[val[i]].insert(i);
}
for(int i=2; i<=m; i++){
p2[lca(val[i-1], val[i])].insert(i);
}
while(q--){
int tp;
cin >> tp;
if(tp == 1){
int pos, v;
cin >> pos >> v;
p1[val[pos]].erase(pos);
if(pos > 1) p2[lca(val[pos], val[pos-1])].erase(pos);
if(pos < m) p2[lca(val[pos], val[pos+1])].erase(pos+1);
val[pos] = v;
p1[val[pos]].insert(pos);
if(pos > 1) p2[lca(val[pos], val[pos-1])].insert(pos);
if(pos < m) p2[lca(val[pos], val[pos+1])].insert(pos+1);
}
else{
int l, r, v;
cin >> l >> r >> v;
auto x = p1[v].lower_bound(l);
if(x != p1[v].end() && *x <= r){
cout << *x << " " << *x << "\n";
continue;
}
x = p2[v].lower_bound(l+1);
if(x != p2[v].end() && *x <= r){
cout << (*x)-1 << " " << *x << "\n";
continue;
}
cout << "-1 -1\n";
}
}
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 |
18 ms |
23732 KB |
n=5 |
2 |
Correct |
18 ms |
23756 KB |
n=100 |
3 |
Correct |
17 ms |
23820 KB |
n=100 |
4 |
Correct |
17 ms |
23852 KB |
n=100 |
5 |
Correct |
21 ms |
23800 KB |
n=100 |
6 |
Correct |
18 ms |
23756 KB |
n=100 |
7 |
Correct |
19 ms |
23756 KB |
n=100 |
8 |
Correct |
16 ms |
23756 KB |
n=100 |
9 |
Correct |
18 ms |
23836 KB |
n=100 |
10 |
Correct |
19 ms |
23820 KB |
n=100 |
11 |
Correct |
18 ms |
23856 KB |
n=100 |
12 |
Correct |
18 ms |
23756 KB |
n=100 |
13 |
Correct |
17 ms |
23820 KB |
n=100 |
14 |
Correct |
16 ms |
23756 KB |
n=100 |
15 |
Correct |
17 ms |
23852 KB |
n=100 |
16 |
Correct |
17 ms |
23756 KB |
n=100 |
17 |
Correct |
17 ms |
23780 KB |
n=100 |
18 |
Correct |
15 ms |
23756 KB |
n=100 |
19 |
Correct |
16 ms |
23756 KB |
n=100 |
20 |
Correct |
16 ms |
23764 KB |
n=100 |
21 |
Correct |
15 ms |
23756 KB |
n=100 |
22 |
Correct |
18 ms |
23756 KB |
n=100 |
23 |
Correct |
18 ms |
23728 KB |
n=100 |
24 |
Correct |
19 ms |
23812 KB |
n=100 |
25 |
Correct |
15 ms |
23756 KB |
n=100 |
26 |
Correct |
18 ms |
23776 KB |
n=12 |
27 |
Correct |
16 ms |
23812 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
23732 KB |
n=5 |
2 |
Correct |
18 ms |
23756 KB |
n=100 |
3 |
Correct |
17 ms |
23820 KB |
n=100 |
4 |
Correct |
17 ms |
23852 KB |
n=100 |
5 |
Correct |
21 ms |
23800 KB |
n=100 |
6 |
Correct |
18 ms |
23756 KB |
n=100 |
7 |
Correct |
19 ms |
23756 KB |
n=100 |
8 |
Correct |
16 ms |
23756 KB |
n=100 |
9 |
Correct |
18 ms |
23836 KB |
n=100 |
10 |
Correct |
19 ms |
23820 KB |
n=100 |
11 |
Correct |
18 ms |
23856 KB |
n=100 |
12 |
Correct |
18 ms |
23756 KB |
n=100 |
13 |
Correct |
17 ms |
23820 KB |
n=100 |
14 |
Correct |
16 ms |
23756 KB |
n=100 |
15 |
Correct |
17 ms |
23852 KB |
n=100 |
16 |
Correct |
17 ms |
23756 KB |
n=100 |
17 |
Correct |
17 ms |
23780 KB |
n=100 |
18 |
Correct |
15 ms |
23756 KB |
n=100 |
19 |
Correct |
16 ms |
23756 KB |
n=100 |
20 |
Correct |
16 ms |
23764 KB |
n=100 |
21 |
Correct |
15 ms |
23756 KB |
n=100 |
22 |
Correct |
18 ms |
23756 KB |
n=100 |
23 |
Correct |
18 ms |
23728 KB |
n=100 |
24 |
Correct |
19 ms |
23812 KB |
n=100 |
25 |
Correct |
15 ms |
23756 KB |
n=100 |
26 |
Correct |
18 ms |
23776 KB |
n=12 |
27 |
Correct |
16 ms |
23812 KB |
n=100 |
28 |
Correct |
16 ms |
23952 KB |
n=500 |
29 |
Correct |
20 ms |
23956 KB |
n=500 |
30 |
Correct |
18 ms |
23860 KB |
n=500 |
31 |
Correct |
20 ms |
23964 KB |
n=500 |
32 |
Correct |
17 ms |
23884 KB |
n=500 |
33 |
Correct |
19 ms |
23864 KB |
n=500 |
34 |
Correct |
17 ms |
23960 KB |
n=500 |
35 |
Correct |
19 ms |
23936 KB |
n=500 |
36 |
Correct |
17 ms |
23904 KB |
n=500 |
37 |
Correct |
20 ms |
23932 KB |
n=500 |
38 |
Correct |
17 ms |
23816 KB |
n=500 |
39 |
Correct |
19 ms |
23948 KB |
n=500 |
40 |
Correct |
18 ms |
23944 KB |
n=500 |
41 |
Correct |
19 ms |
23912 KB |
n=500 |
42 |
Correct |
18 ms |
23884 KB |
n=500 |
43 |
Correct |
20 ms |
23960 KB |
n=500 |
44 |
Correct |
18 ms |
23956 KB |
n=500 |
45 |
Correct |
16 ms |
23884 KB |
n=500 |
46 |
Correct |
18 ms |
23884 KB |
n=500 |
47 |
Correct |
18 ms |
23884 KB |
n=500 |
48 |
Correct |
19 ms |
23884 KB |
n=500 |
49 |
Correct |
18 ms |
23912 KB |
n=500 |
50 |
Correct |
19 ms |
23860 KB |
n=500 |
51 |
Correct |
19 ms |
23884 KB |
n=500 |
52 |
Correct |
20 ms |
23884 KB |
n=500 |
53 |
Correct |
18 ms |
23884 KB |
n=500 |
54 |
Correct |
18 ms |
23884 KB |
n=500 |
55 |
Correct |
16 ms |
23824 KB |
n=278 |
56 |
Correct |
17 ms |
23940 KB |
n=500 |
57 |
Correct |
16 ms |
23968 KB |
n=500 |
58 |
Correct |
17 ms |
23884 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
23732 KB |
n=5 |
2 |
Correct |
18 ms |
23756 KB |
n=100 |
3 |
Correct |
17 ms |
23820 KB |
n=100 |
4 |
Correct |
17 ms |
23852 KB |
n=100 |
5 |
Correct |
21 ms |
23800 KB |
n=100 |
6 |
Correct |
18 ms |
23756 KB |
n=100 |
7 |
Correct |
19 ms |
23756 KB |
n=100 |
8 |
Correct |
16 ms |
23756 KB |
n=100 |
9 |
Correct |
18 ms |
23836 KB |
n=100 |
10 |
Correct |
19 ms |
23820 KB |
n=100 |
11 |
Correct |
18 ms |
23856 KB |
n=100 |
12 |
Correct |
18 ms |
23756 KB |
n=100 |
13 |
Correct |
17 ms |
23820 KB |
n=100 |
14 |
Correct |
16 ms |
23756 KB |
n=100 |
15 |
Correct |
17 ms |
23852 KB |
n=100 |
16 |
Correct |
17 ms |
23756 KB |
n=100 |
17 |
Correct |
17 ms |
23780 KB |
n=100 |
18 |
Correct |
15 ms |
23756 KB |
n=100 |
19 |
Correct |
16 ms |
23756 KB |
n=100 |
20 |
Correct |
16 ms |
23764 KB |
n=100 |
21 |
Correct |
15 ms |
23756 KB |
n=100 |
22 |
Correct |
18 ms |
23756 KB |
n=100 |
23 |
Correct |
18 ms |
23728 KB |
n=100 |
24 |
Correct |
19 ms |
23812 KB |
n=100 |
25 |
Correct |
15 ms |
23756 KB |
n=100 |
26 |
Correct |
18 ms |
23776 KB |
n=12 |
27 |
Correct |
16 ms |
23812 KB |
n=100 |
28 |
Correct |
16 ms |
23952 KB |
n=500 |
29 |
Correct |
20 ms |
23956 KB |
n=500 |
30 |
Correct |
18 ms |
23860 KB |
n=500 |
31 |
Correct |
20 ms |
23964 KB |
n=500 |
32 |
Correct |
17 ms |
23884 KB |
n=500 |
33 |
Correct |
19 ms |
23864 KB |
n=500 |
34 |
Correct |
17 ms |
23960 KB |
n=500 |
35 |
Correct |
19 ms |
23936 KB |
n=500 |
36 |
Correct |
17 ms |
23904 KB |
n=500 |
37 |
Correct |
20 ms |
23932 KB |
n=500 |
38 |
Correct |
17 ms |
23816 KB |
n=500 |
39 |
Correct |
19 ms |
23948 KB |
n=500 |
40 |
Correct |
18 ms |
23944 KB |
n=500 |
41 |
Correct |
19 ms |
23912 KB |
n=500 |
42 |
Correct |
18 ms |
23884 KB |
n=500 |
43 |
Correct |
20 ms |
23960 KB |
n=500 |
44 |
Correct |
18 ms |
23956 KB |
n=500 |
45 |
Correct |
16 ms |
23884 KB |
n=500 |
46 |
Correct |
18 ms |
23884 KB |
n=500 |
47 |
Correct |
18 ms |
23884 KB |
n=500 |
48 |
Correct |
19 ms |
23884 KB |
n=500 |
49 |
Correct |
18 ms |
23912 KB |
n=500 |
50 |
Correct |
19 ms |
23860 KB |
n=500 |
51 |
Correct |
19 ms |
23884 KB |
n=500 |
52 |
Correct |
20 ms |
23884 KB |
n=500 |
53 |
Correct |
18 ms |
23884 KB |
n=500 |
54 |
Correct |
18 ms |
23884 KB |
n=500 |
55 |
Correct |
16 ms |
23824 KB |
n=278 |
56 |
Correct |
17 ms |
23940 KB |
n=500 |
57 |
Correct |
16 ms |
23968 KB |
n=500 |
58 |
Correct |
17 ms |
23884 KB |
n=500 |
59 |
Correct |
21 ms |
24200 KB |
n=2000 |
60 |
Correct |
24 ms |
24288 KB |
n=2000 |
61 |
Correct |
25 ms |
24268 KB |
n=2000 |
62 |
Correct |
21 ms |
24268 KB |
n=2000 |
63 |
Correct |
19 ms |
24228 KB |
n=2000 |
64 |
Correct |
21 ms |
24344 KB |
n=2000 |
65 |
Correct |
24 ms |
24304 KB |
n=2000 |
66 |
Correct |
23 ms |
24268 KB |
n=2000 |
67 |
Correct |
24 ms |
24260 KB |
n=2000 |
68 |
Correct |
20 ms |
24344 KB |
n=2000 |
69 |
Correct |
18 ms |
24236 KB |
n=2000 |
70 |
Correct |
19 ms |
24280 KB |
n=2000 |
71 |
Correct |
21 ms |
24268 KB |
n=2000 |
72 |
Correct |
22 ms |
24260 KB |
n=2000 |
73 |
Correct |
22 ms |
24236 KB |
n=2000 |
74 |
Correct |
24 ms |
24224 KB |
n=1844 |
75 |
Correct |
21 ms |
24204 KB |
n=2000 |
76 |
Correct |
21 ms |
24348 KB |
n=2000 |
77 |
Correct |
19 ms |
24268 KB |
n=2000 |
78 |
Correct |
23 ms |
24260 KB |
n=2000 |
79 |
Correct |
20 ms |
24284 KB |
n=2000 |
80 |
Correct |
19 ms |
24268 KB |
n=2000 |
81 |
Correct |
19 ms |
24268 KB |
n=2000 |
82 |
Correct |
17 ms |
24308 KB |
n=2000 |
83 |
Correct |
25 ms |
24372 KB |
n=2000 |
84 |
Correct |
17 ms |
24284 KB |
n=2000 |
85 |
Correct |
18 ms |
24332 KB |
n=2000 |
86 |
Correct |
18 ms |
24332 KB |
n=2000 |
87 |
Correct |
20 ms |
24268 KB |
n=2000 |
88 |
Correct |
17 ms |
24344 KB |
n=2000 |
89 |
Correct |
18 ms |
24344 KB |
n=2000 |
90 |
Correct |
17 ms |
24344 KB |
n=2000 |
91 |
Correct |
21 ms |
24268 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
23732 KB |
n=5 |
2 |
Correct |
18 ms |
23756 KB |
n=100 |
3 |
Correct |
17 ms |
23820 KB |
n=100 |
4 |
Correct |
17 ms |
23852 KB |
n=100 |
5 |
Correct |
21 ms |
23800 KB |
n=100 |
6 |
Correct |
18 ms |
23756 KB |
n=100 |
7 |
Correct |
19 ms |
23756 KB |
n=100 |
8 |
Correct |
16 ms |
23756 KB |
n=100 |
9 |
Correct |
18 ms |
23836 KB |
n=100 |
10 |
Correct |
19 ms |
23820 KB |
n=100 |
11 |
Correct |
18 ms |
23856 KB |
n=100 |
12 |
Correct |
18 ms |
23756 KB |
n=100 |
13 |
Correct |
17 ms |
23820 KB |
n=100 |
14 |
Correct |
16 ms |
23756 KB |
n=100 |
15 |
Correct |
17 ms |
23852 KB |
n=100 |
16 |
Correct |
17 ms |
23756 KB |
n=100 |
17 |
Correct |
17 ms |
23780 KB |
n=100 |
18 |
Correct |
15 ms |
23756 KB |
n=100 |
19 |
Correct |
16 ms |
23756 KB |
n=100 |
20 |
Correct |
16 ms |
23764 KB |
n=100 |
21 |
Correct |
15 ms |
23756 KB |
n=100 |
22 |
Correct |
18 ms |
23756 KB |
n=100 |
23 |
Correct |
18 ms |
23728 KB |
n=100 |
24 |
Correct |
19 ms |
23812 KB |
n=100 |
25 |
Correct |
15 ms |
23756 KB |
n=100 |
26 |
Correct |
18 ms |
23776 KB |
n=12 |
27 |
Correct |
16 ms |
23812 KB |
n=100 |
28 |
Correct |
16 ms |
23952 KB |
n=500 |
29 |
Correct |
20 ms |
23956 KB |
n=500 |
30 |
Correct |
18 ms |
23860 KB |
n=500 |
31 |
Correct |
20 ms |
23964 KB |
n=500 |
32 |
Correct |
17 ms |
23884 KB |
n=500 |
33 |
Correct |
19 ms |
23864 KB |
n=500 |
34 |
Correct |
17 ms |
23960 KB |
n=500 |
35 |
Correct |
19 ms |
23936 KB |
n=500 |
36 |
Correct |
17 ms |
23904 KB |
n=500 |
37 |
Correct |
20 ms |
23932 KB |
n=500 |
38 |
Correct |
17 ms |
23816 KB |
n=500 |
39 |
Correct |
19 ms |
23948 KB |
n=500 |
40 |
Correct |
18 ms |
23944 KB |
n=500 |
41 |
Correct |
19 ms |
23912 KB |
n=500 |
42 |
Correct |
18 ms |
23884 KB |
n=500 |
43 |
Correct |
20 ms |
23960 KB |
n=500 |
44 |
Correct |
18 ms |
23956 KB |
n=500 |
45 |
Correct |
16 ms |
23884 KB |
n=500 |
46 |
Correct |
18 ms |
23884 KB |
n=500 |
47 |
Correct |
18 ms |
23884 KB |
n=500 |
48 |
Correct |
19 ms |
23884 KB |
n=500 |
49 |
Correct |
18 ms |
23912 KB |
n=500 |
50 |
Correct |
19 ms |
23860 KB |
n=500 |
51 |
Correct |
19 ms |
23884 KB |
n=500 |
52 |
Correct |
20 ms |
23884 KB |
n=500 |
53 |
Correct |
18 ms |
23884 KB |
n=500 |
54 |
Correct |
18 ms |
23884 KB |
n=500 |
55 |
Correct |
16 ms |
23824 KB |
n=278 |
56 |
Correct |
17 ms |
23940 KB |
n=500 |
57 |
Correct |
16 ms |
23968 KB |
n=500 |
58 |
Correct |
17 ms |
23884 KB |
n=500 |
59 |
Correct |
21 ms |
24200 KB |
n=2000 |
60 |
Correct |
24 ms |
24288 KB |
n=2000 |
61 |
Correct |
25 ms |
24268 KB |
n=2000 |
62 |
Correct |
21 ms |
24268 KB |
n=2000 |
63 |
Correct |
19 ms |
24228 KB |
n=2000 |
64 |
Correct |
21 ms |
24344 KB |
n=2000 |
65 |
Correct |
24 ms |
24304 KB |
n=2000 |
66 |
Correct |
23 ms |
24268 KB |
n=2000 |
67 |
Correct |
24 ms |
24260 KB |
n=2000 |
68 |
Correct |
20 ms |
24344 KB |
n=2000 |
69 |
Correct |
18 ms |
24236 KB |
n=2000 |
70 |
Correct |
19 ms |
24280 KB |
n=2000 |
71 |
Correct |
21 ms |
24268 KB |
n=2000 |
72 |
Correct |
22 ms |
24260 KB |
n=2000 |
73 |
Correct |
22 ms |
24236 KB |
n=2000 |
74 |
Correct |
24 ms |
24224 KB |
n=1844 |
75 |
Correct |
21 ms |
24204 KB |
n=2000 |
76 |
Correct |
21 ms |
24348 KB |
n=2000 |
77 |
Correct |
19 ms |
24268 KB |
n=2000 |
78 |
Correct |
23 ms |
24260 KB |
n=2000 |
79 |
Correct |
20 ms |
24284 KB |
n=2000 |
80 |
Correct |
19 ms |
24268 KB |
n=2000 |
81 |
Correct |
19 ms |
24268 KB |
n=2000 |
82 |
Correct |
17 ms |
24308 KB |
n=2000 |
83 |
Correct |
25 ms |
24372 KB |
n=2000 |
84 |
Correct |
17 ms |
24284 KB |
n=2000 |
85 |
Correct |
18 ms |
24332 KB |
n=2000 |
86 |
Correct |
18 ms |
24332 KB |
n=2000 |
87 |
Correct |
20 ms |
24268 KB |
n=2000 |
88 |
Correct |
17 ms |
24344 KB |
n=2000 |
89 |
Correct |
18 ms |
24344 KB |
n=2000 |
90 |
Correct |
17 ms |
24344 KB |
n=2000 |
91 |
Correct |
21 ms |
24268 KB |
n=2000 |
92 |
Correct |
983 ms |
74560 KB |
n=200000 |
93 |
Correct |
1528 ms |
79352 KB |
n=200000 |
94 |
Correct |
1319 ms |
82840 KB |
n=200000 |
95 |
Correct |
959 ms |
74428 KB |
n=200000 |
96 |
Correct |
855 ms |
74432 KB |
n=200000 |
97 |
Correct |
1406 ms |
78556 KB |
n=200000 |
98 |
Correct |
909 ms |
74316 KB |
n=200000 |
99 |
Correct |
1153 ms |
74580 KB |
n=200000 |
100 |
Correct |
908 ms |
74460 KB |
n=200000 |
101 |
Correct |
1339 ms |
84016 KB |
n=200000 |
102 |
Correct |
576 ms |
75536 KB |
n=200000 |
103 |
Correct |
577 ms |
75524 KB |
n=200000 |
104 |
Correct |
576 ms |
75568 KB |
n=200000 |
105 |
Correct |
594 ms |
76060 KB |
n=200000 |
106 |
Correct |
568 ms |
75880 KB |
n=200000 |
107 |
Correct |
593 ms |
75988 KB |
n=200000 |
108 |
Correct |
1157 ms |
74444 KB |
n=200000 |
109 |
Correct |
1109 ms |
74340 KB |
n=200000 |
110 |
Correct |
1116 ms |
74420 KB |
n=200000 |
111 |
Correct |
842 ms |
73792 KB |
n=200000 |
112 |
Correct |
1227 ms |
82972 KB |
n=200000 |
113 |
Correct |
1334 ms |
78484 KB |
n=200000 |
114 |
Correct |
927 ms |
73876 KB |
n=200000 |
115 |
Correct |
1478 ms |
76408 KB |
n=200000 |
116 |
Correct |
823 ms |
74452 KB |
n=200000 |
117 |
Correct |
1189 ms |
83404 KB |
n=200000 |
118 |
Correct |
1369 ms |
77368 KB |
n=200000 |
119 |
Correct |
832 ms |
74528 KB |
n=200000 |
120 |
Correct |
1156 ms |
82912 KB |
n=200000 |
121 |
Correct |
1188 ms |
82936 KB |
n=200000 |
122 |
Correct |
1073 ms |
83236 KB |
n=200000 |
123 |
Correct |
595 ms |
75692 KB |
n=200000 |
124 |
Correct |
285 ms |
38592 KB |
n=25264 |