#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 < N) {
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 |
14584 KB |
n=5 |
2 |
Correct |
15 ms |
14584 KB |
n=100 |
3 |
Correct |
15 ms |
14584 KB |
n=100 |
4 |
Correct |
15 ms |
14584 KB |
n=100 |
5 |
Correct |
15 ms |
14584 KB |
n=100 |
6 |
Correct |
15 ms |
14584 KB |
n=100 |
7 |
Correct |
15 ms |
14584 KB |
n=100 |
8 |
Correct |
14 ms |
14584 KB |
n=100 |
9 |
Correct |
15 ms |
14540 KB |
n=100 |
10 |
Correct |
15 ms |
14584 KB |
n=100 |
11 |
Correct |
15 ms |
14608 KB |
n=100 |
12 |
Correct |
15 ms |
14584 KB |
n=100 |
13 |
Correct |
15 ms |
14712 KB |
n=100 |
14 |
Correct |
15 ms |
14584 KB |
n=100 |
15 |
Correct |
15 ms |
14584 KB |
n=100 |
16 |
Correct |
15 ms |
14584 KB |
n=100 |
17 |
Correct |
15 ms |
14584 KB |
n=100 |
18 |
Correct |
15 ms |
14584 KB |
n=100 |
19 |
Correct |
15 ms |
14584 KB |
n=100 |
20 |
Correct |
15 ms |
14584 KB |
n=100 |
21 |
Correct |
14 ms |
14584 KB |
n=100 |
22 |
Correct |
15 ms |
14584 KB |
n=100 |
23 |
Correct |
15 ms |
14584 KB |
n=100 |
24 |
Correct |
15 ms |
14584 KB |
n=100 |
25 |
Correct |
15 ms |
14584 KB |
n=100 |
26 |
Runtime error |
36 ms |
29432 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
14584 KB |
n=5 |
2 |
Correct |
15 ms |
14584 KB |
n=100 |
3 |
Correct |
15 ms |
14584 KB |
n=100 |
4 |
Correct |
15 ms |
14584 KB |
n=100 |
5 |
Correct |
15 ms |
14584 KB |
n=100 |
6 |
Correct |
15 ms |
14584 KB |
n=100 |
7 |
Correct |
15 ms |
14584 KB |
n=100 |
8 |
Correct |
14 ms |
14584 KB |
n=100 |
9 |
Correct |
15 ms |
14540 KB |
n=100 |
10 |
Correct |
15 ms |
14584 KB |
n=100 |
11 |
Correct |
15 ms |
14608 KB |
n=100 |
12 |
Correct |
15 ms |
14584 KB |
n=100 |
13 |
Correct |
15 ms |
14712 KB |
n=100 |
14 |
Correct |
15 ms |
14584 KB |
n=100 |
15 |
Correct |
15 ms |
14584 KB |
n=100 |
16 |
Correct |
15 ms |
14584 KB |
n=100 |
17 |
Correct |
15 ms |
14584 KB |
n=100 |
18 |
Correct |
15 ms |
14584 KB |
n=100 |
19 |
Correct |
15 ms |
14584 KB |
n=100 |
20 |
Correct |
15 ms |
14584 KB |
n=100 |
21 |
Correct |
14 ms |
14584 KB |
n=100 |
22 |
Correct |
15 ms |
14584 KB |
n=100 |
23 |
Correct |
15 ms |
14584 KB |
n=100 |
24 |
Correct |
15 ms |
14584 KB |
n=100 |
25 |
Correct |
15 ms |
14584 KB |
n=100 |
26 |
Runtime error |
36 ms |
29432 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
14584 KB |
n=5 |
2 |
Correct |
15 ms |
14584 KB |
n=100 |
3 |
Correct |
15 ms |
14584 KB |
n=100 |
4 |
Correct |
15 ms |
14584 KB |
n=100 |
5 |
Correct |
15 ms |
14584 KB |
n=100 |
6 |
Correct |
15 ms |
14584 KB |
n=100 |
7 |
Correct |
15 ms |
14584 KB |
n=100 |
8 |
Correct |
14 ms |
14584 KB |
n=100 |
9 |
Correct |
15 ms |
14540 KB |
n=100 |
10 |
Correct |
15 ms |
14584 KB |
n=100 |
11 |
Correct |
15 ms |
14608 KB |
n=100 |
12 |
Correct |
15 ms |
14584 KB |
n=100 |
13 |
Correct |
15 ms |
14712 KB |
n=100 |
14 |
Correct |
15 ms |
14584 KB |
n=100 |
15 |
Correct |
15 ms |
14584 KB |
n=100 |
16 |
Correct |
15 ms |
14584 KB |
n=100 |
17 |
Correct |
15 ms |
14584 KB |
n=100 |
18 |
Correct |
15 ms |
14584 KB |
n=100 |
19 |
Correct |
15 ms |
14584 KB |
n=100 |
20 |
Correct |
15 ms |
14584 KB |
n=100 |
21 |
Correct |
14 ms |
14584 KB |
n=100 |
22 |
Correct |
15 ms |
14584 KB |
n=100 |
23 |
Correct |
15 ms |
14584 KB |
n=100 |
24 |
Correct |
15 ms |
14584 KB |
n=100 |
25 |
Correct |
15 ms |
14584 KB |
n=100 |
26 |
Runtime error |
36 ms |
29432 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
14584 KB |
n=5 |
2 |
Correct |
15 ms |
14584 KB |
n=100 |
3 |
Correct |
15 ms |
14584 KB |
n=100 |
4 |
Correct |
15 ms |
14584 KB |
n=100 |
5 |
Correct |
15 ms |
14584 KB |
n=100 |
6 |
Correct |
15 ms |
14584 KB |
n=100 |
7 |
Correct |
15 ms |
14584 KB |
n=100 |
8 |
Correct |
14 ms |
14584 KB |
n=100 |
9 |
Correct |
15 ms |
14540 KB |
n=100 |
10 |
Correct |
15 ms |
14584 KB |
n=100 |
11 |
Correct |
15 ms |
14608 KB |
n=100 |
12 |
Correct |
15 ms |
14584 KB |
n=100 |
13 |
Correct |
15 ms |
14712 KB |
n=100 |
14 |
Correct |
15 ms |
14584 KB |
n=100 |
15 |
Correct |
15 ms |
14584 KB |
n=100 |
16 |
Correct |
15 ms |
14584 KB |
n=100 |
17 |
Correct |
15 ms |
14584 KB |
n=100 |
18 |
Correct |
15 ms |
14584 KB |
n=100 |
19 |
Correct |
15 ms |
14584 KB |
n=100 |
20 |
Correct |
15 ms |
14584 KB |
n=100 |
21 |
Correct |
14 ms |
14584 KB |
n=100 |
22 |
Correct |
15 ms |
14584 KB |
n=100 |
23 |
Correct |
15 ms |
14584 KB |
n=100 |
24 |
Correct |
15 ms |
14584 KB |
n=100 |
25 |
Correct |
15 ms |
14584 KB |
n=100 |
26 |
Runtime error |
36 ms |
29432 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
27 |
Halted |
0 ms |
0 KB |
- |