#include <bits/stdc++.h>
using namespace std;
#define sz(s) (int)s.size()
vector <vector <int>> v, sp;
vector <int> h, p;
void dfs(int x, int y){
h[x] = h[y]+1;
p[x] = y;
for(auto i : v[x]){
if(i != y){
dfs(i,x);
}
}
}
int lca(int x, int y){
if(h[x] < h[y]) swap(x,y);
for(int i = 20; i >= 0; i--){
if(h[sp[x][i]] >= h[y]){
x = sp[x][i];
}
}
for(int i = 20; i >= 0; i--){
if(sp[x][i] != sp[y][i]){
x = sp[x][i];
y = sp[y][i];
}
}
if(x == y) return x;
return p[x];
}
int main(){
int n, m, q;
cin >> n >> m >> q;
v.resize(n+1);
h.resize(n+1,0);
for(int i = 1; i < n; i++){
int u1, u2;
cin >> u1 >> u2;
v[u1].push_back(u2);
v[u2].push_back(u1);
}
p.resize(n+1);
sp.resize(n+1, vector <int> (25,0));
dfs(1,0);
for(int i = 1; i <= n; i++){
sp[i][0] = p[i];
}
for(int j = 1; j <= 20; j++){
for(int i = 1; i <= n; i++){
sp[i][j] = sp[sp[i][j-1]][j-1];
}
}
set <int> s[n+1], s1[n+1];
vector <int> a(m+1);
for(int i = 1; i <= m; i++){
cin >> a[i];
s1[a[i]].insert(i);
if(i != 1){
s[lca(a[i],a[i-1])].insert(i-1);
}
}
for(int i = 1; i <= q; i++){
int t;
cin >> t;
if(t == 1){
int in, vl;
cin >> in >> vl;
s1[a[in]].erase(s1[a[in]].find(in));
if(in != 1){
int x = lca(a[in],a[in-1]);
s[x].erase(s[x].find(in-1));
}
if(in != m){
int x = lca(a[in],a[in+1]);
s[x].erase(s[x].find(in));
}
a[in] = vl;
if(in != 1){
int x = lca(a[in],a[in-1]);
s[x].insert(in-1);
}
if(in != m){
int x = lca(a[in],a[in+1]);
s[x].insert(in);
}
s1[a[in]].insert(in);
}
else {
int l, r, vl;
cin >> l >> r >> vl;
int x = m+1, y = m+1;
if(sz(s1[vl]) > 0 and *(--s1[vl].end()) >= l) x = (*s1[vl].lower_bound(l));
if(sz(s[vl]) > 0 and *(--s[vl].end()) >= l) y = (*s[vl].lower_bound(l));
if(x <= r){
cout << x << ' ' << x << '\n';
}
else if(y < r){
cout << y << ' ' << y+1 << '\n';
}
else {
cout << "-1 -1\n";
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
n=5 |
2 |
Correct |
1 ms |
336 KB |
n=100 |
3 |
Correct |
1 ms |
336 KB |
n=100 |
4 |
Correct |
1 ms |
336 KB |
n=100 |
5 |
Correct |
1 ms |
336 KB |
n=100 |
6 |
Correct |
1 ms |
504 KB |
n=100 |
7 |
Correct |
1 ms |
336 KB |
n=100 |
8 |
Correct |
1 ms |
336 KB |
n=100 |
9 |
Correct |
1 ms |
336 KB |
n=100 |
10 |
Correct |
1 ms |
504 KB |
n=100 |
11 |
Correct |
1 ms |
336 KB |
n=100 |
12 |
Correct |
1 ms |
336 KB |
n=100 |
13 |
Correct |
1 ms |
336 KB |
n=100 |
14 |
Correct |
1 ms |
336 KB |
n=100 |
15 |
Correct |
1 ms |
336 KB |
n=100 |
16 |
Correct |
1 ms |
336 KB |
n=100 |
17 |
Correct |
1 ms |
336 KB |
n=100 |
18 |
Correct |
1 ms |
336 KB |
n=100 |
19 |
Correct |
1 ms |
336 KB |
n=100 |
20 |
Correct |
1 ms |
336 KB |
n=100 |
21 |
Correct |
1 ms |
336 KB |
n=100 |
22 |
Correct |
1 ms |
336 KB |
n=100 |
23 |
Correct |
1 ms |
336 KB |
n=100 |
24 |
Correct |
2 ms |
336 KB |
n=100 |
25 |
Correct |
1 ms |
336 KB |
n=100 |
26 |
Correct |
1 ms |
504 KB |
n=12 |
27 |
Correct |
1 ms |
336 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
n=5 |
2 |
Correct |
1 ms |
336 KB |
n=100 |
3 |
Correct |
1 ms |
336 KB |
n=100 |
4 |
Correct |
1 ms |
336 KB |
n=100 |
5 |
Correct |
1 ms |
336 KB |
n=100 |
6 |
Correct |
1 ms |
504 KB |
n=100 |
7 |
Correct |
1 ms |
336 KB |
n=100 |
8 |
Correct |
1 ms |
336 KB |
n=100 |
9 |
Correct |
1 ms |
336 KB |
n=100 |
10 |
Correct |
1 ms |
504 KB |
n=100 |
11 |
Correct |
1 ms |
336 KB |
n=100 |
12 |
Correct |
1 ms |
336 KB |
n=100 |
13 |
Correct |
1 ms |
336 KB |
n=100 |
14 |
Correct |
1 ms |
336 KB |
n=100 |
15 |
Correct |
1 ms |
336 KB |
n=100 |
16 |
Correct |
1 ms |
336 KB |
n=100 |
17 |
Correct |
1 ms |
336 KB |
n=100 |
18 |
Correct |
1 ms |
336 KB |
n=100 |
19 |
Correct |
1 ms |
336 KB |
n=100 |
20 |
Correct |
1 ms |
336 KB |
n=100 |
21 |
Correct |
1 ms |
336 KB |
n=100 |
22 |
Correct |
1 ms |
336 KB |
n=100 |
23 |
Correct |
1 ms |
336 KB |
n=100 |
24 |
Correct |
2 ms |
336 KB |
n=100 |
25 |
Correct |
1 ms |
336 KB |
n=100 |
26 |
Correct |
1 ms |
504 KB |
n=12 |
27 |
Correct |
1 ms |
336 KB |
n=100 |
28 |
Correct |
2 ms |
776 KB |
n=500 |
29 |
Correct |
2 ms |
592 KB |
n=500 |
30 |
Correct |
2 ms |
592 KB |
n=500 |
31 |
Correct |
3 ms |
592 KB |
n=500 |
32 |
Correct |
3 ms |
764 KB |
n=500 |
33 |
Correct |
2 ms |
592 KB |
n=500 |
34 |
Correct |
2 ms |
592 KB |
n=500 |
35 |
Correct |
2 ms |
592 KB |
n=500 |
36 |
Correct |
3 ms |
592 KB |
n=500 |
37 |
Correct |
3 ms |
592 KB |
n=500 |
38 |
Correct |
2 ms |
592 KB |
n=500 |
39 |
Correct |
2 ms |
592 KB |
n=500 |
40 |
Correct |
2 ms |
764 KB |
n=500 |
41 |
Correct |
3 ms |
592 KB |
n=500 |
42 |
Correct |
2 ms |
760 KB |
n=500 |
43 |
Correct |
2 ms |
592 KB |
n=500 |
44 |
Correct |
3 ms |
760 KB |
n=500 |
45 |
Correct |
2 ms |
592 KB |
n=500 |
46 |
Correct |
4 ms |
592 KB |
n=500 |
47 |
Correct |
2 ms |
592 KB |
n=500 |
48 |
Correct |
2 ms |
592 KB |
n=500 |
49 |
Correct |
2 ms |
592 KB |
n=500 |
50 |
Correct |
2 ms |
592 KB |
n=500 |
51 |
Correct |
2 ms |
592 KB |
n=500 |
52 |
Correct |
3 ms |
592 KB |
n=500 |
53 |
Correct |
3 ms |
592 KB |
n=500 |
54 |
Correct |
2 ms |
592 KB |
n=500 |
55 |
Correct |
1 ms |
336 KB |
n=278 |
56 |
Correct |
2 ms |
592 KB |
n=500 |
57 |
Correct |
2 ms |
592 KB |
n=500 |
58 |
Correct |
3 ms |
592 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
n=5 |
2 |
Correct |
1 ms |
336 KB |
n=100 |
3 |
Correct |
1 ms |
336 KB |
n=100 |
4 |
Correct |
1 ms |
336 KB |
n=100 |
5 |
Correct |
1 ms |
336 KB |
n=100 |
6 |
Correct |
1 ms |
504 KB |
n=100 |
7 |
Correct |
1 ms |
336 KB |
n=100 |
8 |
Correct |
1 ms |
336 KB |
n=100 |
9 |
Correct |
1 ms |
336 KB |
n=100 |
10 |
Correct |
1 ms |
504 KB |
n=100 |
11 |
Correct |
1 ms |
336 KB |
n=100 |
12 |
Correct |
1 ms |
336 KB |
n=100 |
13 |
Correct |
1 ms |
336 KB |
n=100 |
14 |
Correct |
1 ms |
336 KB |
n=100 |
15 |
Correct |
1 ms |
336 KB |
n=100 |
16 |
Correct |
1 ms |
336 KB |
n=100 |
17 |
Correct |
1 ms |
336 KB |
n=100 |
18 |
Correct |
1 ms |
336 KB |
n=100 |
19 |
Correct |
1 ms |
336 KB |
n=100 |
20 |
Correct |
1 ms |
336 KB |
n=100 |
21 |
Correct |
1 ms |
336 KB |
n=100 |
22 |
Correct |
1 ms |
336 KB |
n=100 |
23 |
Correct |
1 ms |
336 KB |
n=100 |
24 |
Correct |
2 ms |
336 KB |
n=100 |
25 |
Correct |
1 ms |
336 KB |
n=100 |
26 |
Correct |
1 ms |
504 KB |
n=12 |
27 |
Correct |
1 ms |
336 KB |
n=100 |
28 |
Correct |
2 ms |
776 KB |
n=500 |
29 |
Correct |
2 ms |
592 KB |
n=500 |
30 |
Correct |
2 ms |
592 KB |
n=500 |
31 |
Correct |
3 ms |
592 KB |
n=500 |
32 |
Correct |
3 ms |
764 KB |
n=500 |
33 |
Correct |
2 ms |
592 KB |
n=500 |
34 |
Correct |
2 ms |
592 KB |
n=500 |
35 |
Correct |
2 ms |
592 KB |
n=500 |
36 |
Correct |
3 ms |
592 KB |
n=500 |
37 |
Correct |
3 ms |
592 KB |
n=500 |
38 |
Correct |
2 ms |
592 KB |
n=500 |
39 |
Correct |
2 ms |
592 KB |
n=500 |
40 |
Correct |
2 ms |
764 KB |
n=500 |
41 |
Correct |
3 ms |
592 KB |
n=500 |
42 |
Correct |
2 ms |
760 KB |
n=500 |
43 |
Correct |
2 ms |
592 KB |
n=500 |
44 |
Correct |
3 ms |
760 KB |
n=500 |
45 |
Correct |
2 ms |
592 KB |
n=500 |
46 |
Correct |
4 ms |
592 KB |
n=500 |
47 |
Correct |
2 ms |
592 KB |
n=500 |
48 |
Correct |
2 ms |
592 KB |
n=500 |
49 |
Correct |
2 ms |
592 KB |
n=500 |
50 |
Correct |
2 ms |
592 KB |
n=500 |
51 |
Correct |
2 ms |
592 KB |
n=500 |
52 |
Correct |
3 ms |
592 KB |
n=500 |
53 |
Correct |
3 ms |
592 KB |
n=500 |
54 |
Correct |
2 ms |
592 KB |
n=500 |
55 |
Correct |
1 ms |
336 KB |
n=278 |
56 |
Correct |
2 ms |
592 KB |
n=500 |
57 |
Correct |
2 ms |
592 KB |
n=500 |
58 |
Correct |
3 ms |
592 KB |
n=500 |
59 |
Correct |
7 ms |
1280 KB |
n=2000 |
60 |
Correct |
8 ms |
1104 KB |
n=2000 |
61 |
Correct |
8 ms |
1104 KB |
n=2000 |
62 |
Correct |
8 ms |
1104 KB |
n=2000 |
63 |
Correct |
10 ms |
1104 KB |
n=2000 |
64 |
Correct |
7 ms |
1104 KB |
n=2000 |
65 |
Correct |
6 ms |
1104 KB |
n=2000 |
66 |
Correct |
8 ms |
1104 KB |
n=2000 |
67 |
Correct |
7 ms |
1104 KB |
n=2000 |
68 |
Correct |
7 ms |
1104 KB |
n=2000 |
69 |
Correct |
8 ms |
1104 KB |
n=2000 |
70 |
Correct |
8 ms |
1264 KB |
n=2000 |
71 |
Correct |
7 ms |
1272 KB |
n=2000 |
72 |
Correct |
8 ms |
1104 KB |
n=2000 |
73 |
Correct |
8 ms |
1104 KB |
n=2000 |
74 |
Correct |
6 ms |
1276 KB |
n=1844 |
75 |
Correct |
8 ms |
1104 KB |
n=2000 |
76 |
Correct |
8 ms |
1304 KB |
n=2000 |
77 |
Correct |
8 ms |
1104 KB |
n=2000 |
78 |
Correct |
8 ms |
1104 KB |
n=2000 |
79 |
Correct |
6 ms |
1164 KB |
n=2000 |
80 |
Correct |
7 ms |
1104 KB |
n=2000 |
81 |
Correct |
7 ms |
1104 KB |
n=2000 |
82 |
Correct |
7 ms |
1104 KB |
n=2000 |
83 |
Correct |
8 ms |
1104 KB |
n=2000 |
84 |
Correct |
8 ms |
1104 KB |
n=2000 |
85 |
Correct |
7 ms |
1104 KB |
n=2000 |
86 |
Correct |
8 ms |
1104 KB |
n=2000 |
87 |
Correct |
7 ms |
1104 KB |
n=2000 |
88 |
Correct |
8 ms |
1104 KB |
n=2000 |
89 |
Correct |
8 ms |
1104 KB |
n=2000 |
90 |
Correct |
8 ms |
1104 KB |
n=2000 |
91 |
Correct |
8 ms |
1104 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
n=5 |
2 |
Correct |
1 ms |
336 KB |
n=100 |
3 |
Correct |
1 ms |
336 KB |
n=100 |
4 |
Correct |
1 ms |
336 KB |
n=100 |
5 |
Correct |
1 ms |
336 KB |
n=100 |
6 |
Correct |
1 ms |
504 KB |
n=100 |
7 |
Correct |
1 ms |
336 KB |
n=100 |
8 |
Correct |
1 ms |
336 KB |
n=100 |
9 |
Correct |
1 ms |
336 KB |
n=100 |
10 |
Correct |
1 ms |
504 KB |
n=100 |
11 |
Correct |
1 ms |
336 KB |
n=100 |
12 |
Correct |
1 ms |
336 KB |
n=100 |
13 |
Correct |
1 ms |
336 KB |
n=100 |
14 |
Correct |
1 ms |
336 KB |
n=100 |
15 |
Correct |
1 ms |
336 KB |
n=100 |
16 |
Correct |
1 ms |
336 KB |
n=100 |
17 |
Correct |
1 ms |
336 KB |
n=100 |
18 |
Correct |
1 ms |
336 KB |
n=100 |
19 |
Correct |
1 ms |
336 KB |
n=100 |
20 |
Correct |
1 ms |
336 KB |
n=100 |
21 |
Correct |
1 ms |
336 KB |
n=100 |
22 |
Correct |
1 ms |
336 KB |
n=100 |
23 |
Correct |
1 ms |
336 KB |
n=100 |
24 |
Correct |
2 ms |
336 KB |
n=100 |
25 |
Correct |
1 ms |
336 KB |
n=100 |
26 |
Correct |
1 ms |
504 KB |
n=12 |
27 |
Correct |
1 ms |
336 KB |
n=100 |
28 |
Correct |
2 ms |
776 KB |
n=500 |
29 |
Correct |
2 ms |
592 KB |
n=500 |
30 |
Correct |
2 ms |
592 KB |
n=500 |
31 |
Correct |
3 ms |
592 KB |
n=500 |
32 |
Correct |
3 ms |
764 KB |
n=500 |
33 |
Correct |
2 ms |
592 KB |
n=500 |
34 |
Correct |
2 ms |
592 KB |
n=500 |
35 |
Correct |
2 ms |
592 KB |
n=500 |
36 |
Correct |
3 ms |
592 KB |
n=500 |
37 |
Correct |
3 ms |
592 KB |
n=500 |
38 |
Correct |
2 ms |
592 KB |
n=500 |
39 |
Correct |
2 ms |
592 KB |
n=500 |
40 |
Correct |
2 ms |
764 KB |
n=500 |
41 |
Correct |
3 ms |
592 KB |
n=500 |
42 |
Correct |
2 ms |
760 KB |
n=500 |
43 |
Correct |
2 ms |
592 KB |
n=500 |
44 |
Correct |
3 ms |
760 KB |
n=500 |
45 |
Correct |
2 ms |
592 KB |
n=500 |
46 |
Correct |
4 ms |
592 KB |
n=500 |
47 |
Correct |
2 ms |
592 KB |
n=500 |
48 |
Correct |
2 ms |
592 KB |
n=500 |
49 |
Correct |
2 ms |
592 KB |
n=500 |
50 |
Correct |
2 ms |
592 KB |
n=500 |
51 |
Correct |
2 ms |
592 KB |
n=500 |
52 |
Correct |
3 ms |
592 KB |
n=500 |
53 |
Correct |
3 ms |
592 KB |
n=500 |
54 |
Correct |
2 ms |
592 KB |
n=500 |
55 |
Correct |
1 ms |
336 KB |
n=278 |
56 |
Correct |
2 ms |
592 KB |
n=500 |
57 |
Correct |
2 ms |
592 KB |
n=500 |
58 |
Correct |
3 ms |
592 KB |
n=500 |
59 |
Correct |
7 ms |
1280 KB |
n=2000 |
60 |
Correct |
8 ms |
1104 KB |
n=2000 |
61 |
Correct |
8 ms |
1104 KB |
n=2000 |
62 |
Correct |
8 ms |
1104 KB |
n=2000 |
63 |
Correct |
10 ms |
1104 KB |
n=2000 |
64 |
Correct |
7 ms |
1104 KB |
n=2000 |
65 |
Correct |
6 ms |
1104 KB |
n=2000 |
66 |
Correct |
8 ms |
1104 KB |
n=2000 |
67 |
Correct |
7 ms |
1104 KB |
n=2000 |
68 |
Correct |
7 ms |
1104 KB |
n=2000 |
69 |
Correct |
8 ms |
1104 KB |
n=2000 |
70 |
Correct |
8 ms |
1264 KB |
n=2000 |
71 |
Correct |
7 ms |
1272 KB |
n=2000 |
72 |
Correct |
8 ms |
1104 KB |
n=2000 |
73 |
Correct |
8 ms |
1104 KB |
n=2000 |
74 |
Correct |
6 ms |
1276 KB |
n=1844 |
75 |
Correct |
8 ms |
1104 KB |
n=2000 |
76 |
Correct |
8 ms |
1304 KB |
n=2000 |
77 |
Correct |
8 ms |
1104 KB |
n=2000 |
78 |
Correct |
8 ms |
1104 KB |
n=2000 |
79 |
Correct |
6 ms |
1164 KB |
n=2000 |
80 |
Correct |
7 ms |
1104 KB |
n=2000 |
81 |
Correct |
7 ms |
1104 KB |
n=2000 |
82 |
Correct |
7 ms |
1104 KB |
n=2000 |
83 |
Correct |
8 ms |
1104 KB |
n=2000 |
84 |
Correct |
8 ms |
1104 KB |
n=2000 |
85 |
Correct |
7 ms |
1104 KB |
n=2000 |
86 |
Correct |
8 ms |
1104 KB |
n=2000 |
87 |
Correct |
7 ms |
1104 KB |
n=2000 |
88 |
Correct |
8 ms |
1104 KB |
n=2000 |
89 |
Correct |
8 ms |
1104 KB |
n=2000 |
90 |
Correct |
8 ms |
1104 KB |
n=2000 |
91 |
Correct |
8 ms |
1104 KB |
n=2000 |
92 |
Correct |
989 ms |
80100 KB |
n=200000 |
93 |
Correct |
1469 ms |
82320 KB |
n=200000 |
94 |
Correct |
1545 ms |
86664 KB |
n=200000 |
95 |
Correct |
1024 ms |
85948 KB |
n=200000 |
96 |
Correct |
963 ms |
86204 KB |
n=200000 |
97 |
Correct |
1475 ms |
86600 KB |
n=200000 |
98 |
Correct |
1078 ms |
86164 KB |
n=200000 |
99 |
Correct |
1361 ms |
86420 KB |
n=200000 |
100 |
Correct |
1084 ms |
86204 KB |
n=200000 |
101 |
Correct |
1595 ms |
86516 KB |
n=200000 |
102 |
Correct |
836 ms |
87368 KB |
n=200000 |
103 |
Correct |
835 ms |
87368 KB |
n=200000 |
104 |
Correct |
842 ms |
87272 KB |
n=200000 |
105 |
Correct |
877 ms |
87684 KB |
n=200000 |
106 |
Correct |
791 ms |
87624 KB |
n=200000 |
107 |
Correct |
821 ms |
87624 KB |
n=200000 |
108 |
Correct |
1184 ms |
86088 KB |
n=200000 |
109 |
Correct |
1188 ms |
86124 KB |
n=200000 |
110 |
Correct |
1004 ms |
86088 KB |
n=200000 |
111 |
Correct |
1012 ms |
85728 KB |
n=200000 |
112 |
Correct |
1339 ms |
86600 KB |
n=200000 |
113 |
Correct |
1743 ms |
86600 KB |
n=200000 |
114 |
Correct |
985 ms |
85692 KB |
n=200000 |
115 |
Correct |
1808 ms |
86584 KB |
n=200000 |
116 |
Correct |
1063 ms |
86316 KB |
n=200000 |
117 |
Correct |
1476 ms |
86284 KB |
n=200000 |
118 |
Correct |
1506 ms |
86300 KB |
n=200000 |
119 |
Correct |
1064 ms |
86576 KB |
n=200000 |
120 |
Correct |
1522 ms |
85496 KB |
n=200000 |
121 |
Correct |
1540 ms |
85404 KB |
n=200000 |
122 |
Correct |
1585 ms |
85820 KB |
n=200000 |
123 |
Correct |
855 ms |
87484 KB |
n=200000 |
124 |
Correct |
357 ms |
18760 KB |
n=25264 |