#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define mp make_pair
#define ff first
#define ss second
#define pii pair < int, int >
const int maxn = (int) 1e5 + 10;
using namespace std;
int par[20][200200], lift[200200];
vector<int> adj[200200];
int n, m, q;
void dfs(int u, int p){
par[0][u] = p;
for(int i = 1; i < 19; i++) par[i][u] = par[i - 1][par[i - 1][u]];
lift[u] = lift[p] + 1;
for(auto v : adj[u]) if(v != p) dfs(v, u);
}
int a[200200];
set<int> S[200200];
set<int> T[200200];
int lca(int u, int v){
if(lift[u] < lift[v]) swap(u, v);
for(int i = 18; i > -1; i--) if(lift[u] - (1 << i) >= lift[v]) u = par[i][u];
if(u == v) return u;
for(int i = 18; i > -1; i--){
if(par[i][u] != par[i][v]) {
u = par[i][u];
v = par[i][v];
}
}
return par[0][v];
}
int main(){
cin >> n >> m >> q;
for(int i = 1, x, y; i < n; i++){
cin >> x >> y;
adj[x].pb(y);
adj[y].pb(x);
}
for(int i = 1; i < m + 1; i++) cin >> a[i];
dfs(1, 0);
for(int i = 1; i < m + 1; i++) S[a[i]].insert(i);
for(int i = 2; i < m + 1; i++) T[lca(a[i], a[i - 1])].insert(i);
for(int i = 1; i < n + 1; i++) {
S[i].insert(INT_MAX);
T[i].insert(INT_MAX);
}
while(q--){
int op, l, r, v; cin >> op;
if(op == 1){
cin >> l >> v;
S[a[l]].erase(l);
if(l > 1) T[lca(a[l], a[l - 1])].erase(l);
if(l < m) T[lca(a[l], a[l + 1])].erase(l + 1);
a[l] = v;
S[a[l]].insert(l);
if(l > 1) T[lca(a[l], a[l-1])].insert(l);
if(l < m) T[lca(a[l], a[l+1])].insert(l + 1);
}else{
cin >> l >> r >> v;
int d = *S[v].lower_bound(l), e = *T[v].lower_bound(l+1);
if(d <= r) cout << d << ' ' << d << '\n';
else if(e <= r) cout << e - 1 << ' ' << e << '\n';
else cout << "-1 -1\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
39516 KB |
n=5 |
2 |
Correct |
7 ms |
39516 KB |
n=100 |
3 |
Correct |
7 ms |
39516 KB |
n=100 |
4 |
Correct |
7 ms |
39516 KB |
n=100 |
5 |
Correct |
7 ms |
39516 KB |
n=100 |
6 |
Correct |
7 ms |
39768 KB |
n=100 |
7 |
Correct |
7 ms |
39516 KB |
n=100 |
8 |
Correct |
7 ms |
39564 KB |
n=100 |
9 |
Correct |
7 ms |
39560 KB |
n=100 |
10 |
Correct |
7 ms |
39516 KB |
n=100 |
11 |
Correct |
8 ms |
39512 KB |
n=100 |
12 |
Correct |
7 ms |
39516 KB |
n=100 |
13 |
Correct |
7 ms |
39516 KB |
n=100 |
14 |
Correct |
7 ms |
39516 KB |
n=100 |
15 |
Correct |
7 ms |
39516 KB |
n=100 |
16 |
Correct |
7 ms |
39516 KB |
n=100 |
17 |
Correct |
8 ms |
39768 KB |
n=100 |
18 |
Correct |
7 ms |
39516 KB |
n=100 |
19 |
Correct |
7 ms |
39512 KB |
n=100 |
20 |
Correct |
7 ms |
39512 KB |
n=100 |
21 |
Correct |
8 ms |
39512 KB |
n=100 |
22 |
Correct |
7 ms |
39516 KB |
n=100 |
23 |
Correct |
7 ms |
39516 KB |
n=100 |
24 |
Correct |
7 ms |
39516 KB |
n=100 |
25 |
Correct |
7 ms |
39516 KB |
n=100 |
26 |
Correct |
7 ms |
39380 KB |
n=12 |
27 |
Correct |
7 ms |
39512 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
39516 KB |
n=5 |
2 |
Correct |
7 ms |
39516 KB |
n=100 |
3 |
Correct |
7 ms |
39516 KB |
n=100 |
4 |
Correct |
7 ms |
39516 KB |
n=100 |
5 |
Correct |
7 ms |
39516 KB |
n=100 |
6 |
Correct |
7 ms |
39768 KB |
n=100 |
7 |
Correct |
7 ms |
39516 KB |
n=100 |
8 |
Correct |
7 ms |
39564 KB |
n=100 |
9 |
Correct |
7 ms |
39560 KB |
n=100 |
10 |
Correct |
7 ms |
39516 KB |
n=100 |
11 |
Correct |
8 ms |
39512 KB |
n=100 |
12 |
Correct |
7 ms |
39516 KB |
n=100 |
13 |
Correct |
7 ms |
39516 KB |
n=100 |
14 |
Correct |
7 ms |
39516 KB |
n=100 |
15 |
Correct |
7 ms |
39516 KB |
n=100 |
16 |
Correct |
7 ms |
39516 KB |
n=100 |
17 |
Correct |
8 ms |
39768 KB |
n=100 |
18 |
Correct |
7 ms |
39516 KB |
n=100 |
19 |
Correct |
7 ms |
39512 KB |
n=100 |
20 |
Correct |
7 ms |
39512 KB |
n=100 |
21 |
Correct |
8 ms |
39512 KB |
n=100 |
22 |
Correct |
7 ms |
39516 KB |
n=100 |
23 |
Correct |
7 ms |
39516 KB |
n=100 |
24 |
Correct |
7 ms |
39516 KB |
n=100 |
25 |
Correct |
7 ms |
39516 KB |
n=100 |
26 |
Correct |
7 ms |
39380 KB |
n=12 |
27 |
Correct |
7 ms |
39512 KB |
n=100 |
28 |
Correct |
8 ms |
39516 KB |
n=500 |
29 |
Correct |
8 ms |
39516 KB |
n=500 |
30 |
Correct |
8 ms |
39516 KB |
n=500 |
31 |
Correct |
8 ms |
39512 KB |
n=500 |
32 |
Correct |
8 ms |
39512 KB |
n=500 |
33 |
Correct |
8 ms |
39516 KB |
n=500 |
34 |
Correct |
8 ms |
39516 KB |
n=500 |
35 |
Correct |
8 ms |
39516 KB |
n=500 |
36 |
Correct |
9 ms |
39516 KB |
n=500 |
37 |
Correct |
8 ms |
39516 KB |
n=500 |
38 |
Correct |
9 ms |
39512 KB |
n=500 |
39 |
Correct |
8 ms |
39768 KB |
n=500 |
40 |
Correct |
8 ms |
39516 KB |
n=500 |
41 |
Correct |
8 ms |
39512 KB |
n=500 |
42 |
Correct |
9 ms |
39516 KB |
n=500 |
43 |
Correct |
8 ms |
39516 KB |
n=500 |
44 |
Correct |
8 ms |
39516 KB |
n=500 |
45 |
Correct |
8 ms |
39516 KB |
n=500 |
46 |
Correct |
9 ms |
39512 KB |
n=500 |
47 |
Correct |
8 ms |
39516 KB |
n=500 |
48 |
Correct |
8 ms |
39516 KB |
n=500 |
49 |
Correct |
8 ms |
39516 KB |
n=500 |
50 |
Correct |
8 ms |
39516 KB |
n=500 |
51 |
Correct |
8 ms |
39512 KB |
n=500 |
52 |
Correct |
8 ms |
39516 KB |
n=500 |
53 |
Correct |
8 ms |
39516 KB |
n=500 |
54 |
Correct |
8 ms |
39516 KB |
n=500 |
55 |
Correct |
7 ms |
39512 KB |
n=278 |
56 |
Correct |
8 ms |
39516 KB |
n=500 |
57 |
Correct |
8 ms |
39516 KB |
n=500 |
58 |
Correct |
9 ms |
39516 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
39516 KB |
n=5 |
2 |
Correct |
7 ms |
39516 KB |
n=100 |
3 |
Correct |
7 ms |
39516 KB |
n=100 |
4 |
Correct |
7 ms |
39516 KB |
n=100 |
5 |
Correct |
7 ms |
39516 KB |
n=100 |
6 |
Correct |
7 ms |
39768 KB |
n=100 |
7 |
Correct |
7 ms |
39516 KB |
n=100 |
8 |
Correct |
7 ms |
39564 KB |
n=100 |
9 |
Correct |
7 ms |
39560 KB |
n=100 |
10 |
Correct |
7 ms |
39516 KB |
n=100 |
11 |
Correct |
8 ms |
39512 KB |
n=100 |
12 |
Correct |
7 ms |
39516 KB |
n=100 |
13 |
Correct |
7 ms |
39516 KB |
n=100 |
14 |
Correct |
7 ms |
39516 KB |
n=100 |
15 |
Correct |
7 ms |
39516 KB |
n=100 |
16 |
Correct |
7 ms |
39516 KB |
n=100 |
17 |
Correct |
8 ms |
39768 KB |
n=100 |
18 |
Correct |
7 ms |
39516 KB |
n=100 |
19 |
Correct |
7 ms |
39512 KB |
n=100 |
20 |
Correct |
7 ms |
39512 KB |
n=100 |
21 |
Correct |
8 ms |
39512 KB |
n=100 |
22 |
Correct |
7 ms |
39516 KB |
n=100 |
23 |
Correct |
7 ms |
39516 KB |
n=100 |
24 |
Correct |
7 ms |
39516 KB |
n=100 |
25 |
Correct |
7 ms |
39516 KB |
n=100 |
26 |
Correct |
7 ms |
39380 KB |
n=12 |
27 |
Correct |
7 ms |
39512 KB |
n=100 |
28 |
Correct |
8 ms |
39516 KB |
n=500 |
29 |
Correct |
8 ms |
39516 KB |
n=500 |
30 |
Correct |
8 ms |
39516 KB |
n=500 |
31 |
Correct |
8 ms |
39512 KB |
n=500 |
32 |
Correct |
8 ms |
39512 KB |
n=500 |
33 |
Correct |
8 ms |
39516 KB |
n=500 |
34 |
Correct |
8 ms |
39516 KB |
n=500 |
35 |
Correct |
8 ms |
39516 KB |
n=500 |
36 |
Correct |
9 ms |
39516 KB |
n=500 |
37 |
Correct |
8 ms |
39516 KB |
n=500 |
38 |
Correct |
9 ms |
39512 KB |
n=500 |
39 |
Correct |
8 ms |
39768 KB |
n=500 |
40 |
Correct |
8 ms |
39516 KB |
n=500 |
41 |
Correct |
8 ms |
39512 KB |
n=500 |
42 |
Correct |
9 ms |
39516 KB |
n=500 |
43 |
Correct |
8 ms |
39516 KB |
n=500 |
44 |
Correct |
8 ms |
39516 KB |
n=500 |
45 |
Correct |
8 ms |
39516 KB |
n=500 |
46 |
Correct |
9 ms |
39512 KB |
n=500 |
47 |
Correct |
8 ms |
39516 KB |
n=500 |
48 |
Correct |
8 ms |
39516 KB |
n=500 |
49 |
Correct |
8 ms |
39516 KB |
n=500 |
50 |
Correct |
8 ms |
39516 KB |
n=500 |
51 |
Correct |
8 ms |
39512 KB |
n=500 |
52 |
Correct |
8 ms |
39516 KB |
n=500 |
53 |
Correct |
8 ms |
39516 KB |
n=500 |
54 |
Correct |
8 ms |
39516 KB |
n=500 |
55 |
Correct |
7 ms |
39512 KB |
n=278 |
56 |
Correct |
8 ms |
39516 KB |
n=500 |
57 |
Correct |
8 ms |
39516 KB |
n=500 |
58 |
Correct |
9 ms |
39516 KB |
n=500 |
59 |
Correct |
13 ms |
40024 KB |
n=2000 |
60 |
Correct |
14 ms |
40024 KB |
n=2000 |
61 |
Correct |
14 ms |
40028 KB |
n=2000 |
62 |
Correct |
12 ms |
40028 KB |
n=2000 |
63 |
Correct |
12 ms |
40028 KB |
n=2000 |
64 |
Correct |
12 ms |
40028 KB |
n=2000 |
65 |
Correct |
11 ms |
40028 KB |
n=2000 |
66 |
Correct |
12 ms |
40028 KB |
n=2000 |
67 |
Correct |
14 ms |
40028 KB |
n=2000 |
68 |
Correct |
12 ms |
40028 KB |
n=2000 |
69 |
Correct |
12 ms |
39896 KB |
n=2000 |
70 |
Correct |
12 ms |
40024 KB |
n=2000 |
71 |
Correct |
12 ms |
40024 KB |
n=2000 |
72 |
Correct |
12 ms |
40024 KB |
n=2000 |
73 |
Correct |
12 ms |
40028 KB |
n=2000 |
74 |
Correct |
11 ms |
40024 KB |
n=1844 |
75 |
Correct |
12 ms |
40024 KB |
n=2000 |
76 |
Correct |
12 ms |
40028 KB |
n=2000 |
77 |
Correct |
12 ms |
40028 KB |
n=2000 |
78 |
Correct |
12 ms |
40028 KB |
n=2000 |
79 |
Correct |
11 ms |
40028 KB |
n=2000 |
80 |
Correct |
12 ms |
40028 KB |
n=2000 |
81 |
Correct |
12 ms |
40028 KB |
n=2000 |
82 |
Correct |
12 ms |
40024 KB |
n=2000 |
83 |
Correct |
12 ms |
40028 KB |
n=2000 |
84 |
Correct |
13 ms |
40072 KB |
n=2000 |
85 |
Correct |
12 ms |
40028 KB |
n=2000 |
86 |
Correct |
12 ms |
40028 KB |
n=2000 |
87 |
Correct |
12 ms |
40028 KB |
n=2000 |
88 |
Correct |
12 ms |
40024 KB |
n=2000 |
89 |
Correct |
12 ms |
39912 KB |
n=2000 |
90 |
Correct |
12 ms |
40028 KB |
n=2000 |
91 |
Correct |
12 ms |
40064 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
39516 KB |
n=5 |
2 |
Correct |
7 ms |
39516 KB |
n=100 |
3 |
Correct |
7 ms |
39516 KB |
n=100 |
4 |
Correct |
7 ms |
39516 KB |
n=100 |
5 |
Correct |
7 ms |
39516 KB |
n=100 |
6 |
Correct |
7 ms |
39768 KB |
n=100 |
7 |
Correct |
7 ms |
39516 KB |
n=100 |
8 |
Correct |
7 ms |
39564 KB |
n=100 |
9 |
Correct |
7 ms |
39560 KB |
n=100 |
10 |
Correct |
7 ms |
39516 KB |
n=100 |
11 |
Correct |
8 ms |
39512 KB |
n=100 |
12 |
Correct |
7 ms |
39516 KB |
n=100 |
13 |
Correct |
7 ms |
39516 KB |
n=100 |
14 |
Correct |
7 ms |
39516 KB |
n=100 |
15 |
Correct |
7 ms |
39516 KB |
n=100 |
16 |
Correct |
7 ms |
39516 KB |
n=100 |
17 |
Correct |
8 ms |
39768 KB |
n=100 |
18 |
Correct |
7 ms |
39516 KB |
n=100 |
19 |
Correct |
7 ms |
39512 KB |
n=100 |
20 |
Correct |
7 ms |
39512 KB |
n=100 |
21 |
Correct |
8 ms |
39512 KB |
n=100 |
22 |
Correct |
7 ms |
39516 KB |
n=100 |
23 |
Correct |
7 ms |
39516 KB |
n=100 |
24 |
Correct |
7 ms |
39516 KB |
n=100 |
25 |
Correct |
7 ms |
39516 KB |
n=100 |
26 |
Correct |
7 ms |
39380 KB |
n=12 |
27 |
Correct |
7 ms |
39512 KB |
n=100 |
28 |
Correct |
8 ms |
39516 KB |
n=500 |
29 |
Correct |
8 ms |
39516 KB |
n=500 |
30 |
Correct |
8 ms |
39516 KB |
n=500 |
31 |
Correct |
8 ms |
39512 KB |
n=500 |
32 |
Correct |
8 ms |
39512 KB |
n=500 |
33 |
Correct |
8 ms |
39516 KB |
n=500 |
34 |
Correct |
8 ms |
39516 KB |
n=500 |
35 |
Correct |
8 ms |
39516 KB |
n=500 |
36 |
Correct |
9 ms |
39516 KB |
n=500 |
37 |
Correct |
8 ms |
39516 KB |
n=500 |
38 |
Correct |
9 ms |
39512 KB |
n=500 |
39 |
Correct |
8 ms |
39768 KB |
n=500 |
40 |
Correct |
8 ms |
39516 KB |
n=500 |
41 |
Correct |
8 ms |
39512 KB |
n=500 |
42 |
Correct |
9 ms |
39516 KB |
n=500 |
43 |
Correct |
8 ms |
39516 KB |
n=500 |
44 |
Correct |
8 ms |
39516 KB |
n=500 |
45 |
Correct |
8 ms |
39516 KB |
n=500 |
46 |
Correct |
9 ms |
39512 KB |
n=500 |
47 |
Correct |
8 ms |
39516 KB |
n=500 |
48 |
Correct |
8 ms |
39516 KB |
n=500 |
49 |
Correct |
8 ms |
39516 KB |
n=500 |
50 |
Correct |
8 ms |
39516 KB |
n=500 |
51 |
Correct |
8 ms |
39512 KB |
n=500 |
52 |
Correct |
8 ms |
39516 KB |
n=500 |
53 |
Correct |
8 ms |
39516 KB |
n=500 |
54 |
Correct |
8 ms |
39516 KB |
n=500 |
55 |
Correct |
7 ms |
39512 KB |
n=278 |
56 |
Correct |
8 ms |
39516 KB |
n=500 |
57 |
Correct |
8 ms |
39516 KB |
n=500 |
58 |
Correct |
9 ms |
39516 KB |
n=500 |
59 |
Correct |
13 ms |
40024 KB |
n=2000 |
60 |
Correct |
14 ms |
40024 KB |
n=2000 |
61 |
Correct |
14 ms |
40028 KB |
n=2000 |
62 |
Correct |
12 ms |
40028 KB |
n=2000 |
63 |
Correct |
12 ms |
40028 KB |
n=2000 |
64 |
Correct |
12 ms |
40028 KB |
n=2000 |
65 |
Correct |
11 ms |
40028 KB |
n=2000 |
66 |
Correct |
12 ms |
40028 KB |
n=2000 |
67 |
Correct |
14 ms |
40028 KB |
n=2000 |
68 |
Correct |
12 ms |
40028 KB |
n=2000 |
69 |
Correct |
12 ms |
39896 KB |
n=2000 |
70 |
Correct |
12 ms |
40024 KB |
n=2000 |
71 |
Correct |
12 ms |
40024 KB |
n=2000 |
72 |
Correct |
12 ms |
40024 KB |
n=2000 |
73 |
Correct |
12 ms |
40028 KB |
n=2000 |
74 |
Correct |
11 ms |
40024 KB |
n=1844 |
75 |
Correct |
12 ms |
40024 KB |
n=2000 |
76 |
Correct |
12 ms |
40028 KB |
n=2000 |
77 |
Correct |
12 ms |
40028 KB |
n=2000 |
78 |
Correct |
12 ms |
40028 KB |
n=2000 |
79 |
Correct |
11 ms |
40028 KB |
n=2000 |
80 |
Correct |
12 ms |
40028 KB |
n=2000 |
81 |
Correct |
12 ms |
40028 KB |
n=2000 |
82 |
Correct |
12 ms |
40024 KB |
n=2000 |
83 |
Correct |
12 ms |
40028 KB |
n=2000 |
84 |
Correct |
13 ms |
40072 KB |
n=2000 |
85 |
Correct |
12 ms |
40028 KB |
n=2000 |
86 |
Correct |
12 ms |
40028 KB |
n=2000 |
87 |
Correct |
12 ms |
40028 KB |
n=2000 |
88 |
Correct |
12 ms |
40024 KB |
n=2000 |
89 |
Correct |
12 ms |
39912 KB |
n=2000 |
90 |
Correct |
12 ms |
40028 KB |
n=2000 |
91 |
Correct |
12 ms |
40064 KB |
n=2000 |
92 |
Correct |
878 ms |
86460 KB |
n=200000 |
93 |
Correct |
1046 ms |
93244 KB |
n=200000 |
94 |
Correct |
1092 ms |
100700 KB |
n=200000 |
95 |
Correct |
890 ms |
92388 KB |
n=200000 |
96 |
Correct |
869 ms |
92872 KB |
n=200000 |
97 |
Correct |
1111 ms |
96668 KB |
n=200000 |
98 |
Correct |
841 ms |
92892 KB |
n=200000 |
99 |
Correct |
1056 ms |
92752 KB |
n=200000 |
100 |
Correct |
896 ms |
92760 KB |
n=200000 |
101 |
Correct |
1082 ms |
102228 KB |
n=200000 |
102 |
Correct |
762 ms |
94184 KB |
n=200000 |
103 |
Correct |
714 ms |
94032 KB |
n=200000 |
104 |
Correct |
730 ms |
93736 KB |
n=200000 |
105 |
Correct |
788 ms |
94032 KB |
n=200000 |
106 |
Correct |
705 ms |
94188 KB |
n=200000 |
107 |
Correct |
745 ms |
94140 KB |
n=200000 |
108 |
Correct |
1000 ms |
92448 KB |
n=200000 |
109 |
Correct |
935 ms |
92808 KB |
n=200000 |
110 |
Correct |
1016 ms |
92448 KB |
n=200000 |
111 |
Correct |
878 ms |
91864 KB |
n=200000 |
112 |
Correct |
1070 ms |
101128 KB |
n=200000 |
113 |
Correct |
1072 ms |
96800 KB |
n=200000 |
114 |
Correct |
901 ms |
91868 KB |
n=200000 |
115 |
Correct |
1122 ms |
94852 KB |
n=200000 |
116 |
Correct |
852 ms |
92896 KB |
n=200000 |
117 |
Correct |
1014 ms |
101484 KB |
n=200000 |
118 |
Correct |
1089 ms |
95276 KB |
n=200000 |
119 |
Correct |
846 ms |
92964 KB |
n=200000 |
120 |
Correct |
948 ms |
101008 KB |
n=200000 |
121 |
Correct |
948 ms |
101164 KB |
n=200000 |
122 |
Correct |
958 ms |
101428 KB |
n=200000 |
123 |
Correct |
726 ms |
93780 KB |
n=200000 |
124 |
Correct |
224 ms |
54356 KB |
n=25264 |