// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define pb push_back
#define f first
#define s second
#define mp make_pair
using pi = pair<int, int>;
// const int nax = 2e5+5;
// const int LG = 18;
template<class T> using V = vector<T>;
int main() {
cin.tie(0)->sync_with_stdio(0);
int N, M, Q; cin >> N >> M >> Q;
int LG = 0; while((1 << LG) < N) LG++;
V<V<int>> up(N, V<int>(LG));
V<int> dep(N);
V<V<int>> adj(N);
for(int _ = 0; _ < N-1; _++) {
int u, v; cin >> u >> v; --u, --v;
adj[u].pb(v);
adj[v].pb(u);
}
function<int(int, int)> jmp = [&] (int u, int d) {
for(int i = 0; i < LG; i++) if ((d >> i) & 1) {
u = up[u][i];
}
return u;
};
function<int(int, int)> lca = [&](int a, int b) {
if (dep[a] < dep[b]) swap(a, b);
a = jmp(a, dep[a] - dep[b]);
if (a == b) return a;
for(int i = LG - 1; i >= 0; i--) {
if (up[a][i] != up[b][i]) a = up[a][i], b = up[b][i];
}
return up[a][0];
};
function<void(int, int)> dfs = [&](int u, int p) {
up[u][0] = p;
for(int i = 1; i < LG; i++) up[u][i] = up[up[u][i-1]][i-1];
for(auto v : adj[u]) if (v != p) {
dep[v] = dep[u] + 1; dfs(v, u);
}
};
dep[0] = 0; dfs(0, 0);
V<set<pi>> X(N);
V<int> A(M), LCA(M-1); for(auto& x : A) { cin >> x; --x; }
for(int i = 0; i < M; i++) {
if (i+1 < M) X[(LCA[i] = lca(A[i], A[i+1]))].insert(mp(i, i+1));
X[A[i]].insert(mp(i, i));
}
while(Q--) {
int t; cin >> t;
if (t == 1) {
int i, x; cin >> i >> x; --i, --x;
if (i-1 >= 0) X[LCA[i-1]].erase(mp(i-1, i));
if (i+1 < M) X[LCA[i]].erase(mp(i, i+1));
X[A[i]].erase(mp(i, i));
A[i] = x;
X[A[i]].insert(mp(i, i));
if (i-1 >= 0) X[(LCA[i-1] = lca(A[i-1], A[i]))].insert(mp(i-1, i));
if (i+1 < M) X[(LCA[i] = lca(A[i], A[i+1]))].insert(mp(i, i+1));
} else {
int l, r, x; cin >> l >> r >> x; --l, --r, --x;
// --r; // BECAUSE NEED TO FIND i SUCH THAT l ≤ i < r
// for(auto v : X[x]) cout << "(" << v.f << ", " << v.s << ")" << nl;
// cout << nl;
auto it = X[x].lower_bound(mp(l, -1));
if (it == end(X[x])) cout << -1 << " " << -1 << nl;
else {
int L, R; tie(L, R) = *it;
if (R > r) L = R = -1;
else ++L, ++R;
cout << L << " " << R << nl;
}
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n=5 |
2 |
Correct |
1 ms |
340 KB |
n=100 |
3 |
Correct |
1 ms |
340 KB |
n=100 |
4 |
Correct |
1 ms |
340 KB |
n=100 |
5 |
Correct |
1 ms |
340 KB |
n=100 |
6 |
Correct |
0 ms |
340 KB |
n=100 |
7 |
Correct |
1 ms |
340 KB |
n=100 |
8 |
Correct |
1 ms |
340 KB |
n=100 |
9 |
Correct |
1 ms |
340 KB |
n=100 |
10 |
Correct |
0 ms |
340 KB |
n=100 |
11 |
Correct |
1 ms |
340 KB |
n=100 |
12 |
Correct |
1 ms |
340 KB |
n=100 |
13 |
Correct |
0 ms |
340 KB |
n=100 |
14 |
Correct |
0 ms |
340 KB |
n=100 |
15 |
Correct |
1 ms |
340 KB |
n=100 |
16 |
Correct |
1 ms |
340 KB |
n=100 |
17 |
Correct |
1 ms |
340 KB |
n=100 |
18 |
Correct |
1 ms |
340 KB |
n=100 |
19 |
Correct |
1 ms |
340 KB |
n=100 |
20 |
Correct |
0 ms |
340 KB |
n=100 |
21 |
Correct |
1 ms |
340 KB |
n=100 |
22 |
Correct |
1 ms |
340 KB |
n=100 |
23 |
Correct |
1 ms |
340 KB |
n=100 |
24 |
Correct |
0 ms |
340 KB |
n=100 |
25 |
Correct |
1 ms |
340 KB |
n=100 |
26 |
Correct |
0 ms |
212 KB |
n=12 |
27 |
Correct |
0 ms |
340 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n=5 |
2 |
Correct |
1 ms |
340 KB |
n=100 |
3 |
Correct |
1 ms |
340 KB |
n=100 |
4 |
Correct |
1 ms |
340 KB |
n=100 |
5 |
Correct |
1 ms |
340 KB |
n=100 |
6 |
Correct |
0 ms |
340 KB |
n=100 |
7 |
Correct |
1 ms |
340 KB |
n=100 |
8 |
Correct |
1 ms |
340 KB |
n=100 |
9 |
Correct |
1 ms |
340 KB |
n=100 |
10 |
Correct |
0 ms |
340 KB |
n=100 |
11 |
Correct |
1 ms |
340 KB |
n=100 |
12 |
Correct |
1 ms |
340 KB |
n=100 |
13 |
Correct |
0 ms |
340 KB |
n=100 |
14 |
Correct |
0 ms |
340 KB |
n=100 |
15 |
Correct |
1 ms |
340 KB |
n=100 |
16 |
Correct |
1 ms |
340 KB |
n=100 |
17 |
Correct |
1 ms |
340 KB |
n=100 |
18 |
Correct |
1 ms |
340 KB |
n=100 |
19 |
Correct |
1 ms |
340 KB |
n=100 |
20 |
Correct |
0 ms |
340 KB |
n=100 |
21 |
Correct |
1 ms |
340 KB |
n=100 |
22 |
Correct |
1 ms |
340 KB |
n=100 |
23 |
Correct |
1 ms |
340 KB |
n=100 |
24 |
Correct |
0 ms |
340 KB |
n=100 |
25 |
Correct |
1 ms |
340 KB |
n=100 |
26 |
Correct |
0 ms |
212 KB |
n=12 |
27 |
Correct |
0 ms |
340 KB |
n=100 |
28 |
Correct |
1 ms |
340 KB |
n=500 |
29 |
Correct |
1 ms |
468 KB |
n=500 |
30 |
Correct |
1 ms |
468 KB |
n=500 |
31 |
Correct |
1 ms |
468 KB |
n=500 |
32 |
Correct |
1 ms |
340 KB |
n=500 |
33 |
Correct |
1 ms |
468 KB |
n=500 |
34 |
Correct |
1 ms |
468 KB |
n=500 |
35 |
Correct |
1 ms |
468 KB |
n=500 |
36 |
Correct |
1 ms |
340 KB |
n=500 |
37 |
Correct |
1 ms |
340 KB |
n=500 |
38 |
Correct |
1 ms |
340 KB |
n=500 |
39 |
Correct |
1 ms |
340 KB |
n=500 |
40 |
Correct |
1 ms |
340 KB |
n=500 |
41 |
Correct |
1 ms |
340 KB |
n=500 |
42 |
Correct |
1 ms |
340 KB |
n=500 |
43 |
Correct |
1 ms |
340 KB |
n=500 |
44 |
Correct |
1 ms |
340 KB |
n=500 |
45 |
Correct |
1 ms |
340 KB |
n=500 |
46 |
Correct |
1 ms |
468 KB |
n=500 |
47 |
Correct |
1 ms |
468 KB |
n=500 |
48 |
Correct |
1 ms |
340 KB |
n=500 |
49 |
Correct |
1 ms |
468 KB |
n=500 |
50 |
Correct |
1 ms |
468 KB |
n=500 |
51 |
Correct |
1 ms |
468 KB |
n=500 |
52 |
Correct |
1 ms |
468 KB |
n=500 |
53 |
Correct |
1 ms |
468 KB |
n=500 |
54 |
Correct |
1 ms |
468 KB |
n=500 |
55 |
Correct |
1 ms |
340 KB |
n=278 |
56 |
Correct |
1 ms |
468 KB |
n=500 |
57 |
Correct |
1 ms |
468 KB |
n=500 |
58 |
Correct |
1 ms |
468 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n=5 |
2 |
Correct |
1 ms |
340 KB |
n=100 |
3 |
Correct |
1 ms |
340 KB |
n=100 |
4 |
Correct |
1 ms |
340 KB |
n=100 |
5 |
Correct |
1 ms |
340 KB |
n=100 |
6 |
Correct |
0 ms |
340 KB |
n=100 |
7 |
Correct |
1 ms |
340 KB |
n=100 |
8 |
Correct |
1 ms |
340 KB |
n=100 |
9 |
Correct |
1 ms |
340 KB |
n=100 |
10 |
Correct |
0 ms |
340 KB |
n=100 |
11 |
Correct |
1 ms |
340 KB |
n=100 |
12 |
Correct |
1 ms |
340 KB |
n=100 |
13 |
Correct |
0 ms |
340 KB |
n=100 |
14 |
Correct |
0 ms |
340 KB |
n=100 |
15 |
Correct |
1 ms |
340 KB |
n=100 |
16 |
Correct |
1 ms |
340 KB |
n=100 |
17 |
Correct |
1 ms |
340 KB |
n=100 |
18 |
Correct |
1 ms |
340 KB |
n=100 |
19 |
Correct |
1 ms |
340 KB |
n=100 |
20 |
Correct |
0 ms |
340 KB |
n=100 |
21 |
Correct |
1 ms |
340 KB |
n=100 |
22 |
Correct |
1 ms |
340 KB |
n=100 |
23 |
Correct |
1 ms |
340 KB |
n=100 |
24 |
Correct |
0 ms |
340 KB |
n=100 |
25 |
Correct |
1 ms |
340 KB |
n=100 |
26 |
Correct |
0 ms |
212 KB |
n=12 |
27 |
Correct |
0 ms |
340 KB |
n=100 |
28 |
Correct |
1 ms |
340 KB |
n=500 |
29 |
Correct |
1 ms |
468 KB |
n=500 |
30 |
Correct |
1 ms |
468 KB |
n=500 |
31 |
Correct |
1 ms |
468 KB |
n=500 |
32 |
Correct |
1 ms |
340 KB |
n=500 |
33 |
Correct |
1 ms |
468 KB |
n=500 |
34 |
Correct |
1 ms |
468 KB |
n=500 |
35 |
Correct |
1 ms |
468 KB |
n=500 |
36 |
Correct |
1 ms |
340 KB |
n=500 |
37 |
Correct |
1 ms |
340 KB |
n=500 |
38 |
Correct |
1 ms |
340 KB |
n=500 |
39 |
Correct |
1 ms |
340 KB |
n=500 |
40 |
Correct |
1 ms |
340 KB |
n=500 |
41 |
Correct |
1 ms |
340 KB |
n=500 |
42 |
Correct |
1 ms |
340 KB |
n=500 |
43 |
Correct |
1 ms |
340 KB |
n=500 |
44 |
Correct |
1 ms |
340 KB |
n=500 |
45 |
Correct |
1 ms |
340 KB |
n=500 |
46 |
Correct |
1 ms |
468 KB |
n=500 |
47 |
Correct |
1 ms |
468 KB |
n=500 |
48 |
Correct |
1 ms |
340 KB |
n=500 |
49 |
Correct |
1 ms |
468 KB |
n=500 |
50 |
Correct |
1 ms |
468 KB |
n=500 |
51 |
Correct |
1 ms |
468 KB |
n=500 |
52 |
Correct |
1 ms |
468 KB |
n=500 |
53 |
Correct |
1 ms |
468 KB |
n=500 |
54 |
Correct |
1 ms |
468 KB |
n=500 |
55 |
Correct |
1 ms |
340 KB |
n=278 |
56 |
Correct |
1 ms |
468 KB |
n=500 |
57 |
Correct |
1 ms |
468 KB |
n=500 |
58 |
Correct |
1 ms |
468 KB |
n=500 |
59 |
Correct |
3 ms |
856 KB |
n=2000 |
60 |
Correct |
4 ms |
980 KB |
n=2000 |
61 |
Correct |
3 ms |
980 KB |
n=2000 |
62 |
Correct |
4 ms |
852 KB |
n=2000 |
63 |
Correct |
3 ms |
852 KB |
n=2000 |
64 |
Correct |
4 ms |
980 KB |
n=2000 |
65 |
Correct |
3 ms |
852 KB |
n=2000 |
66 |
Correct |
3 ms |
980 KB |
n=2000 |
67 |
Correct |
3 ms |
852 KB |
n=2000 |
68 |
Correct |
3 ms |
980 KB |
n=2000 |
69 |
Correct |
2 ms |
852 KB |
n=2000 |
70 |
Correct |
2 ms |
852 KB |
n=2000 |
71 |
Correct |
2 ms |
852 KB |
n=2000 |
72 |
Correct |
2 ms |
852 KB |
n=2000 |
73 |
Correct |
3 ms |
852 KB |
n=2000 |
74 |
Correct |
2 ms |
852 KB |
n=1844 |
75 |
Correct |
2 ms |
852 KB |
n=2000 |
76 |
Correct |
4 ms |
980 KB |
n=2000 |
77 |
Correct |
3 ms |
852 KB |
n=2000 |
78 |
Correct |
3 ms |
852 KB |
n=2000 |
79 |
Correct |
3 ms |
852 KB |
n=2000 |
80 |
Correct |
3 ms |
980 KB |
n=2000 |
81 |
Correct |
3 ms |
980 KB |
n=2000 |
82 |
Correct |
4 ms |
852 KB |
n=2000 |
83 |
Correct |
3 ms |
980 KB |
n=2000 |
84 |
Correct |
4 ms |
852 KB |
n=2000 |
85 |
Correct |
3 ms |
980 KB |
n=2000 |
86 |
Correct |
3 ms |
852 KB |
n=2000 |
87 |
Correct |
3 ms |
852 KB |
n=2000 |
88 |
Correct |
3 ms |
980 KB |
n=2000 |
89 |
Correct |
3 ms |
980 KB |
n=2000 |
90 |
Correct |
3 ms |
1108 KB |
n=2000 |
91 |
Correct |
3 ms |
852 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n=5 |
2 |
Correct |
1 ms |
340 KB |
n=100 |
3 |
Correct |
1 ms |
340 KB |
n=100 |
4 |
Correct |
1 ms |
340 KB |
n=100 |
5 |
Correct |
1 ms |
340 KB |
n=100 |
6 |
Correct |
0 ms |
340 KB |
n=100 |
7 |
Correct |
1 ms |
340 KB |
n=100 |
8 |
Correct |
1 ms |
340 KB |
n=100 |
9 |
Correct |
1 ms |
340 KB |
n=100 |
10 |
Correct |
0 ms |
340 KB |
n=100 |
11 |
Correct |
1 ms |
340 KB |
n=100 |
12 |
Correct |
1 ms |
340 KB |
n=100 |
13 |
Correct |
0 ms |
340 KB |
n=100 |
14 |
Correct |
0 ms |
340 KB |
n=100 |
15 |
Correct |
1 ms |
340 KB |
n=100 |
16 |
Correct |
1 ms |
340 KB |
n=100 |
17 |
Correct |
1 ms |
340 KB |
n=100 |
18 |
Correct |
1 ms |
340 KB |
n=100 |
19 |
Correct |
1 ms |
340 KB |
n=100 |
20 |
Correct |
0 ms |
340 KB |
n=100 |
21 |
Correct |
1 ms |
340 KB |
n=100 |
22 |
Correct |
1 ms |
340 KB |
n=100 |
23 |
Correct |
1 ms |
340 KB |
n=100 |
24 |
Correct |
0 ms |
340 KB |
n=100 |
25 |
Correct |
1 ms |
340 KB |
n=100 |
26 |
Correct |
0 ms |
212 KB |
n=12 |
27 |
Correct |
0 ms |
340 KB |
n=100 |
28 |
Correct |
1 ms |
340 KB |
n=500 |
29 |
Correct |
1 ms |
468 KB |
n=500 |
30 |
Correct |
1 ms |
468 KB |
n=500 |
31 |
Correct |
1 ms |
468 KB |
n=500 |
32 |
Correct |
1 ms |
340 KB |
n=500 |
33 |
Correct |
1 ms |
468 KB |
n=500 |
34 |
Correct |
1 ms |
468 KB |
n=500 |
35 |
Correct |
1 ms |
468 KB |
n=500 |
36 |
Correct |
1 ms |
340 KB |
n=500 |
37 |
Correct |
1 ms |
340 KB |
n=500 |
38 |
Correct |
1 ms |
340 KB |
n=500 |
39 |
Correct |
1 ms |
340 KB |
n=500 |
40 |
Correct |
1 ms |
340 KB |
n=500 |
41 |
Correct |
1 ms |
340 KB |
n=500 |
42 |
Correct |
1 ms |
340 KB |
n=500 |
43 |
Correct |
1 ms |
340 KB |
n=500 |
44 |
Correct |
1 ms |
340 KB |
n=500 |
45 |
Correct |
1 ms |
340 KB |
n=500 |
46 |
Correct |
1 ms |
468 KB |
n=500 |
47 |
Correct |
1 ms |
468 KB |
n=500 |
48 |
Correct |
1 ms |
340 KB |
n=500 |
49 |
Correct |
1 ms |
468 KB |
n=500 |
50 |
Correct |
1 ms |
468 KB |
n=500 |
51 |
Correct |
1 ms |
468 KB |
n=500 |
52 |
Correct |
1 ms |
468 KB |
n=500 |
53 |
Correct |
1 ms |
468 KB |
n=500 |
54 |
Correct |
1 ms |
468 KB |
n=500 |
55 |
Correct |
1 ms |
340 KB |
n=278 |
56 |
Correct |
1 ms |
468 KB |
n=500 |
57 |
Correct |
1 ms |
468 KB |
n=500 |
58 |
Correct |
1 ms |
468 KB |
n=500 |
59 |
Correct |
3 ms |
856 KB |
n=2000 |
60 |
Correct |
4 ms |
980 KB |
n=2000 |
61 |
Correct |
3 ms |
980 KB |
n=2000 |
62 |
Correct |
4 ms |
852 KB |
n=2000 |
63 |
Correct |
3 ms |
852 KB |
n=2000 |
64 |
Correct |
4 ms |
980 KB |
n=2000 |
65 |
Correct |
3 ms |
852 KB |
n=2000 |
66 |
Correct |
3 ms |
980 KB |
n=2000 |
67 |
Correct |
3 ms |
852 KB |
n=2000 |
68 |
Correct |
3 ms |
980 KB |
n=2000 |
69 |
Correct |
2 ms |
852 KB |
n=2000 |
70 |
Correct |
2 ms |
852 KB |
n=2000 |
71 |
Correct |
2 ms |
852 KB |
n=2000 |
72 |
Correct |
2 ms |
852 KB |
n=2000 |
73 |
Correct |
3 ms |
852 KB |
n=2000 |
74 |
Correct |
2 ms |
852 KB |
n=1844 |
75 |
Correct |
2 ms |
852 KB |
n=2000 |
76 |
Correct |
4 ms |
980 KB |
n=2000 |
77 |
Correct |
3 ms |
852 KB |
n=2000 |
78 |
Correct |
3 ms |
852 KB |
n=2000 |
79 |
Correct |
3 ms |
852 KB |
n=2000 |
80 |
Correct |
3 ms |
980 KB |
n=2000 |
81 |
Correct |
3 ms |
980 KB |
n=2000 |
82 |
Correct |
4 ms |
852 KB |
n=2000 |
83 |
Correct |
3 ms |
980 KB |
n=2000 |
84 |
Correct |
4 ms |
852 KB |
n=2000 |
85 |
Correct |
3 ms |
980 KB |
n=2000 |
86 |
Correct |
3 ms |
852 KB |
n=2000 |
87 |
Correct |
3 ms |
852 KB |
n=2000 |
88 |
Correct |
3 ms |
980 KB |
n=2000 |
89 |
Correct |
3 ms |
980 KB |
n=2000 |
90 |
Correct |
3 ms |
1108 KB |
n=2000 |
91 |
Correct |
3 ms |
852 KB |
n=2000 |
92 |
Correct |
702 ms |
64024 KB |
n=200000 |
93 |
Correct |
920 ms |
72492 KB |
n=200000 |
94 |
Correct |
908 ms |
79152 KB |
n=200000 |
95 |
Correct |
647 ms |
63936 KB |
n=200000 |
96 |
Correct |
638 ms |
63908 KB |
n=200000 |
97 |
Correct |
876 ms |
70560 KB |
n=200000 |
98 |
Correct |
678 ms |
63956 KB |
n=200000 |
99 |
Correct |
804 ms |
63396 KB |
n=200000 |
100 |
Correct |
778 ms |
63972 KB |
n=200000 |
101 |
Correct |
1024 ms |
81636 KB |
n=200000 |
102 |
Correct |
447 ms |
64876 KB |
n=200000 |
103 |
Correct |
424 ms |
64924 KB |
n=200000 |
104 |
Correct |
444 ms |
64936 KB |
n=200000 |
105 |
Correct |
487 ms |
64624 KB |
n=200000 |
106 |
Correct |
438 ms |
64632 KB |
n=200000 |
107 |
Correct |
383 ms |
64676 KB |
n=200000 |
108 |
Correct |
921 ms |
63628 KB |
n=200000 |
109 |
Correct |
798 ms |
63612 KB |
n=200000 |
110 |
Correct |
900 ms |
63600 KB |
n=200000 |
111 |
Correct |
618 ms |
63872 KB |
n=200000 |
112 |
Correct |
999 ms |
79692 KB |
n=200000 |
113 |
Correct |
1069 ms |
70596 KB |
n=200000 |
114 |
Correct |
721 ms |
63860 KB |
n=200000 |
115 |
Correct |
1099 ms |
66320 KB |
n=200000 |
116 |
Correct |
675 ms |
63708 KB |
n=200000 |
117 |
Correct |
867 ms |
80536 KB |
n=200000 |
118 |
Correct |
957 ms |
68516 KB |
n=200000 |
119 |
Correct |
647 ms |
63652 KB |
n=200000 |
120 |
Correct |
837 ms |
81484 KB |
n=200000 |
121 |
Correct |
848 ms |
81440 KB |
n=200000 |
122 |
Correct |
952 ms |
81960 KB |
n=200000 |
123 |
Correct |
448 ms |
64388 KB |
n=200000 |
124 |
Correct |
171 ms |
17140 KB |
n=25264 |