#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, q; cin>>n>>m>>q;
vector<int> g[n + 1];
for (int i = 1; i < n; i++){
int u, v; cin>>u>>v;
g[u].pb(v);
g[v].pb(u);
}
const int lg = log2(n);
vector<vector<int>> pw(n + 1, vector<int>(lg + 1));
vector<int> tin(n + 1), tout(n + 1);
int timer = 0;
function<void(int, int)> fill = [&](int v, int pr){
tin[v] = ++timer;
pw[v][0] = pr;
for (int i = 1; i <= lg; i++){
pw[v][i] = pw[pw[v][i - 1]][i - 1];
}
for (int i: g[v]){
if (i == pr) continue;
fill(i, v);
}
tout[v] = timer;
};
fill(1, 1);
auto check = [&](int x, int y){
return (tin[x] <= tin[y] && tout[x] >= tout[y]);
};
auto lca = [&](int x, int y){
if (check(x, y)) return x;
if (check(y, x)) return y;
for (int i = lg; i >= 0; i--){
if (!check(pw[x][i], y)){
x = pw[x][i];
}
}
return pw[x][0];
};
vector<int> a(m + 1);
set<int> st[n + 1];
for (int i = 1; i <= m; i++){
cin>>a[i];
st[a[i]].insert(i);
}
set<int> st1[n + 1];
for (int i = 1; i + 1 <= m; i++){
st1[lca(a[i], a[i + 1])].insert(i);
}
while (q--){
int type; cin>>type;
if (type == 1){
int p, v; cin>>p>>v;
if (p > 1) st1[lca(a[p - 1], a[p])].erase(p - 1);
if (p < m) st1[lca(a[p], a[p + 1])].erase(p);
st[a[p]].erase(p);
a[p] = v;
st[v].insert(p);
if (p > 1) st1[lca(a[p - 1], a[p])].insert(p - 1);
if (p < m) st1[lca(a[p], a[p + 1])].insert(p);
}
else {
int l, r, v; cin>>l>>r>>v;
auto it = st[v].lower_bound(l);
if (it != st[v].end() && (*it) <= r){
cout<<(*it)<<" "<<(*it)<<"\n";
continue;
}
it = st1[v].lower_bound(l);
if (it != st1[v].end() && (*it) < r){
cout<<(*it)<<" "<<(*it) + 1<<"\n";
continue;
}
cout<<-1<<" "<<-1<<"\n";
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n=5 |
2 |
Correct |
0 ms |
348 KB |
n=100 |
3 |
Correct |
0 ms |
348 KB |
n=100 |
4 |
Correct |
0 ms |
348 KB |
n=100 |
5 |
Correct |
0 ms |
456 KB |
n=100 |
6 |
Correct |
1 ms |
348 KB |
n=100 |
7 |
Correct |
0 ms |
348 KB |
n=100 |
8 |
Correct |
1 ms |
348 KB |
n=100 |
9 |
Correct |
0 ms |
348 KB |
n=100 |
10 |
Correct |
1 ms |
452 KB |
n=100 |
11 |
Correct |
0 ms |
344 KB |
n=100 |
12 |
Correct |
1 ms |
348 KB |
n=100 |
13 |
Correct |
1 ms |
348 KB |
n=100 |
14 |
Correct |
1 ms |
348 KB |
n=100 |
15 |
Correct |
0 ms |
348 KB |
n=100 |
16 |
Correct |
0 ms |
344 KB |
n=100 |
17 |
Correct |
0 ms |
344 KB |
n=100 |
18 |
Correct |
0 ms |
344 KB |
n=100 |
19 |
Correct |
1 ms |
348 KB |
n=100 |
20 |
Correct |
1 ms |
348 KB |
n=100 |
21 |
Correct |
0 ms |
348 KB |
n=100 |
22 |
Correct |
1 ms |
348 KB |
n=100 |
23 |
Correct |
1 ms |
348 KB |
n=100 |
24 |
Correct |
1 ms |
348 KB |
n=100 |
25 |
Correct |
1 ms |
348 KB |
n=100 |
26 |
Correct |
1 ms |
348 KB |
n=12 |
27 |
Correct |
1 ms |
344 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n=5 |
2 |
Correct |
0 ms |
348 KB |
n=100 |
3 |
Correct |
0 ms |
348 KB |
n=100 |
4 |
Correct |
0 ms |
348 KB |
n=100 |
5 |
Correct |
0 ms |
456 KB |
n=100 |
6 |
Correct |
1 ms |
348 KB |
n=100 |
7 |
Correct |
0 ms |
348 KB |
n=100 |
8 |
Correct |
1 ms |
348 KB |
n=100 |
9 |
Correct |
0 ms |
348 KB |
n=100 |
10 |
Correct |
1 ms |
452 KB |
n=100 |
11 |
Correct |
0 ms |
344 KB |
n=100 |
12 |
Correct |
1 ms |
348 KB |
n=100 |
13 |
Correct |
1 ms |
348 KB |
n=100 |
14 |
Correct |
1 ms |
348 KB |
n=100 |
15 |
Correct |
0 ms |
348 KB |
n=100 |
16 |
Correct |
0 ms |
344 KB |
n=100 |
17 |
Correct |
0 ms |
344 KB |
n=100 |
18 |
Correct |
0 ms |
344 KB |
n=100 |
19 |
Correct |
1 ms |
348 KB |
n=100 |
20 |
Correct |
1 ms |
348 KB |
n=100 |
21 |
Correct |
0 ms |
348 KB |
n=100 |
22 |
Correct |
1 ms |
348 KB |
n=100 |
23 |
Correct |
1 ms |
348 KB |
n=100 |
24 |
Correct |
1 ms |
348 KB |
n=100 |
25 |
Correct |
1 ms |
348 KB |
n=100 |
26 |
Correct |
1 ms |
348 KB |
n=12 |
27 |
Correct |
1 ms |
344 KB |
n=100 |
28 |
Correct |
1 ms |
604 KB |
n=500 |
29 |
Correct |
1 ms |
604 KB |
n=500 |
30 |
Correct |
1 ms |
604 KB |
n=500 |
31 |
Correct |
1 ms |
600 KB |
n=500 |
32 |
Correct |
1 ms |
600 KB |
n=500 |
33 |
Correct |
1 ms |
604 KB |
n=500 |
34 |
Correct |
1 ms |
604 KB |
n=500 |
35 |
Correct |
1 ms |
604 KB |
n=500 |
36 |
Correct |
1 ms |
604 KB |
n=500 |
37 |
Correct |
1 ms |
604 KB |
n=500 |
38 |
Correct |
1 ms |
604 KB |
n=500 |
39 |
Correct |
1 ms |
604 KB |
n=500 |
40 |
Correct |
1 ms |
604 KB |
n=500 |
41 |
Correct |
1 ms |
604 KB |
n=500 |
42 |
Correct |
1 ms |
600 KB |
n=500 |
43 |
Correct |
1 ms |
600 KB |
n=500 |
44 |
Correct |
1 ms |
600 KB |
n=500 |
45 |
Correct |
1 ms |
604 KB |
n=500 |
46 |
Correct |
1 ms |
604 KB |
n=500 |
47 |
Correct |
1 ms |
604 KB |
n=500 |
48 |
Correct |
1 ms |
604 KB |
n=500 |
49 |
Correct |
1 ms |
604 KB |
n=500 |
50 |
Correct |
1 ms |
600 KB |
n=500 |
51 |
Correct |
1 ms |
604 KB |
n=500 |
52 |
Correct |
1 ms |
604 KB |
n=500 |
53 |
Correct |
1 ms |
604 KB |
n=500 |
54 |
Correct |
1 ms |
604 KB |
n=500 |
55 |
Correct |
0 ms |
348 KB |
n=278 |
56 |
Correct |
2 ms |
604 KB |
n=500 |
57 |
Correct |
1 ms |
604 KB |
n=500 |
58 |
Correct |
1 ms |
600 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n=5 |
2 |
Correct |
0 ms |
348 KB |
n=100 |
3 |
Correct |
0 ms |
348 KB |
n=100 |
4 |
Correct |
0 ms |
348 KB |
n=100 |
5 |
Correct |
0 ms |
456 KB |
n=100 |
6 |
Correct |
1 ms |
348 KB |
n=100 |
7 |
Correct |
0 ms |
348 KB |
n=100 |
8 |
Correct |
1 ms |
348 KB |
n=100 |
9 |
Correct |
0 ms |
348 KB |
n=100 |
10 |
Correct |
1 ms |
452 KB |
n=100 |
11 |
Correct |
0 ms |
344 KB |
n=100 |
12 |
Correct |
1 ms |
348 KB |
n=100 |
13 |
Correct |
1 ms |
348 KB |
n=100 |
14 |
Correct |
1 ms |
348 KB |
n=100 |
15 |
Correct |
0 ms |
348 KB |
n=100 |
16 |
Correct |
0 ms |
344 KB |
n=100 |
17 |
Correct |
0 ms |
344 KB |
n=100 |
18 |
Correct |
0 ms |
344 KB |
n=100 |
19 |
Correct |
1 ms |
348 KB |
n=100 |
20 |
Correct |
1 ms |
348 KB |
n=100 |
21 |
Correct |
0 ms |
348 KB |
n=100 |
22 |
Correct |
1 ms |
348 KB |
n=100 |
23 |
Correct |
1 ms |
348 KB |
n=100 |
24 |
Correct |
1 ms |
348 KB |
n=100 |
25 |
Correct |
1 ms |
348 KB |
n=100 |
26 |
Correct |
1 ms |
348 KB |
n=12 |
27 |
Correct |
1 ms |
344 KB |
n=100 |
28 |
Correct |
1 ms |
604 KB |
n=500 |
29 |
Correct |
1 ms |
604 KB |
n=500 |
30 |
Correct |
1 ms |
604 KB |
n=500 |
31 |
Correct |
1 ms |
600 KB |
n=500 |
32 |
Correct |
1 ms |
600 KB |
n=500 |
33 |
Correct |
1 ms |
604 KB |
n=500 |
34 |
Correct |
1 ms |
604 KB |
n=500 |
35 |
Correct |
1 ms |
604 KB |
n=500 |
36 |
Correct |
1 ms |
604 KB |
n=500 |
37 |
Correct |
1 ms |
604 KB |
n=500 |
38 |
Correct |
1 ms |
604 KB |
n=500 |
39 |
Correct |
1 ms |
604 KB |
n=500 |
40 |
Correct |
1 ms |
604 KB |
n=500 |
41 |
Correct |
1 ms |
604 KB |
n=500 |
42 |
Correct |
1 ms |
600 KB |
n=500 |
43 |
Correct |
1 ms |
600 KB |
n=500 |
44 |
Correct |
1 ms |
600 KB |
n=500 |
45 |
Correct |
1 ms |
604 KB |
n=500 |
46 |
Correct |
1 ms |
604 KB |
n=500 |
47 |
Correct |
1 ms |
604 KB |
n=500 |
48 |
Correct |
1 ms |
604 KB |
n=500 |
49 |
Correct |
1 ms |
604 KB |
n=500 |
50 |
Correct |
1 ms |
600 KB |
n=500 |
51 |
Correct |
1 ms |
604 KB |
n=500 |
52 |
Correct |
1 ms |
604 KB |
n=500 |
53 |
Correct |
1 ms |
604 KB |
n=500 |
54 |
Correct |
1 ms |
604 KB |
n=500 |
55 |
Correct |
0 ms |
348 KB |
n=278 |
56 |
Correct |
2 ms |
604 KB |
n=500 |
57 |
Correct |
1 ms |
604 KB |
n=500 |
58 |
Correct |
1 ms |
600 KB |
n=500 |
59 |
Correct |
3 ms |
1116 KB |
n=2000 |
60 |
Correct |
2 ms |
1124 KB |
n=2000 |
61 |
Correct |
2 ms |
1112 KB |
n=2000 |
62 |
Correct |
3 ms |
1112 KB |
n=2000 |
63 |
Correct |
3 ms |
1116 KB |
n=2000 |
64 |
Correct |
2 ms |
1192 KB |
n=2000 |
65 |
Correct |
3 ms |
1112 KB |
n=2000 |
66 |
Correct |
3 ms |
1128 KB |
n=2000 |
67 |
Correct |
3 ms |
1112 KB |
n=2000 |
68 |
Correct |
2 ms |
1116 KB |
n=2000 |
69 |
Correct |
2 ms |
1112 KB |
n=2000 |
70 |
Correct |
2 ms |
1116 KB |
n=2000 |
71 |
Correct |
2 ms |
1116 KB |
n=2000 |
72 |
Correct |
2 ms |
1116 KB |
n=2000 |
73 |
Correct |
3 ms |
1116 KB |
n=2000 |
74 |
Correct |
2 ms |
976 KB |
n=1844 |
75 |
Correct |
2 ms |
1116 KB |
n=2000 |
76 |
Correct |
3 ms |
1124 KB |
n=2000 |
77 |
Correct |
3 ms |
1116 KB |
n=2000 |
78 |
Correct |
3 ms |
1116 KB |
n=2000 |
79 |
Correct |
3 ms |
1128 KB |
n=2000 |
80 |
Correct |
2 ms |
1116 KB |
n=2000 |
81 |
Correct |
2 ms |
1116 KB |
n=2000 |
82 |
Correct |
3 ms |
1116 KB |
n=2000 |
83 |
Correct |
2 ms |
1116 KB |
n=2000 |
84 |
Correct |
3 ms |
1116 KB |
n=2000 |
85 |
Correct |
3 ms |
1116 KB |
n=2000 |
86 |
Correct |
2 ms |
1064 KB |
n=2000 |
87 |
Correct |
3 ms |
1116 KB |
n=2000 |
88 |
Correct |
3 ms |
1116 KB |
n=2000 |
89 |
Correct |
2 ms |
1112 KB |
n=2000 |
90 |
Correct |
2 ms |
1116 KB |
n=2000 |
91 |
Correct |
2 ms |
1116 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n=5 |
2 |
Correct |
0 ms |
348 KB |
n=100 |
3 |
Correct |
0 ms |
348 KB |
n=100 |
4 |
Correct |
0 ms |
348 KB |
n=100 |
5 |
Correct |
0 ms |
456 KB |
n=100 |
6 |
Correct |
1 ms |
348 KB |
n=100 |
7 |
Correct |
0 ms |
348 KB |
n=100 |
8 |
Correct |
1 ms |
348 KB |
n=100 |
9 |
Correct |
0 ms |
348 KB |
n=100 |
10 |
Correct |
1 ms |
452 KB |
n=100 |
11 |
Correct |
0 ms |
344 KB |
n=100 |
12 |
Correct |
1 ms |
348 KB |
n=100 |
13 |
Correct |
1 ms |
348 KB |
n=100 |
14 |
Correct |
1 ms |
348 KB |
n=100 |
15 |
Correct |
0 ms |
348 KB |
n=100 |
16 |
Correct |
0 ms |
344 KB |
n=100 |
17 |
Correct |
0 ms |
344 KB |
n=100 |
18 |
Correct |
0 ms |
344 KB |
n=100 |
19 |
Correct |
1 ms |
348 KB |
n=100 |
20 |
Correct |
1 ms |
348 KB |
n=100 |
21 |
Correct |
0 ms |
348 KB |
n=100 |
22 |
Correct |
1 ms |
348 KB |
n=100 |
23 |
Correct |
1 ms |
348 KB |
n=100 |
24 |
Correct |
1 ms |
348 KB |
n=100 |
25 |
Correct |
1 ms |
348 KB |
n=100 |
26 |
Correct |
1 ms |
348 KB |
n=12 |
27 |
Correct |
1 ms |
344 KB |
n=100 |
28 |
Correct |
1 ms |
604 KB |
n=500 |
29 |
Correct |
1 ms |
604 KB |
n=500 |
30 |
Correct |
1 ms |
604 KB |
n=500 |
31 |
Correct |
1 ms |
600 KB |
n=500 |
32 |
Correct |
1 ms |
600 KB |
n=500 |
33 |
Correct |
1 ms |
604 KB |
n=500 |
34 |
Correct |
1 ms |
604 KB |
n=500 |
35 |
Correct |
1 ms |
604 KB |
n=500 |
36 |
Correct |
1 ms |
604 KB |
n=500 |
37 |
Correct |
1 ms |
604 KB |
n=500 |
38 |
Correct |
1 ms |
604 KB |
n=500 |
39 |
Correct |
1 ms |
604 KB |
n=500 |
40 |
Correct |
1 ms |
604 KB |
n=500 |
41 |
Correct |
1 ms |
604 KB |
n=500 |
42 |
Correct |
1 ms |
600 KB |
n=500 |
43 |
Correct |
1 ms |
600 KB |
n=500 |
44 |
Correct |
1 ms |
600 KB |
n=500 |
45 |
Correct |
1 ms |
604 KB |
n=500 |
46 |
Correct |
1 ms |
604 KB |
n=500 |
47 |
Correct |
1 ms |
604 KB |
n=500 |
48 |
Correct |
1 ms |
604 KB |
n=500 |
49 |
Correct |
1 ms |
604 KB |
n=500 |
50 |
Correct |
1 ms |
600 KB |
n=500 |
51 |
Correct |
1 ms |
604 KB |
n=500 |
52 |
Correct |
1 ms |
604 KB |
n=500 |
53 |
Correct |
1 ms |
604 KB |
n=500 |
54 |
Correct |
1 ms |
604 KB |
n=500 |
55 |
Correct |
0 ms |
348 KB |
n=278 |
56 |
Correct |
2 ms |
604 KB |
n=500 |
57 |
Correct |
1 ms |
604 KB |
n=500 |
58 |
Correct |
1 ms |
600 KB |
n=500 |
59 |
Correct |
3 ms |
1116 KB |
n=2000 |
60 |
Correct |
2 ms |
1124 KB |
n=2000 |
61 |
Correct |
2 ms |
1112 KB |
n=2000 |
62 |
Correct |
3 ms |
1112 KB |
n=2000 |
63 |
Correct |
3 ms |
1116 KB |
n=2000 |
64 |
Correct |
2 ms |
1192 KB |
n=2000 |
65 |
Correct |
3 ms |
1112 KB |
n=2000 |
66 |
Correct |
3 ms |
1128 KB |
n=2000 |
67 |
Correct |
3 ms |
1112 KB |
n=2000 |
68 |
Correct |
2 ms |
1116 KB |
n=2000 |
69 |
Correct |
2 ms |
1112 KB |
n=2000 |
70 |
Correct |
2 ms |
1116 KB |
n=2000 |
71 |
Correct |
2 ms |
1116 KB |
n=2000 |
72 |
Correct |
2 ms |
1116 KB |
n=2000 |
73 |
Correct |
3 ms |
1116 KB |
n=2000 |
74 |
Correct |
2 ms |
976 KB |
n=1844 |
75 |
Correct |
2 ms |
1116 KB |
n=2000 |
76 |
Correct |
3 ms |
1124 KB |
n=2000 |
77 |
Correct |
3 ms |
1116 KB |
n=2000 |
78 |
Correct |
3 ms |
1116 KB |
n=2000 |
79 |
Correct |
3 ms |
1128 KB |
n=2000 |
80 |
Correct |
2 ms |
1116 KB |
n=2000 |
81 |
Correct |
2 ms |
1116 KB |
n=2000 |
82 |
Correct |
3 ms |
1116 KB |
n=2000 |
83 |
Correct |
2 ms |
1116 KB |
n=2000 |
84 |
Correct |
3 ms |
1116 KB |
n=2000 |
85 |
Correct |
3 ms |
1116 KB |
n=2000 |
86 |
Correct |
2 ms |
1064 KB |
n=2000 |
87 |
Correct |
3 ms |
1116 KB |
n=2000 |
88 |
Correct |
3 ms |
1116 KB |
n=2000 |
89 |
Correct |
2 ms |
1112 KB |
n=2000 |
90 |
Correct |
2 ms |
1116 KB |
n=2000 |
91 |
Correct |
2 ms |
1116 KB |
n=2000 |
92 |
Correct |
464 ms |
80032 KB |
n=200000 |
93 |
Correct |
534 ms |
80332 KB |
n=200000 |
94 |
Correct |
403 ms |
80464 KB |
n=200000 |
95 |
Correct |
501 ms |
79932 KB |
n=200000 |
96 |
Correct |
453 ms |
79812 KB |
n=200000 |
97 |
Correct |
560 ms |
80464 KB |
n=200000 |
98 |
Correct |
464 ms |
79816 KB |
n=200000 |
99 |
Correct |
566 ms |
80340 KB |
n=200000 |
100 |
Correct |
465 ms |
80064 KB |
n=200000 |
101 |
Correct |
352 ms |
80212 KB |
n=200000 |
102 |
Correct |
273 ms |
81028 KB |
n=200000 |
103 |
Correct |
296 ms |
80980 KB |
n=200000 |
104 |
Correct |
279 ms |
81232 KB |
n=200000 |
105 |
Correct |
290 ms |
81556 KB |
n=200000 |
106 |
Correct |
322 ms |
81460 KB |
n=200000 |
107 |
Correct |
293 ms |
81488 KB |
n=200000 |
108 |
Correct |
476 ms |
79932 KB |
n=200000 |
109 |
Correct |
514 ms |
79956 KB |
n=200000 |
110 |
Correct |
496 ms |
79884 KB |
n=200000 |
111 |
Correct |
455 ms |
79436 KB |
n=200000 |
112 |
Correct |
359 ms |
80380 KB |
n=200000 |
113 |
Correct |
538 ms |
80212 KB |
n=200000 |
114 |
Correct |
459 ms |
79300 KB |
n=200000 |
115 |
Correct |
710 ms |
80464 KB |
n=200000 |
116 |
Correct |
507 ms |
80324 KB |
n=200000 |
117 |
Correct |
357 ms |
80212 KB |
n=200000 |
118 |
Correct |
607 ms |
80200 KB |
n=200000 |
119 |
Correct |
485 ms |
80096 KB |
n=200000 |
120 |
Correct |
267 ms |
79188 KB |
n=200000 |
121 |
Correct |
272 ms |
79184 KB |
n=200000 |
122 |
Correct |
249 ms |
79528 KB |
n=200000 |
123 |
Correct |
267 ms |
81360 KB |
n=200000 |
124 |
Correct |
83 ms |
18000 KB |
n=25264 |