#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
vector<long long> g[N];
long long DP[18][N], depth[N];
void dfs(long long node, long long par) {
DP[0][node] = par;
for(long long i = 0; i < g[node].size(); i++) {
if(g[node][i] != par) {
depth[g[node][i]] = depth[node] + 1;
dfs(g[node][i], node);
}
}
}
void DPTable(long long n) {
for(long long j = 1; j < 18; j++) {
for(long long i = 1; i <= n; i++) {
if(DP[j - 1][i] == -1)
DP[j][i] = -1;
else
DP[j][i] = DP[j - 1][DP[j - 1][i]];
}
}
}
long long lca(long long a, long long b) {
if(depth[a] < depth[b])
swap(a, b);
long long diff = depth[a] - depth[b];
for(long long i = 17; i >= 0; i--) {
if(diff >= (1 << i)) {
diff -= (1 << i);
a = DP[i][a];
}
}
if(a == b)
return a;
for(long long i = 17; i >= 0; i--) {
if(DP[i][a] != DP[i][b]) {
a = DP[i][a];
b = DP[i][b];
}
}
return DP[0][a];
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n, m, q;
cin >> n >> m >> q;
for(long long i = 0; i < n - 1; i++) {
long long v, u;
cin >> v >> u;
g[v].push_back(u);
g[u].push_back(v);
}
depth[1] = 0;
dfs(1, -1);
DPTable(n);
long long a[m + 1];
for(long long i = 1; i <= m; i++) {
cin >> a[i];
}
set<long long> ones[n + 1], twos[n + 1];
for(long long i = 1; i < m; i++) {
ones[a[i]].insert(i);
twos[lca(a[i], a[i + 1])].insert(i);
}
ones[a[m]].insert(m);
//cout << "121" << endl;
for(long long i = 1; i <= q; i++) {
long long command;
cin >> command;
if(command == 1) {
long long idx, val;
cin >> idx >> val;
ones[a[idx]].erase(idx);
if(idx < m) {
twos[lca(a[idx], a[idx + 1])].erase(idx);
}
if(idx > 1) {
twos[lca(a[idx], a[idx - 1])].erase(idx - 1);
}
a[idx] = val;
ones[a[idx]].insert(idx);
if(idx < m) {
twos[lca(a[idx], a[idx + 1])].insert(idx);
}
if(idx > 1) {
twos[lca(a[idx], a[idx - 1])].insert(idx - 1);
}
}
else {
long long l, r, v;
cin >> l >> r >> v;
if(ones[v].size() != 0 && *(ones[v].begin()) <= r) {
auto temp = ones[v].upper_bound(r);
temp--;
long long x = *(temp);
if(x >= l) {
cout << x << " " << x << endl;
continue;
}
}
if(twos[v].size() != 0 && *(twos[v].begin()) < r) {
auto temp = twos[v].lower_bound(r);
temp--;
long long x = *(temp);
if(x >= l && x < r) {
cout << x << " " << x + 1 << endl;
continue;
}
}
cout << "-1 -1" << endl;
}
}
}
Compilation message
treearray.cpp: In function 'void dfs(long long int, long long int)':
treearray.cpp:10:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
10 | for(long long i = 0; i < g[node].size(); i++) {
| ~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5100 KB |
n=5 |
2 |
Correct |
4 ms |
5228 KB |
n=100 |
3 |
Correct |
4 ms |
5248 KB |
n=100 |
4 |
Correct |
5 ms |
5228 KB |
n=100 |
5 |
Correct |
4 ms |
5228 KB |
n=100 |
6 |
Correct |
4 ms |
5228 KB |
n=100 |
7 |
Correct |
4 ms |
5228 KB |
n=100 |
8 |
Correct |
4 ms |
5228 KB |
n=100 |
9 |
Correct |
4 ms |
5228 KB |
n=100 |
10 |
Correct |
4 ms |
5228 KB |
n=100 |
11 |
Correct |
4 ms |
5228 KB |
n=100 |
12 |
Correct |
4 ms |
5228 KB |
n=100 |
13 |
Correct |
5 ms |
5228 KB |
n=100 |
14 |
Correct |
4 ms |
5228 KB |
n=100 |
15 |
Correct |
4 ms |
5228 KB |
n=100 |
16 |
Correct |
4 ms |
5228 KB |
n=100 |
17 |
Correct |
4 ms |
5228 KB |
n=100 |
18 |
Correct |
4 ms |
5228 KB |
n=100 |
19 |
Correct |
4 ms |
5228 KB |
n=100 |
20 |
Correct |
4 ms |
5228 KB |
n=100 |
21 |
Correct |
5 ms |
5228 KB |
n=100 |
22 |
Correct |
4 ms |
5228 KB |
n=100 |
23 |
Correct |
4 ms |
5228 KB |
n=100 |
24 |
Correct |
3 ms |
5228 KB |
n=100 |
25 |
Correct |
4 ms |
5228 KB |
n=100 |
26 |
Correct |
3 ms |
5100 KB |
n=12 |
27 |
Correct |
4 ms |
5228 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5100 KB |
n=5 |
2 |
Correct |
4 ms |
5228 KB |
n=100 |
3 |
Correct |
4 ms |
5248 KB |
n=100 |
4 |
Correct |
5 ms |
5228 KB |
n=100 |
5 |
Correct |
4 ms |
5228 KB |
n=100 |
6 |
Correct |
4 ms |
5228 KB |
n=100 |
7 |
Correct |
4 ms |
5228 KB |
n=100 |
8 |
Correct |
4 ms |
5228 KB |
n=100 |
9 |
Correct |
4 ms |
5228 KB |
n=100 |
10 |
Correct |
4 ms |
5228 KB |
n=100 |
11 |
Correct |
4 ms |
5228 KB |
n=100 |
12 |
Correct |
4 ms |
5228 KB |
n=100 |
13 |
Correct |
5 ms |
5228 KB |
n=100 |
14 |
Correct |
4 ms |
5228 KB |
n=100 |
15 |
Correct |
4 ms |
5228 KB |
n=100 |
16 |
Correct |
4 ms |
5228 KB |
n=100 |
17 |
Correct |
4 ms |
5228 KB |
n=100 |
18 |
Correct |
4 ms |
5228 KB |
n=100 |
19 |
Correct |
4 ms |
5228 KB |
n=100 |
20 |
Correct |
4 ms |
5228 KB |
n=100 |
21 |
Correct |
5 ms |
5228 KB |
n=100 |
22 |
Correct |
4 ms |
5228 KB |
n=100 |
23 |
Correct |
4 ms |
5228 KB |
n=100 |
24 |
Correct |
3 ms |
5228 KB |
n=100 |
25 |
Correct |
4 ms |
5228 KB |
n=100 |
26 |
Correct |
3 ms |
5100 KB |
n=12 |
27 |
Correct |
4 ms |
5228 KB |
n=100 |
28 |
Correct |
5 ms |
5376 KB |
n=500 |
29 |
Correct |
5 ms |
5356 KB |
n=500 |
30 |
Correct |
5 ms |
5356 KB |
n=500 |
31 |
Correct |
5 ms |
5356 KB |
n=500 |
32 |
Correct |
5 ms |
5356 KB |
n=500 |
33 |
Correct |
5 ms |
5376 KB |
n=500 |
34 |
Correct |
5 ms |
5356 KB |
n=500 |
35 |
Correct |
5 ms |
5356 KB |
n=500 |
36 |
Correct |
5 ms |
5356 KB |
n=500 |
37 |
Correct |
5 ms |
5356 KB |
n=500 |
38 |
Correct |
5 ms |
5356 KB |
n=500 |
39 |
Correct |
5 ms |
5356 KB |
n=500 |
40 |
Correct |
5 ms |
5356 KB |
n=500 |
41 |
Correct |
6 ms |
5356 KB |
n=500 |
42 |
Correct |
5 ms |
5356 KB |
n=500 |
43 |
Correct |
5 ms |
5356 KB |
n=500 |
44 |
Correct |
7 ms |
5356 KB |
n=500 |
45 |
Correct |
5 ms |
5356 KB |
n=500 |
46 |
Correct |
5 ms |
5356 KB |
n=500 |
47 |
Correct |
5 ms |
5356 KB |
n=500 |
48 |
Correct |
5 ms |
5356 KB |
n=500 |
49 |
Correct |
5 ms |
5356 KB |
n=500 |
50 |
Correct |
5 ms |
5356 KB |
n=500 |
51 |
Correct |
5 ms |
5356 KB |
n=500 |
52 |
Correct |
6 ms |
5356 KB |
n=500 |
53 |
Correct |
5 ms |
5356 KB |
n=500 |
54 |
Correct |
5 ms |
5356 KB |
n=500 |
55 |
Correct |
5 ms |
5228 KB |
n=278 |
56 |
Correct |
5 ms |
5356 KB |
n=500 |
57 |
Correct |
5 ms |
5356 KB |
n=500 |
58 |
Correct |
6 ms |
5356 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5100 KB |
n=5 |
2 |
Correct |
4 ms |
5228 KB |
n=100 |
3 |
Correct |
4 ms |
5248 KB |
n=100 |
4 |
Correct |
5 ms |
5228 KB |
n=100 |
5 |
Correct |
4 ms |
5228 KB |
n=100 |
6 |
Correct |
4 ms |
5228 KB |
n=100 |
7 |
Correct |
4 ms |
5228 KB |
n=100 |
8 |
Correct |
4 ms |
5228 KB |
n=100 |
9 |
Correct |
4 ms |
5228 KB |
n=100 |
10 |
Correct |
4 ms |
5228 KB |
n=100 |
11 |
Correct |
4 ms |
5228 KB |
n=100 |
12 |
Correct |
4 ms |
5228 KB |
n=100 |
13 |
Correct |
5 ms |
5228 KB |
n=100 |
14 |
Correct |
4 ms |
5228 KB |
n=100 |
15 |
Correct |
4 ms |
5228 KB |
n=100 |
16 |
Correct |
4 ms |
5228 KB |
n=100 |
17 |
Correct |
4 ms |
5228 KB |
n=100 |
18 |
Correct |
4 ms |
5228 KB |
n=100 |
19 |
Correct |
4 ms |
5228 KB |
n=100 |
20 |
Correct |
4 ms |
5228 KB |
n=100 |
21 |
Correct |
5 ms |
5228 KB |
n=100 |
22 |
Correct |
4 ms |
5228 KB |
n=100 |
23 |
Correct |
4 ms |
5228 KB |
n=100 |
24 |
Correct |
3 ms |
5228 KB |
n=100 |
25 |
Correct |
4 ms |
5228 KB |
n=100 |
26 |
Correct |
3 ms |
5100 KB |
n=12 |
27 |
Correct |
4 ms |
5228 KB |
n=100 |
28 |
Correct |
5 ms |
5376 KB |
n=500 |
29 |
Correct |
5 ms |
5356 KB |
n=500 |
30 |
Correct |
5 ms |
5356 KB |
n=500 |
31 |
Correct |
5 ms |
5356 KB |
n=500 |
32 |
Correct |
5 ms |
5356 KB |
n=500 |
33 |
Correct |
5 ms |
5376 KB |
n=500 |
34 |
Correct |
5 ms |
5356 KB |
n=500 |
35 |
Correct |
5 ms |
5356 KB |
n=500 |
36 |
Correct |
5 ms |
5356 KB |
n=500 |
37 |
Correct |
5 ms |
5356 KB |
n=500 |
38 |
Correct |
5 ms |
5356 KB |
n=500 |
39 |
Correct |
5 ms |
5356 KB |
n=500 |
40 |
Correct |
5 ms |
5356 KB |
n=500 |
41 |
Correct |
6 ms |
5356 KB |
n=500 |
42 |
Correct |
5 ms |
5356 KB |
n=500 |
43 |
Correct |
5 ms |
5356 KB |
n=500 |
44 |
Correct |
7 ms |
5356 KB |
n=500 |
45 |
Correct |
5 ms |
5356 KB |
n=500 |
46 |
Correct |
5 ms |
5356 KB |
n=500 |
47 |
Correct |
5 ms |
5356 KB |
n=500 |
48 |
Correct |
5 ms |
5356 KB |
n=500 |
49 |
Correct |
5 ms |
5356 KB |
n=500 |
50 |
Correct |
5 ms |
5356 KB |
n=500 |
51 |
Correct |
5 ms |
5356 KB |
n=500 |
52 |
Correct |
6 ms |
5356 KB |
n=500 |
53 |
Correct |
5 ms |
5356 KB |
n=500 |
54 |
Correct |
5 ms |
5356 KB |
n=500 |
55 |
Correct |
5 ms |
5228 KB |
n=278 |
56 |
Correct |
5 ms |
5356 KB |
n=500 |
57 |
Correct |
5 ms |
5356 KB |
n=500 |
58 |
Correct |
6 ms |
5356 KB |
n=500 |
59 |
Correct |
11 ms |
5996 KB |
n=2000 |
60 |
Correct |
9 ms |
5868 KB |
n=2000 |
61 |
Correct |
9 ms |
5868 KB |
n=2000 |
62 |
Correct |
12 ms |
5868 KB |
n=2000 |
63 |
Correct |
11 ms |
6124 KB |
n=2000 |
64 |
Correct |
10 ms |
5868 KB |
n=2000 |
65 |
Correct |
10 ms |
5996 KB |
n=2000 |
66 |
Correct |
9 ms |
5888 KB |
n=2000 |
67 |
Correct |
13 ms |
5996 KB |
n=2000 |
68 |
Correct |
10 ms |
5868 KB |
n=2000 |
69 |
Correct |
11 ms |
5996 KB |
n=2000 |
70 |
Correct |
11 ms |
5996 KB |
n=2000 |
71 |
Correct |
11 ms |
5996 KB |
n=2000 |
72 |
Correct |
11 ms |
5996 KB |
n=2000 |
73 |
Correct |
10 ms |
5996 KB |
n=2000 |
74 |
Correct |
9 ms |
5868 KB |
n=1844 |
75 |
Correct |
20 ms |
5996 KB |
n=2000 |
76 |
Correct |
11 ms |
5996 KB |
n=2000 |
77 |
Correct |
10 ms |
5996 KB |
n=2000 |
78 |
Correct |
11 ms |
5996 KB |
n=2000 |
79 |
Correct |
10 ms |
5996 KB |
n=2000 |
80 |
Correct |
9 ms |
5868 KB |
n=2000 |
81 |
Correct |
10 ms |
5996 KB |
n=2000 |
82 |
Correct |
10 ms |
5996 KB |
n=2000 |
83 |
Correct |
9 ms |
5868 KB |
n=2000 |
84 |
Correct |
10 ms |
5996 KB |
n=2000 |
85 |
Correct |
10 ms |
5868 KB |
n=2000 |
86 |
Correct |
10 ms |
5868 KB |
n=2000 |
87 |
Correct |
10 ms |
5996 KB |
n=2000 |
88 |
Correct |
9 ms |
5996 KB |
n=2000 |
89 |
Correct |
9 ms |
5868 KB |
n=2000 |
90 |
Correct |
9 ms |
5868 KB |
n=2000 |
91 |
Correct |
10 ms |
5996 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5100 KB |
n=5 |
2 |
Correct |
4 ms |
5228 KB |
n=100 |
3 |
Correct |
4 ms |
5248 KB |
n=100 |
4 |
Correct |
5 ms |
5228 KB |
n=100 |
5 |
Correct |
4 ms |
5228 KB |
n=100 |
6 |
Correct |
4 ms |
5228 KB |
n=100 |
7 |
Correct |
4 ms |
5228 KB |
n=100 |
8 |
Correct |
4 ms |
5228 KB |
n=100 |
9 |
Correct |
4 ms |
5228 KB |
n=100 |
10 |
Correct |
4 ms |
5228 KB |
n=100 |
11 |
Correct |
4 ms |
5228 KB |
n=100 |
12 |
Correct |
4 ms |
5228 KB |
n=100 |
13 |
Correct |
5 ms |
5228 KB |
n=100 |
14 |
Correct |
4 ms |
5228 KB |
n=100 |
15 |
Correct |
4 ms |
5228 KB |
n=100 |
16 |
Correct |
4 ms |
5228 KB |
n=100 |
17 |
Correct |
4 ms |
5228 KB |
n=100 |
18 |
Correct |
4 ms |
5228 KB |
n=100 |
19 |
Correct |
4 ms |
5228 KB |
n=100 |
20 |
Correct |
4 ms |
5228 KB |
n=100 |
21 |
Correct |
5 ms |
5228 KB |
n=100 |
22 |
Correct |
4 ms |
5228 KB |
n=100 |
23 |
Correct |
4 ms |
5228 KB |
n=100 |
24 |
Correct |
3 ms |
5228 KB |
n=100 |
25 |
Correct |
4 ms |
5228 KB |
n=100 |
26 |
Correct |
3 ms |
5100 KB |
n=12 |
27 |
Correct |
4 ms |
5228 KB |
n=100 |
28 |
Correct |
5 ms |
5376 KB |
n=500 |
29 |
Correct |
5 ms |
5356 KB |
n=500 |
30 |
Correct |
5 ms |
5356 KB |
n=500 |
31 |
Correct |
5 ms |
5356 KB |
n=500 |
32 |
Correct |
5 ms |
5356 KB |
n=500 |
33 |
Correct |
5 ms |
5376 KB |
n=500 |
34 |
Correct |
5 ms |
5356 KB |
n=500 |
35 |
Correct |
5 ms |
5356 KB |
n=500 |
36 |
Correct |
5 ms |
5356 KB |
n=500 |
37 |
Correct |
5 ms |
5356 KB |
n=500 |
38 |
Correct |
5 ms |
5356 KB |
n=500 |
39 |
Correct |
5 ms |
5356 KB |
n=500 |
40 |
Correct |
5 ms |
5356 KB |
n=500 |
41 |
Correct |
6 ms |
5356 KB |
n=500 |
42 |
Correct |
5 ms |
5356 KB |
n=500 |
43 |
Correct |
5 ms |
5356 KB |
n=500 |
44 |
Correct |
7 ms |
5356 KB |
n=500 |
45 |
Correct |
5 ms |
5356 KB |
n=500 |
46 |
Correct |
5 ms |
5356 KB |
n=500 |
47 |
Correct |
5 ms |
5356 KB |
n=500 |
48 |
Correct |
5 ms |
5356 KB |
n=500 |
49 |
Correct |
5 ms |
5356 KB |
n=500 |
50 |
Correct |
5 ms |
5356 KB |
n=500 |
51 |
Correct |
5 ms |
5356 KB |
n=500 |
52 |
Correct |
6 ms |
5356 KB |
n=500 |
53 |
Correct |
5 ms |
5356 KB |
n=500 |
54 |
Correct |
5 ms |
5356 KB |
n=500 |
55 |
Correct |
5 ms |
5228 KB |
n=278 |
56 |
Correct |
5 ms |
5356 KB |
n=500 |
57 |
Correct |
5 ms |
5356 KB |
n=500 |
58 |
Correct |
6 ms |
5356 KB |
n=500 |
59 |
Correct |
11 ms |
5996 KB |
n=2000 |
60 |
Correct |
9 ms |
5868 KB |
n=2000 |
61 |
Correct |
9 ms |
5868 KB |
n=2000 |
62 |
Correct |
12 ms |
5868 KB |
n=2000 |
63 |
Correct |
11 ms |
6124 KB |
n=2000 |
64 |
Correct |
10 ms |
5868 KB |
n=2000 |
65 |
Correct |
10 ms |
5996 KB |
n=2000 |
66 |
Correct |
9 ms |
5888 KB |
n=2000 |
67 |
Correct |
13 ms |
5996 KB |
n=2000 |
68 |
Correct |
10 ms |
5868 KB |
n=2000 |
69 |
Correct |
11 ms |
5996 KB |
n=2000 |
70 |
Correct |
11 ms |
5996 KB |
n=2000 |
71 |
Correct |
11 ms |
5996 KB |
n=2000 |
72 |
Correct |
11 ms |
5996 KB |
n=2000 |
73 |
Correct |
10 ms |
5996 KB |
n=2000 |
74 |
Correct |
9 ms |
5868 KB |
n=1844 |
75 |
Correct |
20 ms |
5996 KB |
n=2000 |
76 |
Correct |
11 ms |
5996 KB |
n=2000 |
77 |
Correct |
10 ms |
5996 KB |
n=2000 |
78 |
Correct |
11 ms |
5996 KB |
n=2000 |
79 |
Correct |
10 ms |
5996 KB |
n=2000 |
80 |
Correct |
9 ms |
5868 KB |
n=2000 |
81 |
Correct |
10 ms |
5996 KB |
n=2000 |
82 |
Correct |
10 ms |
5996 KB |
n=2000 |
83 |
Correct |
9 ms |
5868 KB |
n=2000 |
84 |
Correct |
10 ms |
5996 KB |
n=2000 |
85 |
Correct |
10 ms |
5868 KB |
n=2000 |
86 |
Correct |
10 ms |
5868 KB |
n=2000 |
87 |
Correct |
10 ms |
5996 KB |
n=2000 |
88 |
Correct |
9 ms |
5996 KB |
n=2000 |
89 |
Correct |
9 ms |
5868 KB |
n=2000 |
90 |
Correct |
9 ms |
5868 KB |
n=2000 |
91 |
Correct |
10 ms |
5996 KB |
n=2000 |
92 |
Correct |
2089 ms |
83304 KB |
n=200000 |
93 |
Correct |
1701 ms |
82416 KB |
n=200000 |
94 |
Correct |
1435 ms |
81772 KB |
n=200000 |
95 |
Correct |
2001 ms |
83204 KB |
n=200000 |
96 |
Correct |
1902 ms |
82992 KB |
n=200000 |
97 |
Correct |
1805 ms |
82544 KB |
n=200000 |
98 |
Correct |
1937 ms |
83112 KB |
n=200000 |
99 |
Correct |
2207 ms |
82668 KB |
n=200000 |
100 |
Correct |
1968 ms |
83296 KB |
n=200000 |
101 |
Correct |
1371 ms |
81644 KB |
n=200000 |
102 |
Correct |
1207 ms |
84492 KB |
n=200000 |
103 |
Correct |
1198 ms |
84204 KB |
n=200000 |
104 |
Correct |
1209 ms |
84172 KB |
n=200000 |
105 |
Correct |
1223 ms |
84204 KB |
n=200000 |
106 |
Correct |
1203 ms |
83948 KB |
n=200000 |
107 |
Correct |
1226 ms |
84132 KB |
n=200000 |
108 |
Correct |
2086 ms |
83456 KB |
n=200000 |
109 |
Correct |
2052 ms |
83052 KB |
n=200000 |
110 |
Correct |
2085 ms |
83000 KB |
n=200000 |
111 |
Correct |
1782 ms |
82908 KB |
n=200000 |
112 |
Correct |
1397 ms |
81516 KB |
n=200000 |
113 |
Correct |
1711 ms |
82156 KB |
n=200000 |
114 |
Correct |
1777 ms |
82908 KB |
n=200000 |
115 |
Correct |
2130 ms |
82284 KB |
n=200000 |
116 |
Correct |
1878 ms |
82652 KB |
n=200000 |
117 |
Correct |
1362 ms |
81132 KB |
n=200000 |
118 |
Correct |
1874 ms |
82064 KB |
n=200000 |
119 |
Correct |
1943 ms |
82780 KB |
n=200000 |
120 |
Correct |
1303 ms |
80996 KB |
n=200000 |
121 |
Correct |
1297 ms |
80748 KB |
n=200000 |
122 |
Correct |
1344 ms |
81408 KB |
n=200000 |
123 |
Correct |
1234 ms |
83564 KB |
n=200000 |
124 |
Correct |
400 ms |
21704 KB |
n=25264 |