#include "bits/stdc++.h"
using namespace std;
#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif
const int LOG = 20;
const int N = 2e5 + 5;
int a[N];
vector<int> g[N];
int dep[N], up[LOG][N];
set<int> lco[N], no[N];
void dfs(int v, int p) {
for (int u : g[v]) {
if (u == p) {
continue;
}
dep[u] = dep[v] + 1;
up[0][u] = v;
for (int j = 1; j < LOG; ++j) {
up[j][u] = up[j - 1][up[j - 1][u]];
}
dfs(u, v);
}
}
int lca(int u, int v) {
if (dep[u] < dep[v]) swap(u, v);
for (int j = 0; j < LOG; ++j) {
if ((dep[u] - dep[v]) >> j & 1) {
u = up[j][u];
}
}
if (u == v) return v;
for (int j = LOG - 1; j >= 0; --j) {
if (up[j][u] != up[j][v]) {
u = up[j][u], v = up[j][v];
}
}
return up[0][v];
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, q;
cin >> n >> m >> q;
for(int i = 0; i < n - 1; ++i) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
for (int i = 0; i < m; ++i) {
cin >> a[i];
no[a[i]].insert(i);
}
dfs(1, 1);
for (int i = 0; i < m - 1; ++i) {
lco[lca(a[i], a[i + 1])].insert(i);
}
while (q--) {
int t;
cin >> t;
if (t == 1) {
int pos, v;
cin >> pos >> v;
pos--;
no[a[pos]].erase(pos);
if (pos > 0) {
lco[lca(a[pos], a[pos - 1])].erase(pos - 1);
}
if (pos < m) {
lco[lca(a[pos], a[pos + 1])].erase(pos);
}
a[pos] = v;
no[a[pos]].insert(pos);
if (pos > 0) {
lco[lca(a[pos], a[pos - 1])].insert(pos - 1);
}
if (pos < m) {
lco[lca(a[pos], a[pos + 1])].insert(pos);
}
} else {
int l, r, v;
cin >> l >> r >> v;
--l, --r;
auto s1 = lower_bound(no[v].begin(), no[v].end(), l);
if (s1 != no[v].end() && *s1 <= r) {
cout << *s1 + 1 << ' ' << *s1 + 1 << '\n';
continue;
}
s1 = lower_bound(lco[v].begin(), lco[v].end(), l);
if (s1 != lco[v].end() && *s1 < r) {
cout << *s1 + 1 << ' ' << *s1 + 2 << '\n';
} else {
cout << -1 << ' ' << -1 << '\n';
}
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
38244 KB |
n=5 |
2 |
Correct |
7 ms |
38232 KB |
n=100 |
3 |
Correct |
7 ms |
38236 KB |
n=100 |
4 |
Correct |
7 ms |
38236 KB |
n=100 |
5 |
Correct |
7 ms |
38236 KB |
n=100 |
6 |
Correct |
7 ms |
38236 KB |
n=100 |
7 |
Correct |
8 ms |
38232 KB |
n=100 |
8 |
Correct |
7 ms |
38232 KB |
n=100 |
9 |
Correct |
7 ms |
38236 KB |
n=100 |
10 |
Correct |
7 ms |
38236 KB |
n=100 |
11 |
Correct |
7 ms |
38232 KB |
n=100 |
12 |
Correct |
7 ms |
38316 KB |
n=100 |
13 |
Correct |
7 ms |
38260 KB |
n=100 |
14 |
Correct |
7 ms |
38236 KB |
n=100 |
15 |
Correct |
8 ms |
38488 KB |
n=100 |
16 |
Correct |
7 ms |
38236 KB |
n=100 |
17 |
Correct |
7 ms |
38236 KB |
n=100 |
18 |
Correct |
7 ms |
38232 KB |
n=100 |
19 |
Correct |
7 ms |
38236 KB |
n=100 |
20 |
Correct |
7 ms |
38236 KB |
n=100 |
21 |
Correct |
6 ms |
38236 KB |
n=100 |
22 |
Correct |
7 ms |
38236 KB |
n=100 |
23 |
Correct |
7 ms |
38236 KB |
n=100 |
24 |
Correct |
7 ms |
38232 KB |
n=100 |
25 |
Correct |
8 ms |
38236 KB |
n=100 |
26 |
Correct |
7 ms |
38236 KB |
n=12 |
27 |
Correct |
7 ms |
38236 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
38244 KB |
n=5 |
2 |
Correct |
7 ms |
38232 KB |
n=100 |
3 |
Correct |
7 ms |
38236 KB |
n=100 |
4 |
Correct |
7 ms |
38236 KB |
n=100 |
5 |
Correct |
7 ms |
38236 KB |
n=100 |
6 |
Correct |
7 ms |
38236 KB |
n=100 |
7 |
Correct |
8 ms |
38232 KB |
n=100 |
8 |
Correct |
7 ms |
38232 KB |
n=100 |
9 |
Correct |
7 ms |
38236 KB |
n=100 |
10 |
Correct |
7 ms |
38236 KB |
n=100 |
11 |
Correct |
7 ms |
38232 KB |
n=100 |
12 |
Correct |
7 ms |
38316 KB |
n=100 |
13 |
Correct |
7 ms |
38260 KB |
n=100 |
14 |
Correct |
7 ms |
38236 KB |
n=100 |
15 |
Correct |
8 ms |
38488 KB |
n=100 |
16 |
Correct |
7 ms |
38236 KB |
n=100 |
17 |
Correct |
7 ms |
38236 KB |
n=100 |
18 |
Correct |
7 ms |
38232 KB |
n=100 |
19 |
Correct |
7 ms |
38236 KB |
n=100 |
20 |
Correct |
7 ms |
38236 KB |
n=100 |
21 |
Correct |
6 ms |
38236 KB |
n=100 |
22 |
Correct |
7 ms |
38236 KB |
n=100 |
23 |
Correct |
7 ms |
38236 KB |
n=100 |
24 |
Correct |
7 ms |
38232 KB |
n=100 |
25 |
Correct |
8 ms |
38236 KB |
n=100 |
26 |
Correct |
7 ms |
38236 KB |
n=12 |
27 |
Correct |
7 ms |
38236 KB |
n=100 |
28 |
Correct |
8 ms |
38232 KB |
n=500 |
29 |
Correct |
7 ms |
38232 KB |
n=500 |
30 |
Correct |
9 ms |
38232 KB |
n=500 |
31 |
Correct |
8 ms |
38236 KB |
n=500 |
32 |
Correct |
9 ms |
38492 KB |
n=500 |
33 |
Correct |
7 ms |
38236 KB |
n=500 |
34 |
Correct |
8 ms |
38436 KB |
n=500 |
35 |
Correct |
7 ms |
38236 KB |
n=500 |
36 |
Correct |
9 ms |
38236 KB |
n=500 |
37 |
Correct |
7 ms |
38236 KB |
n=500 |
38 |
Correct |
7 ms |
38236 KB |
n=500 |
39 |
Correct |
7 ms |
38236 KB |
n=500 |
40 |
Correct |
8 ms |
38236 KB |
n=500 |
41 |
Correct |
7 ms |
38440 KB |
n=500 |
42 |
Correct |
8 ms |
38236 KB |
n=500 |
43 |
Correct |
7 ms |
38236 KB |
n=500 |
44 |
Correct |
8 ms |
38236 KB |
n=500 |
45 |
Correct |
8 ms |
38236 KB |
n=500 |
46 |
Correct |
9 ms |
38232 KB |
n=500 |
47 |
Correct |
8 ms |
38232 KB |
n=500 |
48 |
Correct |
8 ms |
38236 KB |
n=500 |
49 |
Correct |
8 ms |
38236 KB |
n=500 |
50 |
Correct |
8 ms |
38236 KB |
n=500 |
51 |
Correct |
8 ms |
38236 KB |
n=500 |
52 |
Correct |
7 ms |
38232 KB |
n=500 |
53 |
Correct |
8 ms |
38296 KB |
n=500 |
54 |
Correct |
8 ms |
38236 KB |
n=500 |
55 |
Correct |
7 ms |
38492 KB |
n=278 |
56 |
Correct |
7 ms |
38232 KB |
n=500 |
57 |
Correct |
8 ms |
38236 KB |
n=500 |
58 |
Correct |
9 ms |
38236 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
38244 KB |
n=5 |
2 |
Correct |
7 ms |
38232 KB |
n=100 |
3 |
Correct |
7 ms |
38236 KB |
n=100 |
4 |
Correct |
7 ms |
38236 KB |
n=100 |
5 |
Correct |
7 ms |
38236 KB |
n=100 |
6 |
Correct |
7 ms |
38236 KB |
n=100 |
7 |
Correct |
8 ms |
38232 KB |
n=100 |
8 |
Correct |
7 ms |
38232 KB |
n=100 |
9 |
Correct |
7 ms |
38236 KB |
n=100 |
10 |
Correct |
7 ms |
38236 KB |
n=100 |
11 |
Correct |
7 ms |
38232 KB |
n=100 |
12 |
Correct |
7 ms |
38316 KB |
n=100 |
13 |
Correct |
7 ms |
38260 KB |
n=100 |
14 |
Correct |
7 ms |
38236 KB |
n=100 |
15 |
Correct |
8 ms |
38488 KB |
n=100 |
16 |
Correct |
7 ms |
38236 KB |
n=100 |
17 |
Correct |
7 ms |
38236 KB |
n=100 |
18 |
Correct |
7 ms |
38232 KB |
n=100 |
19 |
Correct |
7 ms |
38236 KB |
n=100 |
20 |
Correct |
7 ms |
38236 KB |
n=100 |
21 |
Correct |
6 ms |
38236 KB |
n=100 |
22 |
Correct |
7 ms |
38236 KB |
n=100 |
23 |
Correct |
7 ms |
38236 KB |
n=100 |
24 |
Correct |
7 ms |
38232 KB |
n=100 |
25 |
Correct |
8 ms |
38236 KB |
n=100 |
26 |
Correct |
7 ms |
38236 KB |
n=12 |
27 |
Correct |
7 ms |
38236 KB |
n=100 |
28 |
Correct |
8 ms |
38232 KB |
n=500 |
29 |
Correct |
7 ms |
38232 KB |
n=500 |
30 |
Correct |
9 ms |
38232 KB |
n=500 |
31 |
Correct |
8 ms |
38236 KB |
n=500 |
32 |
Correct |
9 ms |
38492 KB |
n=500 |
33 |
Correct |
7 ms |
38236 KB |
n=500 |
34 |
Correct |
8 ms |
38436 KB |
n=500 |
35 |
Correct |
7 ms |
38236 KB |
n=500 |
36 |
Correct |
9 ms |
38236 KB |
n=500 |
37 |
Correct |
7 ms |
38236 KB |
n=500 |
38 |
Correct |
7 ms |
38236 KB |
n=500 |
39 |
Correct |
7 ms |
38236 KB |
n=500 |
40 |
Correct |
8 ms |
38236 KB |
n=500 |
41 |
Correct |
7 ms |
38440 KB |
n=500 |
42 |
Correct |
8 ms |
38236 KB |
n=500 |
43 |
Correct |
7 ms |
38236 KB |
n=500 |
44 |
Correct |
8 ms |
38236 KB |
n=500 |
45 |
Correct |
8 ms |
38236 KB |
n=500 |
46 |
Correct |
9 ms |
38232 KB |
n=500 |
47 |
Correct |
8 ms |
38232 KB |
n=500 |
48 |
Correct |
8 ms |
38236 KB |
n=500 |
49 |
Correct |
8 ms |
38236 KB |
n=500 |
50 |
Correct |
8 ms |
38236 KB |
n=500 |
51 |
Correct |
8 ms |
38236 KB |
n=500 |
52 |
Correct |
7 ms |
38232 KB |
n=500 |
53 |
Correct |
8 ms |
38296 KB |
n=500 |
54 |
Correct |
8 ms |
38236 KB |
n=500 |
55 |
Correct |
7 ms |
38492 KB |
n=278 |
56 |
Correct |
7 ms |
38232 KB |
n=500 |
57 |
Correct |
8 ms |
38236 KB |
n=500 |
58 |
Correct |
9 ms |
38236 KB |
n=500 |
59 |
Correct |
20 ms |
38492 KB |
n=2000 |
60 |
Correct |
9 ms |
38748 KB |
n=2000 |
61 |
Correct |
9 ms |
38748 KB |
n=2000 |
62 |
Correct |
10 ms |
38492 KB |
n=2000 |
63 |
Correct |
24 ms |
38488 KB |
n=2000 |
64 |
Correct |
9 ms |
38500 KB |
n=2000 |
65 |
Correct |
24 ms |
38492 KB |
n=2000 |
66 |
Correct |
9 ms |
38748 KB |
n=2000 |
67 |
Correct |
16 ms |
38492 KB |
n=2000 |
68 |
Correct |
9 ms |
38744 KB |
n=2000 |
69 |
Correct |
8 ms |
38492 KB |
n=2000 |
70 |
Correct |
9 ms |
38576 KB |
n=2000 |
71 |
Correct |
9 ms |
38492 KB |
n=2000 |
72 |
Correct |
9 ms |
38488 KB |
n=2000 |
73 |
Correct |
8 ms |
38492 KB |
n=2000 |
74 |
Correct |
18 ms |
38600 KB |
n=1844 |
75 |
Correct |
9 ms |
38492 KB |
n=2000 |
76 |
Correct |
10 ms |
38492 KB |
n=2000 |
77 |
Correct |
9 ms |
38492 KB |
n=2000 |
78 |
Correct |
11 ms |
38488 KB |
n=2000 |
79 |
Correct |
16 ms |
38448 KB |
n=2000 |
80 |
Correct |
9 ms |
38748 KB |
n=2000 |
81 |
Correct |
10 ms |
38748 KB |
n=2000 |
82 |
Correct |
17 ms |
38492 KB |
n=2000 |
83 |
Correct |
9 ms |
38780 KB |
n=2000 |
84 |
Correct |
9 ms |
38488 KB |
n=2000 |
85 |
Correct |
9 ms |
38492 KB |
n=2000 |
86 |
Correct |
9 ms |
38492 KB |
n=2000 |
87 |
Correct |
9 ms |
38492 KB |
n=2000 |
88 |
Correct |
10 ms |
38828 KB |
n=2000 |
89 |
Correct |
9 ms |
38824 KB |
n=2000 |
90 |
Correct |
11 ms |
38824 KB |
n=2000 |
91 |
Correct |
9 ms |
38488 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
38244 KB |
n=5 |
2 |
Correct |
7 ms |
38232 KB |
n=100 |
3 |
Correct |
7 ms |
38236 KB |
n=100 |
4 |
Correct |
7 ms |
38236 KB |
n=100 |
5 |
Correct |
7 ms |
38236 KB |
n=100 |
6 |
Correct |
7 ms |
38236 KB |
n=100 |
7 |
Correct |
8 ms |
38232 KB |
n=100 |
8 |
Correct |
7 ms |
38232 KB |
n=100 |
9 |
Correct |
7 ms |
38236 KB |
n=100 |
10 |
Correct |
7 ms |
38236 KB |
n=100 |
11 |
Correct |
7 ms |
38232 KB |
n=100 |
12 |
Correct |
7 ms |
38316 KB |
n=100 |
13 |
Correct |
7 ms |
38260 KB |
n=100 |
14 |
Correct |
7 ms |
38236 KB |
n=100 |
15 |
Correct |
8 ms |
38488 KB |
n=100 |
16 |
Correct |
7 ms |
38236 KB |
n=100 |
17 |
Correct |
7 ms |
38236 KB |
n=100 |
18 |
Correct |
7 ms |
38232 KB |
n=100 |
19 |
Correct |
7 ms |
38236 KB |
n=100 |
20 |
Correct |
7 ms |
38236 KB |
n=100 |
21 |
Correct |
6 ms |
38236 KB |
n=100 |
22 |
Correct |
7 ms |
38236 KB |
n=100 |
23 |
Correct |
7 ms |
38236 KB |
n=100 |
24 |
Correct |
7 ms |
38232 KB |
n=100 |
25 |
Correct |
8 ms |
38236 KB |
n=100 |
26 |
Correct |
7 ms |
38236 KB |
n=12 |
27 |
Correct |
7 ms |
38236 KB |
n=100 |
28 |
Correct |
8 ms |
38232 KB |
n=500 |
29 |
Correct |
7 ms |
38232 KB |
n=500 |
30 |
Correct |
9 ms |
38232 KB |
n=500 |
31 |
Correct |
8 ms |
38236 KB |
n=500 |
32 |
Correct |
9 ms |
38492 KB |
n=500 |
33 |
Correct |
7 ms |
38236 KB |
n=500 |
34 |
Correct |
8 ms |
38436 KB |
n=500 |
35 |
Correct |
7 ms |
38236 KB |
n=500 |
36 |
Correct |
9 ms |
38236 KB |
n=500 |
37 |
Correct |
7 ms |
38236 KB |
n=500 |
38 |
Correct |
7 ms |
38236 KB |
n=500 |
39 |
Correct |
7 ms |
38236 KB |
n=500 |
40 |
Correct |
8 ms |
38236 KB |
n=500 |
41 |
Correct |
7 ms |
38440 KB |
n=500 |
42 |
Correct |
8 ms |
38236 KB |
n=500 |
43 |
Correct |
7 ms |
38236 KB |
n=500 |
44 |
Correct |
8 ms |
38236 KB |
n=500 |
45 |
Correct |
8 ms |
38236 KB |
n=500 |
46 |
Correct |
9 ms |
38232 KB |
n=500 |
47 |
Correct |
8 ms |
38232 KB |
n=500 |
48 |
Correct |
8 ms |
38236 KB |
n=500 |
49 |
Correct |
8 ms |
38236 KB |
n=500 |
50 |
Correct |
8 ms |
38236 KB |
n=500 |
51 |
Correct |
8 ms |
38236 KB |
n=500 |
52 |
Correct |
7 ms |
38232 KB |
n=500 |
53 |
Correct |
8 ms |
38296 KB |
n=500 |
54 |
Correct |
8 ms |
38236 KB |
n=500 |
55 |
Correct |
7 ms |
38492 KB |
n=278 |
56 |
Correct |
7 ms |
38232 KB |
n=500 |
57 |
Correct |
8 ms |
38236 KB |
n=500 |
58 |
Correct |
9 ms |
38236 KB |
n=500 |
59 |
Correct |
20 ms |
38492 KB |
n=2000 |
60 |
Correct |
9 ms |
38748 KB |
n=2000 |
61 |
Correct |
9 ms |
38748 KB |
n=2000 |
62 |
Correct |
10 ms |
38492 KB |
n=2000 |
63 |
Correct |
24 ms |
38488 KB |
n=2000 |
64 |
Correct |
9 ms |
38500 KB |
n=2000 |
65 |
Correct |
24 ms |
38492 KB |
n=2000 |
66 |
Correct |
9 ms |
38748 KB |
n=2000 |
67 |
Correct |
16 ms |
38492 KB |
n=2000 |
68 |
Correct |
9 ms |
38744 KB |
n=2000 |
69 |
Correct |
8 ms |
38492 KB |
n=2000 |
70 |
Correct |
9 ms |
38576 KB |
n=2000 |
71 |
Correct |
9 ms |
38492 KB |
n=2000 |
72 |
Correct |
9 ms |
38488 KB |
n=2000 |
73 |
Correct |
8 ms |
38492 KB |
n=2000 |
74 |
Correct |
18 ms |
38600 KB |
n=1844 |
75 |
Correct |
9 ms |
38492 KB |
n=2000 |
76 |
Correct |
10 ms |
38492 KB |
n=2000 |
77 |
Correct |
9 ms |
38492 KB |
n=2000 |
78 |
Correct |
11 ms |
38488 KB |
n=2000 |
79 |
Correct |
16 ms |
38448 KB |
n=2000 |
80 |
Correct |
9 ms |
38748 KB |
n=2000 |
81 |
Correct |
10 ms |
38748 KB |
n=2000 |
82 |
Correct |
17 ms |
38492 KB |
n=2000 |
83 |
Correct |
9 ms |
38780 KB |
n=2000 |
84 |
Correct |
9 ms |
38488 KB |
n=2000 |
85 |
Correct |
9 ms |
38492 KB |
n=2000 |
86 |
Correct |
9 ms |
38492 KB |
n=2000 |
87 |
Correct |
9 ms |
38492 KB |
n=2000 |
88 |
Correct |
10 ms |
38828 KB |
n=2000 |
89 |
Correct |
9 ms |
38824 KB |
n=2000 |
90 |
Correct |
11 ms |
38824 KB |
n=2000 |
91 |
Correct |
9 ms |
38488 KB |
n=2000 |
92 |
Execution timed out |
4005 ms |
70864 KB |
Time limit exceeded |
93 |
Halted |
0 ms |
0 KB |
- |