#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORA(i, a) for (auto &i : a)
#define FORB(i, a, b) for (int i = a; i >= b; --i)
#define SZ(a) ((int) a.size())
#define ALL(a) a.begin(), a.end()
const int MAXN = 200007, LOG = 19;
set<pair<int, int>> pairs[MAXN];
vector<int> G[MAXN];
int anc[LOG][MAXN], dep[MAXN], A[MAXN];
int N, M, Q;
int get_lca(int u, int v)
{
if (dep[u] < dep[v]) swap(u, v);
FORB(j, LOG - 1, 0) if (dep[u] - (1 << j) >= dep[v]) u = anc[j][u];
if (u == v) return u;
FORB(j, LOG - 1, 0) if (anc[j][u] != anc[j][v]) u = anc[j][u], v = anc[j][v];
return anc[0][u];
}
void dfs(int u, int p)
{
for (int v : G[u]) if (v != p) {
anc[0][v] = u;
FOR(i, 1, LOG - 1) anc[i][v] = anc[i - 1][anc[i - 1][v]];
dep[v] = dep[u] + 1;
dfs(v, u);
}
}
void rem(int u, int i, int j)
{
pairs[u].erase(pairs[u].find(pair<int, int>(i, j)));
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> N >> M >> Q;
FOR(_, 0, N - 2) {
int u, v;
cin >> u >> v;
G[u].push_back(v);
G[v].push_back(u);
}
dfs(1, 0);
FOR(i, 1, M) cin >> A[i];
FOR(i, 1, M) pairs[A[i]].emplace(i, i);
FOR(i, 1, M - 1) pairs[get_lca(A[i], A[i + 1])].emplace(i, i + 1);
FOR(_, 0, Q - 1) {
int type;
cin >> type;
if (type == 1) {
int i, u;
cin >> i >> u;
rem(A[i], i, i);
pairs[u].emplace(i, i);
if (i > 1) {
rem(get_lca(A[i - 1], A[i]), i - 1, i);
pairs[get_lca(A[i - 1], u)].emplace(i - 1, i);
}
if (i < M) {
rem(get_lca(A[i], A[i + 1]), i, i + 1);
pairs[get_lca(u, A[i + 1])].emplace(i, i + 1);
}
A[i] = u;
} else {
int l, r, u;
cin >> l >> r >> u;
auto it = pairs[u].lower_bound(pair<int, int>(l, l));
if (it == pairs[u].end() || it->second > r) {
cout << "-1 -1\n";
} else {
cout << it->first << ' ' << it->second << '\n';
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
14456 KB |
n=5 |
2 |
Correct |
14 ms |
14556 KB |
n=100 |
3 |
Correct |
15 ms |
14584 KB |
n=100 |
4 |
Correct |
14 ms |
14588 KB |
n=100 |
5 |
Correct |
15 ms |
14712 KB |
n=100 |
6 |
Correct |
14 ms |
14584 KB |
n=100 |
7 |
Correct |
15 ms |
14596 KB |
n=100 |
8 |
Correct |
14 ms |
14584 KB |
n=100 |
9 |
Correct |
15 ms |
14556 KB |
n=100 |
10 |
Correct |
15 ms |
14588 KB |
n=100 |
11 |
Correct |
15 ms |
14584 KB |
n=100 |
12 |
Correct |
15 ms |
14584 KB |
n=100 |
13 |
Correct |
15 ms |
14584 KB |
n=100 |
14 |
Correct |
15 ms |
14588 KB |
n=100 |
15 |
Correct |
14 ms |
14584 KB |
n=100 |
16 |
Correct |
15 ms |
14588 KB |
n=100 |
17 |
Correct |
15 ms |
14584 KB |
n=100 |
18 |
Correct |
14 ms |
14584 KB |
n=100 |
19 |
Correct |
14 ms |
14588 KB |
n=100 |
20 |
Correct |
15 ms |
14584 KB |
n=100 |
21 |
Correct |
15 ms |
14520 KB |
n=100 |
22 |
Correct |
15 ms |
14584 KB |
n=100 |
23 |
Correct |
15 ms |
14556 KB |
n=100 |
24 |
Correct |
14 ms |
14584 KB |
n=100 |
25 |
Correct |
14 ms |
14584 KB |
n=100 |
26 |
Correct |
14 ms |
14584 KB |
n=12 |
27 |
Correct |
17 ms |
14648 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
14456 KB |
n=5 |
2 |
Correct |
14 ms |
14556 KB |
n=100 |
3 |
Correct |
15 ms |
14584 KB |
n=100 |
4 |
Correct |
14 ms |
14588 KB |
n=100 |
5 |
Correct |
15 ms |
14712 KB |
n=100 |
6 |
Correct |
14 ms |
14584 KB |
n=100 |
7 |
Correct |
15 ms |
14596 KB |
n=100 |
8 |
Correct |
14 ms |
14584 KB |
n=100 |
9 |
Correct |
15 ms |
14556 KB |
n=100 |
10 |
Correct |
15 ms |
14588 KB |
n=100 |
11 |
Correct |
15 ms |
14584 KB |
n=100 |
12 |
Correct |
15 ms |
14584 KB |
n=100 |
13 |
Correct |
15 ms |
14584 KB |
n=100 |
14 |
Correct |
15 ms |
14588 KB |
n=100 |
15 |
Correct |
14 ms |
14584 KB |
n=100 |
16 |
Correct |
15 ms |
14588 KB |
n=100 |
17 |
Correct |
15 ms |
14584 KB |
n=100 |
18 |
Correct |
14 ms |
14584 KB |
n=100 |
19 |
Correct |
14 ms |
14588 KB |
n=100 |
20 |
Correct |
15 ms |
14584 KB |
n=100 |
21 |
Correct |
15 ms |
14520 KB |
n=100 |
22 |
Correct |
15 ms |
14584 KB |
n=100 |
23 |
Correct |
15 ms |
14556 KB |
n=100 |
24 |
Correct |
14 ms |
14584 KB |
n=100 |
25 |
Correct |
14 ms |
14584 KB |
n=100 |
26 |
Correct |
14 ms |
14584 KB |
n=12 |
27 |
Correct |
17 ms |
14648 KB |
n=100 |
28 |
Correct |
16 ms |
14740 KB |
n=500 |
29 |
Correct |
16 ms |
14712 KB |
n=500 |
30 |
Correct |
15 ms |
14712 KB |
n=500 |
31 |
Correct |
15 ms |
14712 KB |
n=500 |
32 |
Correct |
15 ms |
14584 KB |
n=500 |
33 |
Correct |
16 ms |
14720 KB |
n=500 |
34 |
Correct |
15 ms |
14712 KB |
n=500 |
35 |
Correct |
16 ms |
14712 KB |
n=500 |
36 |
Correct |
15 ms |
14712 KB |
n=500 |
37 |
Correct |
15 ms |
14712 KB |
n=500 |
38 |
Correct |
15 ms |
14584 KB |
n=500 |
39 |
Correct |
15 ms |
14584 KB |
n=500 |
40 |
Correct |
15 ms |
14584 KB |
n=500 |
41 |
Correct |
15 ms |
14712 KB |
n=500 |
42 |
Correct |
16 ms |
14716 KB |
n=500 |
43 |
Correct |
16 ms |
14584 KB |
n=500 |
44 |
Correct |
16 ms |
14712 KB |
n=500 |
45 |
Correct |
16 ms |
14584 KB |
n=500 |
46 |
Correct |
16 ms |
14712 KB |
n=500 |
47 |
Correct |
15 ms |
14712 KB |
n=500 |
48 |
Correct |
16 ms |
14712 KB |
n=500 |
49 |
Correct |
15 ms |
14712 KB |
n=500 |
50 |
Correct |
16 ms |
14712 KB |
n=500 |
51 |
Correct |
16 ms |
14712 KB |
n=500 |
52 |
Correct |
15 ms |
14712 KB |
n=500 |
53 |
Correct |
16 ms |
14584 KB |
n=500 |
54 |
Correct |
15 ms |
14712 KB |
n=500 |
55 |
Correct |
15 ms |
14584 KB |
n=278 |
56 |
Correct |
15 ms |
14712 KB |
n=500 |
57 |
Correct |
15 ms |
14712 KB |
n=500 |
58 |
Correct |
15 ms |
14588 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
14456 KB |
n=5 |
2 |
Correct |
14 ms |
14556 KB |
n=100 |
3 |
Correct |
15 ms |
14584 KB |
n=100 |
4 |
Correct |
14 ms |
14588 KB |
n=100 |
5 |
Correct |
15 ms |
14712 KB |
n=100 |
6 |
Correct |
14 ms |
14584 KB |
n=100 |
7 |
Correct |
15 ms |
14596 KB |
n=100 |
8 |
Correct |
14 ms |
14584 KB |
n=100 |
9 |
Correct |
15 ms |
14556 KB |
n=100 |
10 |
Correct |
15 ms |
14588 KB |
n=100 |
11 |
Correct |
15 ms |
14584 KB |
n=100 |
12 |
Correct |
15 ms |
14584 KB |
n=100 |
13 |
Correct |
15 ms |
14584 KB |
n=100 |
14 |
Correct |
15 ms |
14588 KB |
n=100 |
15 |
Correct |
14 ms |
14584 KB |
n=100 |
16 |
Correct |
15 ms |
14588 KB |
n=100 |
17 |
Correct |
15 ms |
14584 KB |
n=100 |
18 |
Correct |
14 ms |
14584 KB |
n=100 |
19 |
Correct |
14 ms |
14588 KB |
n=100 |
20 |
Correct |
15 ms |
14584 KB |
n=100 |
21 |
Correct |
15 ms |
14520 KB |
n=100 |
22 |
Correct |
15 ms |
14584 KB |
n=100 |
23 |
Correct |
15 ms |
14556 KB |
n=100 |
24 |
Correct |
14 ms |
14584 KB |
n=100 |
25 |
Correct |
14 ms |
14584 KB |
n=100 |
26 |
Correct |
14 ms |
14584 KB |
n=12 |
27 |
Correct |
17 ms |
14648 KB |
n=100 |
28 |
Correct |
16 ms |
14740 KB |
n=500 |
29 |
Correct |
16 ms |
14712 KB |
n=500 |
30 |
Correct |
15 ms |
14712 KB |
n=500 |
31 |
Correct |
15 ms |
14712 KB |
n=500 |
32 |
Correct |
15 ms |
14584 KB |
n=500 |
33 |
Correct |
16 ms |
14720 KB |
n=500 |
34 |
Correct |
15 ms |
14712 KB |
n=500 |
35 |
Correct |
16 ms |
14712 KB |
n=500 |
36 |
Correct |
15 ms |
14712 KB |
n=500 |
37 |
Correct |
15 ms |
14712 KB |
n=500 |
38 |
Correct |
15 ms |
14584 KB |
n=500 |
39 |
Correct |
15 ms |
14584 KB |
n=500 |
40 |
Correct |
15 ms |
14584 KB |
n=500 |
41 |
Correct |
15 ms |
14712 KB |
n=500 |
42 |
Correct |
16 ms |
14716 KB |
n=500 |
43 |
Correct |
16 ms |
14584 KB |
n=500 |
44 |
Correct |
16 ms |
14712 KB |
n=500 |
45 |
Correct |
16 ms |
14584 KB |
n=500 |
46 |
Correct |
16 ms |
14712 KB |
n=500 |
47 |
Correct |
15 ms |
14712 KB |
n=500 |
48 |
Correct |
16 ms |
14712 KB |
n=500 |
49 |
Correct |
15 ms |
14712 KB |
n=500 |
50 |
Correct |
16 ms |
14712 KB |
n=500 |
51 |
Correct |
16 ms |
14712 KB |
n=500 |
52 |
Correct |
15 ms |
14712 KB |
n=500 |
53 |
Correct |
16 ms |
14584 KB |
n=500 |
54 |
Correct |
15 ms |
14712 KB |
n=500 |
55 |
Correct |
15 ms |
14584 KB |
n=278 |
56 |
Correct |
15 ms |
14712 KB |
n=500 |
57 |
Correct |
15 ms |
14712 KB |
n=500 |
58 |
Correct |
15 ms |
14588 KB |
n=500 |
59 |
Correct |
19 ms |
15096 KB |
n=2000 |
60 |
Correct |
19 ms |
15096 KB |
n=2000 |
61 |
Correct |
19 ms |
15096 KB |
n=2000 |
62 |
Correct |
19 ms |
15096 KB |
n=2000 |
63 |
Correct |
19 ms |
15000 KB |
n=2000 |
64 |
Correct |
19 ms |
15224 KB |
n=2000 |
65 |
Correct |
19 ms |
14968 KB |
n=2000 |
66 |
Correct |
19 ms |
15096 KB |
n=2000 |
67 |
Correct |
20 ms |
15096 KB |
n=2000 |
68 |
Correct |
19 ms |
15096 KB |
n=2000 |
69 |
Correct |
18 ms |
15096 KB |
n=2000 |
70 |
Correct |
18 ms |
14968 KB |
n=2000 |
71 |
Correct |
18 ms |
14968 KB |
n=2000 |
72 |
Correct |
17 ms |
14996 KB |
n=2000 |
73 |
Correct |
17 ms |
14968 KB |
n=2000 |
74 |
Correct |
18 ms |
14972 KB |
n=1844 |
75 |
Correct |
17 ms |
14968 KB |
n=2000 |
76 |
Correct |
19 ms |
14968 KB |
n=2000 |
77 |
Correct |
19 ms |
15096 KB |
n=2000 |
78 |
Correct |
19 ms |
15068 KB |
n=2000 |
79 |
Correct |
19 ms |
14968 KB |
n=2000 |
80 |
Correct |
18 ms |
15096 KB |
n=2000 |
81 |
Correct |
19 ms |
15072 KB |
n=2000 |
82 |
Correct |
19 ms |
15096 KB |
n=2000 |
83 |
Correct |
19 ms |
15096 KB |
n=2000 |
84 |
Correct |
19 ms |
15096 KB |
n=2000 |
85 |
Correct |
19 ms |
15096 KB |
n=2000 |
86 |
Correct |
19 ms |
14968 KB |
n=2000 |
87 |
Correct |
19 ms |
15096 KB |
n=2000 |
88 |
Correct |
18 ms |
15096 KB |
n=2000 |
89 |
Correct |
19 ms |
15096 KB |
n=2000 |
90 |
Correct |
19 ms |
15096 KB |
n=2000 |
91 |
Correct |
18 ms |
15096 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
14456 KB |
n=5 |
2 |
Correct |
14 ms |
14556 KB |
n=100 |
3 |
Correct |
15 ms |
14584 KB |
n=100 |
4 |
Correct |
14 ms |
14588 KB |
n=100 |
5 |
Correct |
15 ms |
14712 KB |
n=100 |
6 |
Correct |
14 ms |
14584 KB |
n=100 |
7 |
Correct |
15 ms |
14596 KB |
n=100 |
8 |
Correct |
14 ms |
14584 KB |
n=100 |
9 |
Correct |
15 ms |
14556 KB |
n=100 |
10 |
Correct |
15 ms |
14588 KB |
n=100 |
11 |
Correct |
15 ms |
14584 KB |
n=100 |
12 |
Correct |
15 ms |
14584 KB |
n=100 |
13 |
Correct |
15 ms |
14584 KB |
n=100 |
14 |
Correct |
15 ms |
14588 KB |
n=100 |
15 |
Correct |
14 ms |
14584 KB |
n=100 |
16 |
Correct |
15 ms |
14588 KB |
n=100 |
17 |
Correct |
15 ms |
14584 KB |
n=100 |
18 |
Correct |
14 ms |
14584 KB |
n=100 |
19 |
Correct |
14 ms |
14588 KB |
n=100 |
20 |
Correct |
15 ms |
14584 KB |
n=100 |
21 |
Correct |
15 ms |
14520 KB |
n=100 |
22 |
Correct |
15 ms |
14584 KB |
n=100 |
23 |
Correct |
15 ms |
14556 KB |
n=100 |
24 |
Correct |
14 ms |
14584 KB |
n=100 |
25 |
Correct |
14 ms |
14584 KB |
n=100 |
26 |
Correct |
14 ms |
14584 KB |
n=12 |
27 |
Correct |
17 ms |
14648 KB |
n=100 |
28 |
Correct |
16 ms |
14740 KB |
n=500 |
29 |
Correct |
16 ms |
14712 KB |
n=500 |
30 |
Correct |
15 ms |
14712 KB |
n=500 |
31 |
Correct |
15 ms |
14712 KB |
n=500 |
32 |
Correct |
15 ms |
14584 KB |
n=500 |
33 |
Correct |
16 ms |
14720 KB |
n=500 |
34 |
Correct |
15 ms |
14712 KB |
n=500 |
35 |
Correct |
16 ms |
14712 KB |
n=500 |
36 |
Correct |
15 ms |
14712 KB |
n=500 |
37 |
Correct |
15 ms |
14712 KB |
n=500 |
38 |
Correct |
15 ms |
14584 KB |
n=500 |
39 |
Correct |
15 ms |
14584 KB |
n=500 |
40 |
Correct |
15 ms |
14584 KB |
n=500 |
41 |
Correct |
15 ms |
14712 KB |
n=500 |
42 |
Correct |
16 ms |
14716 KB |
n=500 |
43 |
Correct |
16 ms |
14584 KB |
n=500 |
44 |
Correct |
16 ms |
14712 KB |
n=500 |
45 |
Correct |
16 ms |
14584 KB |
n=500 |
46 |
Correct |
16 ms |
14712 KB |
n=500 |
47 |
Correct |
15 ms |
14712 KB |
n=500 |
48 |
Correct |
16 ms |
14712 KB |
n=500 |
49 |
Correct |
15 ms |
14712 KB |
n=500 |
50 |
Correct |
16 ms |
14712 KB |
n=500 |
51 |
Correct |
16 ms |
14712 KB |
n=500 |
52 |
Correct |
15 ms |
14712 KB |
n=500 |
53 |
Correct |
16 ms |
14584 KB |
n=500 |
54 |
Correct |
15 ms |
14712 KB |
n=500 |
55 |
Correct |
15 ms |
14584 KB |
n=278 |
56 |
Correct |
15 ms |
14712 KB |
n=500 |
57 |
Correct |
15 ms |
14712 KB |
n=500 |
58 |
Correct |
15 ms |
14588 KB |
n=500 |
59 |
Correct |
19 ms |
15096 KB |
n=2000 |
60 |
Correct |
19 ms |
15096 KB |
n=2000 |
61 |
Correct |
19 ms |
15096 KB |
n=2000 |
62 |
Correct |
19 ms |
15096 KB |
n=2000 |
63 |
Correct |
19 ms |
15000 KB |
n=2000 |
64 |
Correct |
19 ms |
15224 KB |
n=2000 |
65 |
Correct |
19 ms |
14968 KB |
n=2000 |
66 |
Correct |
19 ms |
15096 KB |
n=2000 |
67 |
Correct |
20 ms |
15096 KB |
n=2000 |
68 |
Correct |
19 ms |
15096 KB |
n=2000 |
69 |
Correct |
18 ms |
15096 KB |
n=2000 |
70 |
Correct |
18 ms |
14968 KB |
n=2000 |
71 |
Correct |
18 ms |
14968 KB |
n=2000 |
72 |
Correct |
17 ms |
14996 KB |
n=2000 |
73 |
Correct |
17 ms |
14968 KB |
n=2000 |
74 |
Correct |
18 ms |
14972 KB |
n=1844 |
75 |
Correct |
17 ms |
14968 KB |
n=2000 |
76 |
Correct |
19 ms |
14968 KB |
n=2000 |
77 |
Correct |
19 ms |
15096 KB |
n=2000 |
78 |
Correct |
19 ms |
15068 KB |
n=2000 |
79 |
Correct |
19 ms |
14968 KB |
n=2000 |
80 |
Correct |
18 ms |
15096 KB |
n=2000 |
81 |
Correct |
19 ms |
15072 KB |
n=2000 |
82 |
Correct |
19 ms |
15096 KB |
n=2000 |
83 |
Correct |
19 ms |
15096 KB |
n=2000 |
84 |
Correct |
19 ms |
15096 KB |
n=2000 |
85 |
Correct |
19 ms |
15096 KB |
n=2000 |
86 |
Correct |
19 ms |
14968 KB |
n=2000 |
87 |
Correct |
19 ms |
15096 KB |
n=2000 |
88 |
Correct |
18 ms |
15096 KB |
n=2000 |
89 |
Correct |
19 ms |
15096 KB |
n=2000 |
90 |
Correct |
19 ms |
15096 KB |
n=2000 |
91 |
Correct |
18 ms |
15096 KB |
n=2000 |
92 |
Correct |
1033 ms |
61008 KB |
n=200000 |
93 |
Correct |
1274 ms |
63928 KB |
n=200000 |
94 |
Correct |
1232 ms |
67340 KB |
n=200000 |
95 |
Correct |
999 ms |
61804 KB |
n=200000 |
96 |
Correct |
937 ms |
61960 KB |
n=200000 |
97 |
Correct |
1255 ms |
63100 KB |
n=200000 |
98 |
Correct |
1133 ms |
62400 KB |
n=200000 |
99 |
Correct |
1191 ms |
59560 KB |
n=200000 |
100 |
Correct |
995 ms |
63540 KB |
n=200000 |
101 |
Correct |
1242 ms |
68600 KB |
n=200000 |
102 |
Correct |
582 ms |
61148 KB |
n=200000 |
103 |
Correct |
562 ms |
61168 KB |
n=200000 |
104 |
Correct |
557 ms |
61096 KB |
n=200000 |
105 |
Correct |
582 ms |
60792 KB |
n=200000 |
106 |
Correct |
607 ms |
61100 KB |
n=200000 |
107 |
Correct |
696 ms |
60948 KB |
n=200000 |
108 |
Correct |
1133 ms |
59768 KB |
n=200000 |
109 |
Correct |
1075 ms |
60012 KB |
n=200000 |
110 |
Correct |
1044 ms |
59896 KB |
n=200000 |
111 |
Correct |
949 ms |
63192 KB |
n=200000 |
112 |
Correct |
1195 ms |
67584 KB |
n=200000 |
113 |
Correct |
1439 ms |
62984 KB |
n=200000 |
114 |
Correct |
1018 ms |
63048 KB |
n=200000 |
115 |
Correct |
1366 ms |
60936 KB |
n=200000 |
116 |
Correct |
923 ms |
62268 KB |
n=200000 |
117 |
Correct |
1146 ms |
67844 KB |
n=200000 |
118 |
Correct |
1306 ms |
61952 KB |
n=200000 |
119 |
Correct |
872 ms |
60000 KB |
n=200000 |
120 |
Correct |
1092 ms |
68216 KB |
n=200000 |
121 |
Correct |
1123 ms |
68188 KB |
n=200000 |
122 |
Correct |
1102 ms |
68444 KB |
n=200000 |
123 |
Correct |
575 ms |
60152 KB |
n=200000 |
124 |
Correct |
258 ms |
29344 KB |
n=25264 |