#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <unordered_set>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <bitset>
#include <queue>
#include <unordered_map>
#include <fstream>
#include <random>
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
vector <vector<int>> G;
const int N = 1e5 + 10;
int a[N];
int dp[N][20];
int depth[N];
set <int> f1[N];
set <int> f2[N];
void dfs(int v, int p) {
depth[v] = depth[p] + 1;
dp[v][0] = p;
for (int j = 1; j < 20; j++) {
dp[v][j] = dp[dp[v][j - 1]][j - 1];
}
for (auto it : G[v]) {
if (it == p) continue;
dfs(it, v);
}
}
int find_lca(int a, int b) {
if (depth[a] < depth[b]) swap(a, b);
int k = depth[a] - depth[b];
for (int i = 0; i < 20; i++) {
if (k & (1 << i)) {
a = dp[a][i];
}
}
if (a == b) return a;
for (int i = 19; i >= 0; i--) {
if (dp[a][i] != dp[b][i]) {
a = dp[a][i];
b = dp[b][i];
}
}
return dp[a][0];
}
int main() {
int n, m, q;
cin >> n >> m >> q;
G.resize(n + 1);
for (int i = 1; i < n; i++) {
int a, b;
cin >> a >> b;
G[a].push_back(b);
G[b].push_back(a);
}
dfs(1, 1);
for (int i = 1; i <= m; i++) {
cin >> a[i];
f1[a[i]].insert(i);
}
for (int i = 1; i <= m - 1; i++) {
f2[find_lca(a[i], a[i + 1])].insert(i);
}
while (q--) {
int type;
cin >> type;
if (type == 1) {
int pos, val;
cin >> pos >> val;
f1[a[pos]].erase(pos);
f1[val].insert(pos);
if (pos != 1) {
f2[find_lca(a[pos - 1], a[pos])].erase(pos - 1);
f2[find_lca(a[pos - 1], val)].insert(pos - 1);
}
if (pos != n) {
f2[find_lca(a[pos], a[pos + 1])].erase(pos);
f2[find_lca(val, a[pos + 1])].insert(pos);
}
a[pos] = val;
}
else {
int l, r, v;
cin >> l >> r >> v;
auto it = f1[v].lower_bound(l);
if (it != f1[v].end() && *it <= r) {
cout << *it << " " << *it << "\n";
continue;
}
auto w = f2[v].lower_bound(l);
if (w != f2[v].end() && *w < r) {
cout << *w << " " << *w + 1 << "\n";
continue;
}
cout << -1 << " " << -1 << "\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10844 KB |
n=5 |
2 |
Correct |
2 ms |
10844 KB |
n=100 |
3 |
Correct |
2 ms |
10844 KB |
n=100 |
4 |
Correct |
2 ms |
10844 KB |
n=100 |
5 |
Correct |
2 ms |
10844 KB |
n=100 |
6 |
Correct |
2 ms |
10844 KB |
n=100 |
7 |
Correct |
3 ms |
10844 KB |
n=100 |
8 |
Correct |
2 ms |
11096 KB |
n=100 |
9 |
Correct |
3 ms |
10840 KB |
n=100 |
10 |
Correct |
2 ms |
10844 KB |
n=100 |
11 |
Correct |
2 ms |
10844 KB |
n=100 |
12 |
Correct |
2 ms |
10844 KB |
n=100 |
13 |
Correct |
2 ms |
10844 KB |
n=100 |
14 |
Correct |
2 ms |
10840 KB |
n=100 |
15 |
Correct |
2 ms |
10840 KB |
n=100 |
16 |
Correct |
3 ms |
10844 KB |
n=100 |
17 |
Correct |
2 ms |
10844 KB |
n=100 |
18 |
Correct |
3 ms |
10840 KB |
n=100 |
19 |
Correct |
2 ms |
10840 KB |
n=100 |
20 |
Correct |
2 ms |
10844 KB |
n=100 |
21 |
Correct |
2 ms |
10872 KB |
n=100 |
22 |
Correct |
2 ms |
10840 KB |
n=100 |
23 |
Correct |
2 ms |
10844 KB |
n=100 |
24 |
Correct |
2 ms |
10844 KB |
n=100 |
25 |
Correct |
2 ms |
10844 KB |
n=100 |
26 |
Correct |
2 ms |
10844 KB |
n=12 |
27 |
Correct |
2 ms |
10844 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10844 KB |
n=5 |
2 |
Correct |
2 ms |
10844 KB |
n=100 |
3 |
Correct |
2 ms |
10844 KB |
n=100 |
4 |
Correct |
2 ms |
10844 KB |
n=100 |
5 |
Correct |
2 ms |
10844 KB |
n=100 |
6 |
Correct |
2 ms |
10844 KB |
n=100 |
7 |
Correct |
3 ms |
10844 KB |
n=100 |
8 |
Correct |
2 ms |
11096 KB |
n=100 |
9 |
Correct |
3 ms |
10840 KB |
n=100 |
10 |
Correct |
2 ms |
10844 KB |
n=100 |
11 |
Correct |
2 ms |
10844 KB |
n=100 |
12 |
Correct |
2 ms |
10844 KB |
n=100 |
13 |
Correct |
2 ms |
10844 KB |
n=100 |
14 |
Correct |
2 ms |
10840 KB |
n=100 |
15 |
Correct |
2 ms |
10840 KB |
n=100 |
16 |
Correct |
3 ms |
10844 KB |
n=100 |
17 |
Correct |
2 ms |
10844 KB |
n=100 |
18 |
Correct |
3 ms |
10840 KB |
n=100 |
19 |
Correct |
2 ms |
10840 KB |
n=100 |
20 |
Correct |
2 ms |
10844 KB |
n=100 |
21 |
Correct |
2 ms |
10872 KB |
n=100 |
22 |
Correct |
2 ms |
10840 KB |
n=100 |
23 |
Correct |
2 ms |
10844 KB |
n=100 |
24 |
Correct |
2 ms |
10844 KB |
n=100 |
25 |
Correct |
2 ms |
10844 KB |
n=100 |
26 |
Correct |
2 ms |
10844 KB |
n=12 |
27 |
Correct |
2 ms |
10844 KB |
n=100 |
28 |
Correct |
3 ms |
10844 KB |
n=500 |
29 |
Correct |
3 ms |
10844 KB |
n=500 |
30 |
Correct |
3 ms |
10840 KB |
n=500 |
31 |
Correct |
3 ms |
10844 KB |
n=500 |
32 |
Correct |
3 ms |
10844 KB |
n=500 |
33 |
Correct |
4 ms |
10840 KB |
n=500 |
34 |
Correct |
3 ms |
10844 KB |
n=500 |
35 |
Correct |
3 ms |
10920 KB |
n=500 |
36 |
Correct |
4 ms |
10844 KB |
n=500 |
37 |
Correct |
4 ms |
10844 KB |
n=500 |
38 |
Correct |
3 ms |
10844 KB |
n=500 |
39 |
Correct |
3 ms |
10844 KB |
n=500 |
40 |
Correct |
3 ms |
10844 KB |
n=500 |
41 |
Correct |
3 ms |
10888 KB |
n=500 |
42 |
Correct |
3 ms |
10840 KB |
n=500 |
43 |
Correct |
3 ms |
10844 KB |
n=500 |
44 |
Correct |
4 ms |
10880 KB |
n=500 |
45 |
Correct |
3 ms |
10844 KB |
n=500 |
46 |
Correct |
4 ms |
10888 KB |
n=500 |
47 |
Correct |
3 ms |
10844 KB |
n=500 |
48 |
Correct |
3 ms |
10844 KB |
n=500 |
49 |
Correct |
3 ms |
10840 KB |
n=500 |
50 |
Correct |
3 ms |
10844 KB |
n=500 |
51 |
Correct |
3 ms |
10844 KB |
n=500 |
52 |
Correct |
3 ms |
10888 KB |
n=500 |
53 |
Correct |
4 ms |
10844 KB |
n=500 |
54 |
Correct |
3 ms |
10840 KB |
n=500 |
55 |
Correct |
2 ms |
10844 KB |
n=278 |
56 |
Correct |
3 ms |
10840 KB |
n=500 |
57 |
Correct |
3 ms |
10840 KB |
n=500 |
58 |
Correct |
3 ms |
10844 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10844 KB |
n=5 |
2 |
Correct |
2 ms |
10844 KB |
n=100 |
3 |
Correct |
2 ms |
10844 KB |
n=100 |
4 |
Correct |
2 ms |
10844 KB |
n=100 |
5 |
Correct |
2 ms |
10844 KB |
n=100 |
6 |
Correct |
2 ms |
10844 KB |
n=100 |
7 |
Correct |
3 ms |
10844 KB |
n=100 |
8 |
Correct |
2 ms |
11096 KB |
n=100 |
9 |
Correct |
3 ms |
10840 KB |
n=100 |
10 |
Correct |
2 ms |
10844 KB |
n=100 |
11 |
Correct |
2 ms |
10844 KB |
n=100 |
12 |
Correct |
2 ms |
10844 KB |
n=100 |
13 |
Correct |
2 ms |
10844 KB |
n=100 |
14 |
Correct |
2 ms |
10840 KB |
n=100 |
15 |
Correct |
2 ms |
10840 KB |
n=100 |
16 |
Correct |
3 ms |
10844 KB |
n=100 |
17 |
Correct |
2 ms |
10844 KB |
n=100 |
18 |
Correct |
3 ms |
10840 KB |
n=100 |
19 |
Correct |
2 ms |
10840 KB |
n=100 |
20 |
Correct |
2 ms |
10844 KB |
n=100 |
21 |
Correct |
2 ms |
10872 KB |
n=100 |
22 |
Correct |
2 ms |
10840 KB |
n=100 |
23 |
Correct |
2 ms |
10844 KB |
n=100 |
24 |
Correct |
2 ms |
10844 KB |
n=100 |
25 |
Correct |
2 ms |
10844 KB |
n=100 |
26 |
Correct |
2 ms |
10844 KB |
n=12 |
27 |
Correct |
2 ms |
10844 KB |
n=100 |
28 |
Correct |
3 ms |
10844 KB |
n=500 |
29 |
Correct |
3 ms |
10844 KB |
n=500 |
30 |
Correct |
3 ms |
10840 KB |
n=500 |
31 |
Correct |
3 ms |
10844 KB |
n=500 |
32 |
Correct |
3 ms |
10844 KB |
n=500 |
33 |
Correct |
4 ms |
10840 KB |
n=500 |
34 |
Correct |
3 ms |
10844 KB |
n=500 |
35 |
Correct |
3 ms |
10920 KB |
n=500 |
36 |
Correct |
4 ms |
10844 KB |
n=500 |
37 |
Correct |
4 ms |
10844 KB |
n=500 |
38 |
Correct |
3 ms |
10844 KB |
n=500 |
39 |
Correct |
3 ms |
10844 KB |
n=500 |
40 |
Correct |
3 ms |
10844 KB |
n=500 |
41 |
Correct |
3 ms |
10888 KB |
n=500 |
42 |
Correct |
3 ms |
10840 KB |
n=500 |
43 |
Correct |
3 ms |
10844 KB |
n=500 |
44 |
Correct |
4 ms |
10880 KB |
n=500 |
45 |
Correct |
3 ms |
10844 KB |
n=500 |
46 |
Correct |
4 ms |
10888 KB |
n=500 |
47 |
Correct |
3 ms |
10844 KB |
n=500 |
48 |
Correct |
3 ms |
10844 KB |
n=500 |
49 |
Correct |
3 ms |
10840 KB |
n=500 |
50 |
Correct |
3 ms |
10844 KB |
n=500 |
51 |
Correct |
3 ms |
10844 KB |
n=500 |
52 |
Correct |
3 ms |
10888 KB |
n=500 |
53 |
Correct |
4 ms |
10844 KB |
n=500 |
54 |
Correct |
3 ms |
10840 KB |
n=500 |
55 |
Correct |
2 ms |
10844 KB |
n=278 |
56 |
Correct |
3 ms |
10840 KB |
n=500 |
57 |
Correct |
3 ms |
10840 KB |
n=500 |
58 |
Correct |
3 ms |
10844 KB |
n=500 |
59 |
Correct |
7 ms |
11100 KB |
n=2000 |
60 |
Correct |
7 ms |
11100 KB |
n=2000 |
61 |
Correct |
7 ms |
11100 KB |
n=2000 |
62 |
Correct |
7 ms |
11100 KB |
n=2000 |
63 |
Correct |
7 ms |
11100 KB |
n=2000 |
64 |
Correct |
7 ms |
11100 KB |
n=2000 |
65 |
Correct |
7 ms |
11100 KB |
n=2000 |
66 |
Correct |
10 ms |
11100 KB |
n=2000 |
67 |
Correct |
7 ms |
11100 KB |
n=2000 |
68 |
Correct |
7 ms |
11100 KB |
n=2000 |
69 |
Correct |
8 ms |
11100 KB |
n=2000 |
70 |
Correct |
8 ms |
11100 KB |
n=2000 |
71 |
Correct |
8 ms |
11032 KB |
n=2000 |
72 |
Correct |
8 ms |
11100 KB |
n=2000 |
73 |
Correct |
7 ms |
11100 KB |
n=2000 |
74 |
Correct |
6 ms |
11024 KB |
n=1844 |
75 |
Correct |
8 ms |
11096 KB |
n=2000 |
76 |
Correct |
7 ms |
11100 KB |
n=2000 |
77 |
Correct |
7 ms |
11140 KB |
n=2000 |
78 |
Correct |
7 ms |
11100 KB |
n=2000 |
79 |
Correct |
7 ms |
11100 KB |
n=2000 |
80 |
Correct |
7 ms |
11100 KB |
n=2000 |
81 |
Correct |
7 ms |
11100 KB |
n=2000 |
82 |
Correct |
7 ms |
11096 KB |
n=2000 |
83 |
Correct |
8 ms |
11100 KB |
n=2000 |
84 |
Correct |
7 ms |
11096 KB |
n=2000 |
85 |
Correct |
7 ms |
11100 KB |
n=2000 |
86 |
Correct |
7 ms |
11100 KB |
n=2000 |
87 |
Correct |
7 ms |
11100 KB |
n=2000 |
88 |
Correct |
7 ms |
11100 KB |
n=2000 |
89 |
Correct |
7 ms |
11096 KB |
n=2000 |
90 |
Correct |
7 ms |
11100 KB |
n=2000 |
91 |
Correct |
8 ms |
11184 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10844 KB |
n=5 |
2 |
Correct |
2 ms |
10844 KB |
n=100 |
3 |
Correct |
2 ms |
10844 KB |
n=100 |
4 |
Correct |
2 ms |
10844 KB |
n=100 |
5 |
Correct |
2 ms |
10844 KB |
n=100 |
6 |
Correct |
2 ms |
10844 KB |
n=100 |
7 |
Correct |
3 ms |
10844 KB |
n=100 |
8 |
Correct |
2 ms |
11096 KB |
n=100 |
9 |
Correct |
3 ms |
10840 KB |
n=100 |
10 |
Correct |
2 ms |
10844 KB |
n=100 |
11 |
Correct |
2 ms |
10844 KB |
n=100 |
12 |
Correct |
2 ms |
10844 KB |
n=100 |
13 |
Correct |
2 ms |
10844 KB |
n=100 |
14 |
Correct |
2 ms |
10840 KB |
n=100 |
15 |
Correct |
2 ms |
10840 KB |
n=100 |
16 |
Correct |
3 ms |
10844 KB |
n=100 |
17 |
Correct |
2 ms |
10844 KB |
n=100 |
18 |
Correct |
3 ms |
10840 KB |
n=100 |
19 |
Correct |
2 ms |
10840 KB |
n=100 |
20 |
Correct |
2 ms |
10844 KB |
n=100 |
21 |
Correct |
2 ms |
10872 KB |
n=100 |
22 |
Correct |
2 ms |
10840 KB |
n=100 |
23 |
Correct |
2 ms |
10844 KB |
n=100 |
24 |
Correct |
2 ms |
10844 KB |
n=100 |
25 |
Correct |
2 ms |
10844 KB |
n=100 |
26 |
Correct |
2 ms |
10844 KB |
n=12 |
27 |
Correct |
2 ms |
10844 KB |
n=100 |
28 |
Correct |
3 ms |
10844 KB |
n=500 |
29 |
Correct |
3 ms |
10844 KB |
n=500 |
30 |
Correct |
3 ms |
10840 KB |
n=500 |
31 |
Correct |
3 ms |
10844 KB |
n=500 |
32 |
Correct |
3 ms |
10844 KB |
n=500 |
33 |
Correct |
4 ms |
10840 KB |
n=500 |
34 |
Correct |
3 ms |
10844 KB |
n=500 |
35 |
Correct |
3 ms |
10920 KB |
n=500 |
36 |
Correct |
4 ms |
10844 KB |
n=500 |
37 |
Correct |
4 ms |
10844 KB |
n=500 |
38 |
Correct |
3 ms |
10844 KB |
n=500 |
39 |
Correct |
3 ms |
10844 KB |
n=500 |
40 |
Correct |
3 ms |
10844 KB |
n=500 |
41 |
Correct |
3 ms |
10888 KB |
n=500 |
42 |
Correct |
3 ms |
10840 KB |
n=500 |
43 |
Correct |
3 ms |
10844 KB |
n=500 |
44 |
Correct |
4 ms |
10880 KB |
n=500 |
45 |
Correct |
3 ms |
10844 KB |
n=500 |
46 |
Correct |
4 ms |
10888 KB |
n=500 |
47 |
Correct |
3 ms |
10844 KB |
n=500 |
48 |
Correct |
3 ms |
10844 KB |
n=500 |
49 |
Correct |
3 ms |
10840 KB |
n=500 |
50 |
Correct |
3 ms |
10844 KB |
n=500 |
51 |
Correct |
3 ms |
10844 KB |
n=500 |
52 |
Correct |
3 ms |
10888 KB |
n=500 |
53 |
Correct |
4 ms |
10844 KB |
n=500 |
54 |
Correct |
3 ms |
10840 KB |
n=500 |
55 |
Correct |
2 ms |
10844 KB |
n=278 |
56 |
Correct |
3 ms |
10840 KB |
n=500 |
57 |
Correct |
3 ms |
10840 KB |
n=500 |
58 |
Correct |
3 ms |
10844 KB |
n=500 |
59 |
Correct |
7 ms |
11100 KB |
n=2000 |
60 |
Correct |
7 ms |
11100 KB |
n=2000 |
61 |
Correct |
7 ms |
11100 KB |
n=2000 |
62 |
Correct |
7 ms |
11100 KB |
n=2000 |
63 |
Correct |
7 ms |
11100 KB |
n=2000 |
64 |
Correct |
7 ms |
11100 KB |
n=2000 |
65 |
Correct |
7 ms |
11100 KB |
n=2000 |
66 |
Correct |
10 ms |
11100 KB |
n=2000 |
67 |
Correct |
7 ms |
11100 KB |
n=2000 |
68 |
Correct |
7 ms |
11100 KB |
n=2000 |
69 |
Correct |
8 ms |
11100 KB |
n=2000 |
70 |
Correct |
8 ms |
11100 KB |
n=2000 |
71 |
Correct |
8 ms |
11032 KB |
n=2000 |
72 |
Correct |
8 ms |
11100 KB |
n=2000 |
73 |
Correct |
7 ms |
11100 KB |
n=2000 |
74 |
Correct |
6 ms |
11024 KB |
n=1844 |
75 |
Correct |
8 ms |
11096 KB |
n=2000 |
76 |
Correct |
7 ms |
11100 KB |
n=2000 |
77 |
Correct |
7 ms |
11140 KB |
n=2000 |
78 |
Correct |
7 ms |
11100 KB |
n=2000 |
79 |
Correct |
7 ms |
11100 KB |
n=2000 |
80 |
Correct |
7 ms |
11100 KB |
n=2000 |
81 |
Correct |
7 ms |
11100 KB |
n=2000 |
82 |
Correct |
7 ms |
11096 KB |
n=2000 |
83 |
Correct |
8 ms |
11100 KB |
n=2000 |
84 |
Correct |
7 ms |
11096 KB |
n=2000 |
85 |
Correct |
7 ms |
11100 KB |
n=2000 |
86 |
Correct |
7 ms |
11100 KB |
n=2000 |
87 |
Correct |
7 ms |
11100 KB |
n=2000 |
88 |
Correct |
7 ms |
11100 KB |
n=2000 |
89 |
Correct |
7 ms |
11096 KB |
n=2000 |
90 |
Correct |
7 ms |
11100 KB |
n=2000 |
91 |
Correct |
8 ms |
11184 KB |
n=2000 |
92 |
Runtime error |
103 ms |
52048 KB |
Execution killed with signal 11 |
93 |
Halted |
0 ms |
0 KB |
- |