// 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 up[nax][LG];
int dep[nax];
V<int> adj[nax];
int jmp(int u, int d) {
for(int i = 0; i < LG; i++) if ((d >> i) & 1) {
u = up[u][i];
}
return u;
}
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];
}
void 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);
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int N, M, Q; cin >> N >> M >> Q;
for(int _ = 0; _ < N-1; _++) {
int u, v; cin >> u >> v; --u, --v;
adj[u].pb(v);
adj[v].pb(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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
n=5 |
2 |
Correct |
2 ms |
4948 KB |
n=100 |
3 |
Correct |
2 ms |
4948 KB |
n=100 |
4 |
Correct |
2 ms |
4948 KB |
n=100 |
5 |
Correct |
2 ms |
4948 KB |
n=100 |
6 |
Correct |
2 ms |
4948 KB |
n=100 |
7 |
Correct |
2 ms |
4948 KB |
n=100 |
8 |
Correct |
2 ms |
4948 KB |
n=100 |
9 |
Correct |
2 ms |
4948 KB |
n=100 |
10 |
Correct |
3 ms |
4992 KB |
n=100 |
11 |
Correct |
2 ms |
4948 KB |
n=100 |
12 |
Correct |
2 ms |
4948 KB |
n=100 |
13 |
Correct |
3 ms |
4948 KB |
n=100 |
14 |
Correct |
2 ms |
4948 KB |
n=100 |
15 |
Correct |
2 ms |
4948 KB |
n=100 |
16 |
Correct |
3 ms |
4948 KB |
n=100 |
17 |
Correct |
2 ms |
4948 KB |
n=100 |
18 |
Correct |
2 ms |
4948 KB |
n=100 |
19 |
Correct |
2 ms |
4948 KB |
n=100 |
20 |
Correct |
2 ms |
4948 KB |
n=100 |
21 |
Correct |
2 ms |
4948 KB |
n=100 |
22 |
Correct |
2 ms |
4948 KB |
n=100 |
23 |
Correct |
2 ms |
4948 KB |
n=100 |
24 |
Correct |
2 ms |
4948 KB |
n=100 |
25 |
Correct |
3 ms |
4948 KB |
n=100 |
26 |
Correct |
2 ms |
4948 KB |
n=12 |
27 |
Correct |
2 ms |
4948 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
n=5 |
2 |
Correct |
2 ms |
4948 KB |
n=100 |
3 |
Correct |
2 ms |
4948 KB |
n=100 |
4 |
Correct |
2 ms |
4948 KB |
n=100 |
5 |
Correct |
2 ms |
4948 KB |
n=100 |
6 |
Correct |
2 ms |
4948 KB |
n=100 |
7 |
Correct |
2 ms |
4948 KB |
n=100 |
8 |
Correct |
2 ms |
4948 KB |
n=100 |
9 |
Correct |
2 ms |
4948 KB |
n=100 |
10 |
Correct |
3 ms |
4992 KB |
n=100 |
11 |
Correct |
2 ms |
4948 KB |
n=100 |
12 |
Correct |
2 ms |
4948 KB |
n=100 |
13 |
Correct |
3 ms |
4948 KB |
n=100 |
14 |
Correct |
2 ms |
4948 KB |
n=100 |
15 |
Correct |
2 ms |
4948 KB |
n=100 |
16 |
Correct |
3 ms |
4948 KB |
n=100 |
17 |
Correct |
2 ms |
4948 KB |
n=100 |
18 |
Correct |
2 ms |
4948 KB |
n=100 |
19 |
Correct |
2 ms |
4948 KB |
n=100 |
20 |
Correct |
2 ms |
4948 KB |
n=100 |
21 |
Correct |
2 ms |
4948 KB |
n=100 |
22 |
Correct |
2 ms |
4948 KB |
n=100 |
23 |
Correct |
2 ms |
4948 KB |
n=100 |
24 |
Correct |
2 ms |
4948 KB |
n=100 |
25 |
Correct |
3 ms |
4948 KB |
n=100 |
26 |
Correct |
2 ms |
4948 KB |
n=12 |
27 |
Correct |
2 ms |
4948 KB |
n=100 |
28 |
Correct |
3 ms |
5076 KB |
n=500 |
29 |
Correct |
3 ms |
5076 KB |
n=500 |
30 |
Correct |
3 ms |
5076 KB |
n=500 |
31 |
Correct |
3 ms |
5076 KB |
n=500 |
32 |
Correct |
3 ms |
5076 KB |
n=500 |
33 |
Correct |
3 ms |
5076 KB |
n=500 |
34 |
Correct |
3 ms |
5156 KB |
n=500 |
35 |
Correct |
3 ms |
5076 KB |
n=500 |
36 |
Correct |
3 ms |
5076 KB |
n=500 |
37 |
Correct |
3 ms |
5076 KB |
n=500 |
38 |
Correct |
3 ms |
5076 KB |
n=500 |
39 |
Correct |
3 ms |
5076 KB |
n=500 |
40 |
Correct |
3 ms |
5076 KB |
n=500 |
41 |
Correct |
3 ms |
5076 KB |
n=500 |
42 |
Correct |
3 ms |
5076 KB |
n=500 |
43 |
Correct |
3 ms |
5076 KB |
n=500 |
44 |
Correct |
3 ms |
5076 KB |
n=500 |
45 |
Correct |
3 ms |
5076 KB |
n=500 |
46 |
Correct |
3 ms |
5076 KB |
n=500 |
47 |
Correct |
3 ms |
5076 KB |
n=500 |
48 |
Correct |
3 ms |
5076 KB |
n=500 |
49 |
Correct |
3 ms |
5076 KB |
n=500 |
50 |
Correct |
3 ms |
5204 KB |
n=500 |
51 |
Correct |
4 ms |
5076 KB |
n=500 |
52 |
Correct |
3 ms |
5076 KB |
n=500 |
53 |
Correct |
3 ms |
5116 KB |
n=500 |
54 |
Correct |
3 ms |
5076 KB |
n=500 |
55 |
Correct |
3 ms |
5076 KB |
n=278 |
56 |
Correct |
3 ms |
5076 KB |
n=500 |
57 |
Correct |
3 ms |
5076 KB |
n=500 |
58 |
Correct |
3 ms |
5076 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
n=5 |
2 |
Correct |
2 ms |
4948 KB |
n=100 |
3 |
Correct |
2 ms |
4948 KB |
n=100 |
4 |
Correct |
2 ms |
4948 KB |
n=100 |
5 |
Correct |
2 ms |
4948 KB |
n=100 |
6 |
Correct |
2 ms |
4948 KB |
n=100 |
7 |
Correct |
2 ms |
4948 KB |
n=100 |
8 |
Correct |
2 ms |
4948 KB |
n=100 |
9 |
Correct |
2 ms |
4948 KB |
n=100 |
10 |
Correct |
3 ms |
4992 KB |
n=100 |
11 |
Correct |
2 ms |
4948 KB |
n=100 |
12 |
Correct |
2 ms |
4948 KB |
n=100 |
13 |
Correct |
3 ms |
4948 KB |
n=100 |
14 |
Correct |
2 ms |
4948 KB |
n=100 |
15 |
Correct |
2 ms |
4948 KB |
n=100 |
16 |
Correct |
3 ms |
4948 KB |
n=100 |
17 |
Correct |
2 ms |
4948 KB |
n=100 |
18 |
Correct |
2 ms |
4948 KB |
n=100 |
19 |
Correct |
2 ms |
4948 KB |
n=100 |
20 |
Correct |
2 ms |
4948 KB |
n=100 |
21 |
Correct |
2 ms |
4948 KB |
n=100 |
22 |
Correct |
2 ms |
4948 KB |
n=100 |
23 |
Correct |
2 ms |
4948 KB |
n=100 |
24 |
Correct |
2 ms |
4948 KB |
n=100 |
25 |
Correct |
3 ms |
4948 KB |
n=100 |
26 |
Correct |
2 ms |
4948 KB |
n=12 |
27 |
Correct |
2 ms |
4948 KB |
n=100 |
28 |
Correct |
3 ms |
5076 KB |
n=500 |
29 |
Correct |
3 ms |
5076 KB |
n=500 |
30 |
Correct |
3 ms |
5076 KB |
n=500 |
31 |
Correct |
3 ms |
5076 KB |
n=500 |
32 |
Correct |
3 ms |
5076 KB |
n=500 |
33 |
Correct |
3 ms |
5076 KB |
n=500 |
34 |
Correct |
3 ms |
5156 KB |
n=500 |
35 |
Correct |
3 ms |
5076 KB |
n=500 |
36 |
Correct |
3 ms |
5076 KB |
n=500 |
37 |
Correct |
3 ms |
5076 KB |
n=500 |
38 |
Correct |
3 ms |
5076 KB |
n=500 |
39 |
Correct |
3 ms |
5076 KB |
n=500 |
40 |
Correct |
3 ms |
5076 KB |
n=500 |
41 |
Correct |
3 ms |
5076 KB |
n=500 |
42 |
Correct |
3 ms |
5076 KB |
n=500 |
43 |
Correct |
3 ms |
5076 KB |
n=500 |
44 |
Correct |
3 ms |
5076 KB |
n=500 |
45 |
Correct |
3 ms |
5076 KB |
n=500 |
46 |
Correct |
3 ms |
5076 KB |
n=500 |
47 |
Correct |
3 ms |
5076 KB |
n=500 |
48 |
Correct |
3 ms |
5076 KB |
n=500 |
49 |
Correct |
3 ms |
5076 KB |
n=500 |
50 |
Correct |
3 ms |
5204 KB |
n=500 |
51 |
Correct |
4 ms |
5076 KB |
n=500 |
52 |
Correct |
3 ms |
5076 KB |
n=500 |
53 |
Correct |
3 ms |
5116 KB |
n=500 |
54 |
Correct |
3 ms |
5076 KB |
n=500 |
55 |
Correct |
3 ms |
5076 KB |
n=278 |
56 |
Correct |
3 ms |
5076 KB |
n=500 |
57 |
Correct |
3 ms |
5076 KB |
n=500 |
58 |
Correct |
3 ms |
5076 KB |
n=500 |
59 |
Correct |
4 ms |
5460 KB |
n=2000 |
60 |
Correct |
5 ms |
5588 KB |
n=2000 |
61 |
Correct |
5 ms |
5588 KB |
n=2000 |
62 |
Correct |
5 ms |
5460 KB |
n=2000 |
63 |
Correct |
5 ms |
5460 KB |
n=2000 |
64 |
Correct |
4 ms |
5588 KB |
n=2000 |
65 |
Correct |
4 ms |
5460 KB |
n=2000 |
66 |
Correct |
4 ms |
5628 KB |
n=2000 |
67 |
Correct |
5 ms |
5460 KB |
n=2000 |
68 |
Correct |
7 ms |
5588 KB |
n=2000 |
69 |
Correct |
4 ms |
5460 KB |
n=2000 |
70 |
Correct |
6 ms |
5460 KB |
n=2000 |
71 |
Correct |
5 ms |
5556 KB |
n=2000 |
72 |
Correct |
4 ms |
5544 KB |
n=2000 |
73 |
Correct |
4 ms |
5460 KB |
n=2000 |
74 |
Correct |
8 ms |
5460 KB |
n=1844 |
75 |
Correct |
5 ms |
5460 KB |
n=2000 |
76 |
Correct |
7 ms |
5432 KB |
n=2000 |
77 |
Correct |
7 ms |
5460 KB |
n=2000 |
78 |
Correct |
4 ms |
5460 KB |
n=2000 |
79 |
Correct |
5 ms |
5460 KB |
n=2000 |
80 |
Correct |
5 ms |
5588 KB |
n=2000 |
81 |
Correct |
5 ms |
5588 KB |
n=2000 |
82 |
Correct |
4 ms |
5460 KB |
n=2000 |
83 |
Correct |
5 ms |
5576 KB |
n=2000 |
84 |
Correct |
4 ms |
5520 KB |
n=2000 |
85 |
Correct |
4 ms |
5580 KB |
n=2000 |
86 |
Correct |
4 ms |
5460 KB |
n=2000 |
87 |
Correct |
4 ms |
5460 KB |
n=2000 |
88 |
Correct |
5 ms |
5588 KB |
n=2000 |
89 |
Correct |
5 ms |
5588 KB |
n=2000 |
90 |
Correct |
4 ms |
5588 KB |
n=2000 |
91 |
Correct |
4 ms |
5460 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
n=5 |
2 |
Correct |
2 ms |
4948 KB |
n=100 |
3 |
Correct |
2 ms |
4948 KB |
n=100 |
4 |
Correct |
2 ms |
4948 KB |
n=100 |
5 |
Correct |
2 ms |
4948 KB |
n=100 |
6 |
Correct |
2 ms |
4948 KB |
n=100 |
7 |
Correct |
2 ms |
4948 KB |
n=100 |
8 |
Correct |
2 ms |
4948 KB |
n=100 |
9 |
Correct |
2 ms |
4948 KB |
n=100 |
10 |
Correct |
3 ms |
4992 KB |
n=100 |
11 |
Correct |
2 ms |
4948 KB |
n=100 |
12 |
Correct |
2 ms |
4948 KB |
n=100 |
13 |
Correct |
3 ms |
4948 KB |
n=100 |
14 |
Correct |
2 ms |
4948 KB |
n=100 |
15 |
Correct |
2 ms |
4948 KB |
n=100 |
16 |
Correct |
3 ms |
4948 KB |
n=100 |
17 |
Correct |
2 ms |
4948 KB |
n=100 |
18 |
Correct |
2 ms |
4948 KB |
n=100 |
19 |
Correct |
2 ms |
4948 KB |
n=100 |
20 |
Correct |
2 ms |
4948 KB |
n=100 |
21 |
Correct |
2 ms |
4948 KB |
n=100 |
22 |
Correct |
2 ms |
4948 KB |
n=100 |
23 |
Correct |
2 ms |
4948 KB |
n=100 |
24 |
Correct |
2 ms |
4948 KB |
n=100 |
25 |
Correct |
3 ms |
4948 KB |
n=100 |
26 |
Correct |
2 ms |
4948 KB |
n=12 |
27 |
Correct |
2 ms |
4948 KB |
n=100 |
28 |
Correct |
3 ms |
5076 KB |
n=500 |
29 |
Correct |
3 ms |
5076 KB |
n=500 |
30 |
Correct |
3 ms |
5076 KB |
n=500 |
31 |
Correct |
3 ms |
5076 KB |
n=500 |
32 |
Correct |
3 ms |
5076 KB |
n=500 |
33 |
Correct |
3 ms |
5076 KB |
n=500 |
34 |
Correct |
3 ms |
5156 KB |
n=500 |
35 |
Correct |
3 ms |
5076 KB |
n=500 |
36 |
Correct |
3 ms |
5076 KB |
n=500 |
37 |
Correct |
3 ms |
5076 KB |
n=500 |
38 |
Correct |
3 ms |
5076 KB |
n=500 |
39 |
Correct |
3 ms |
5076 KB |
n=500 |
40 |
Correct |
3 ms |
5076 KB |
n=500 |
41 |
Correct |
3 ms |
5076 KB |
n=500 |
42 |
Correct |
3 ms |
5076 KB |
n=500 |
43 |
Correct |
3 ms |
5076 KB |
n=500 |
44 |
Correct |
3 ms |
5076 KB |
n=500 |
45 |
Correct |
3 ms |
5076 KB |
n=500 |
46 |
Correct |
3 ms |
5076 KB |
n=500 |
47 |
Correct |
3 ms |
5076 KB |
n=500 |
48 |
Correct |
3 ms |
5076 KB |
n=500 |
49 |
Correct |
3 ms |
5076 KB |
n=500 |
50 |
Correct |
3 ms |
5204 KB |
n=500 |
51 |
Correct |
4 ms |
5076 KB |
n=500 |
52 |
Correct |
3 ms |
5076 KB |
n=500 |
53 |
Correct |
3 ms |
5116 KB |
n=500 |
54 |
Correct |
3 ms |
5076 KB |
n=500 |
55 |
Correct |
3 ms |
5076 KB |
n=278 |
56 |
Correct |
3 ms |
5076 KB |
n=500 |
57 |
Correct |
3 ms |
5076 KB |
n=500 |
58 |
Correct |
3 ms |
5076 KB |
n=500 |
59 |
Correct |
4 ms |
5460 KB |
n=2000 |
60 |
Correct |
5 ms |
5588 KB |
n=2000 |
61 |
Correct |
5 ms |
5588 KB |
n=2000 |
62 |
Correct |
5 ms |
5460 KB |
n=2000 |
63 |
Correct |
5 ms |
5460 KB |
n=2000 |
64 |
Correct |
4 ms |
5588 KB |
n=2000 |
65 |
Correct |
4 ms |
5460 KB |
n=2000 |
66 |
Correct |
4 ms |
5628 KB |
n=2000 |
67 |
Correct |
5 ms |
5460 KB |
n=2000 |
68 |
Correct |
7 ms |
5588 KB |
n=2000 |
69 |
Correct |
4 ms |
5460 KB |
n=2000 |
70 |
Correct |
6 ms |
5460 KB |
n=2000 |
71 |
Correct |
5 ms |
5556 KB |
n=2000 |
72 |
Correct |
4 ms |
5544 KB |
n=2000 |
73 |
Correct |
4 ms |
5460 KB |
n=2000 |
74 |
Correct |
8 ms |
5460 KB |
n=1844 |
75 |
Correct |
5 ms |
5460 KB |
n=2000 |
76 |
Correct |
7 ms |
5432 KB |
n=2000 |
77 |
Correct |
7 ms |
5460 KB |
n=2000 |
78 |
Correct |
4 ms |
5460 KB |
n=2000 |
79 |
Correct |
5 ms |
5460 KB |
n=2000 |
80 |
Correct |
5 ms |
5588 KB |
n=2000 |
81 |
Correct |
5 ms |
5588 KB |
n=2000 |
82 |
Correct |
4 ms |
5460 KB |
n=2000 |
83 |
Correct |
5 ms |
5576 KB |
n=2000 |
84 |
Correct |
4 ms |
5520 KB |
n=2000 |
85 |
Correct |
4 ms |
5580 KB |
n=2000 |
86 |
Correct |
4 ms |
5460 KB |
n=2000 |
87 |
Correct |
4 ms |
5460 KB |
n=2000 |
88 |
Correct |
5 ms |
5588 KB |
n=2000 |
89 |
Correct |
5 ms |
5588 KB |
n=2000 |
90 |
Correct |
4 ms |
5588 KB |
n=2000 |
91 |
Correct |
4 ms |
5460 KB |
n=2000 |
92 |
Correct |
552 ms |
57872 KB |
n=200000 |
93 |
Correct |
660 ms |
63112 KB |
n=200000 |
94 |
Correct |
638 ms |
67596 KB |
n=200000 |
95 |
Correct |
533 ms |
57692 KB |
n=200000 |
96 |
Correct |
560 ms |
57684 KB |
n=200000 |
97 |
Correct |
671 ms |
61900 KB |
n=200000 |
98 |
Correct |
549 ms |
57680 KB |
n=200000 |
99 |
Correct |
640 ms |
57116 KB |
n=200000 |
100 |
Correct |
553 ms |
57820 KB |
n=200000 |
101 |
Correct |
610 ms |
69208 KB |
n=200000 |
102 |
Correct |
312 ms |
58700 KB |
n=200000 |
103 |
Correct |
322 ms |
58616 KB |
n=200000 |
104 |
Correct |
323 ms |
58660 KB |
n=200000 |
105 |
Correct |
319 ms |
58572 KB |
n=200000 |
106 |
Correct |
308 ms |
58392 KB |
n=200000 |
107 |
Correct |
406 ms |
58352 KB |
n=200000 |
108 |
Correct |
653 ms |
57380 KB |
n=200000 |
109 |
Correct |
639 ms |
57416 KB |
n=200000 |
110 |
Correct |
654 ms |
57292 KB |
n=200000 |
111 |
Correct |
564 ms |
57624 KB |
n=200000 |
112 |
Correct |
694 ms |
67860 KB |
n=200000 |
113 |
Correct |
706 ms |
61824 KB |
n=200000 |
114 |
Correct |
598 ms |
57668 KB |
n=200000 |
115 |
Correct |
828 ms |
59000 KB |
n=200000 |
116 |
Correct |
654 ms |
57480 KB |
n=200000 |
117 |
Correct |
807 ms |
68440 KB |
n=200000 |
118 |
Correct |
839 ms |
60388 KB |
n=200000 |
119 |
Correct |
611 ms |
57396 KB |
n=200000 |
120 |
Correct |
765 ms |
68944 KB |
n=200000 |
121 |
Correct |
697 ms |
69004 KB |
n=200000 |
122 |
Correct |
705 ms |
69392 KB |
n=200000 |
123 |
Correct |
439 ms |
58052 KB |
n=200000 |
124 |
Correct |
130 ms |
19664 KB |
n=25264 |