#include <bits/stdc++.h>
#define pb push_back
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(data) data.begin() , data.end()
#define endl '\n'
//freopen("nenokku_easy.in", "r", stdin);
//freopen("nenokku_easy.out", "w", stdout);
//#define int long long
#define pii pair < int, int >
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
const int lg = 21;
int n, m, q, tin[N], tout[N], sz, up[N][lg], a[N];
vector < int > g[N];
void dfs(int v, int pr) {
tin[v] = ++sz;
up[v][0] = pr;
for(int i = 1; i < lg; i++) {
up[v][i] = up[up[v][i - 1]][i - 1];
}
for(int i = 0; i < g[v].size(); i++) {
int to = g[v][i];
if(to != pr) {
dfs(to, v);
}
}
tout[v] = ++sz;
}
bool upper(int x, int y) {
return tin[x] <= tin[y] && tout[x] >= tout[y];
}
int lca(int x, int y) {
if(upper(x, y)) return x;
if(upper(y, x)) return y;
for(int i = lg - 1; i >= 0; i--) {
if(up[x][i] == 0) continue;
if(!upper(up[x][i], y)) {
x = up[x][i];
}
}
return up[x][0];
}
main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> q;
for(int i = 1; i < n; i++) {
int a, b;
cin >> a >> b;
g[a].pb(b);
g[b].pb(a);
}
dfs(1, 1);
multiset < int > st1[N];
for(int i = 1; i <= m; i++) {
cin >> a[i];
st1[a[i]].insert(i);
}
multiset < int > st2[N];
for(int i = 1; i < m; i++) {
int lc = lca(a[i], a[i + 1]);
st2[lc].insert(i);
}
while(q--) {
int tp, pos, l, r, v;
cin >> tp;
if(tp % 2) {
cin >> pos >> v;
st1[a[pos]].erase(pos);
st1[v].insert(pos);
if(pos != 1) {
st2[lca(a[pos - 1], a[pos])].erase(pos - 1);
}
if(pos != m) {
st2[lca(a[pos + 1], a[pos])].erase(pos);
}
if(pos != 1) {
st2[lca(a[pos - 1], v)].insert(pos - 1);
}
if(pos != m) {
st2[lca(a[pos + 1], v)].insert(pos);
}
a[pos] = v;
} else {
cin >> l >> r >> v;
if(st1[v].size()) {
int res = *st1[v].lower_bound(l);
if(l <= res && res <= r) {
cout << res << " " << res << endl;
continue;
}
}
if(st2[v].size()) {
int res = *st2[v].lower_bound(l);
if(l <= res && res < r) {
cout << res << " " << res + 1 << endl;
continue;
}
}
cout << "-1 -1\n";
}
}
}
Compilation message
treearray.cpp: In function 'void dfs(int, int)':
treearray.cpp:26:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for(int i = 0; i < g[v].size(); i++) {
| ~~^~~~~~~~~~~~~
treearray.cpp: At global scope:
treearray.cpp:51:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
51 | main() {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23780 KB |
n=5 |
2 |
Correct |
16 ms |
23732 KB |
n=100 |
3 |
Correct |
14 ms |
23756 KB |
n=100 |
4 |
Correct |
13 ms |
23756 KB |
n=100 |
5 |
Correct |
14 ms |
23756 KB |
n=100 |
6 |
Correct |
14 ms |
23756 KB |
n=100 |
7 |
Correct |
15 ms |
23736 KB |
n=100 |
8 |
Correct |
14 ms |
23844 KB |
n=100 |
9 |
Correct |
14 ms |
23832 KB |
n=100 |
10 |
Correct |
14 ms |
23792 KB |
n=100 |
11 |
Correct |
13 ms |
23716 KB |
n=100 |
12 |
Correct |
13 ms |
23832 KB |
n=100 |
13 |
Correct |
14 ms |
23756 KB |
n=100 |
14 |
Correct |
14 ms |
23756 KB |
n=100 |
15 |
Correct |
14 ms |
23756 KB |
n=100 |
16 |
Correct |
19 ms |
23764 KB |
n=100 |
17 |
Correct |
16 ms |
23756 KB |
n=100 |
18 |
Correct |
14 ms |
23756 KB |
n=100 |
19 |
Correct |
15 ms |
23756 KB |
n=100 |
20 |
Correct |
16 ms |
23820 KB |
n=100 |
21 |
Correct |
14 ms |
23732 KB |
n=100 |
22 |
Correct |
15 ms |
23800 KB |
n=100 |
23 |
Correct |
15 ms |
23756 KB |
n=100 |
24 |
Correct |
15 ms |
23756 KB |
n=100 |
25 |
Correct |
19 ms |
23776 KB |
n=100 |
26 |
Correct |
15 ms |
23756 KB |
n=12 |
27 |
Correct |
15 ms |
23808 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23780 KB |
n=5 |
2 |
Correct |
16 ms |
23732 KB |
n=100 |
3 |
Correct |
14 ms |
23756 KB |
n=100 |
4 |
Correct |
13 ms |
23756 KB |
n=100 |
5 |
Correct |
14 ms |
23756 KB |
n=100 |
6 |
Correct |
14 ms |
23756 KB |
n=100 |
7 |
Correct |
15 ms |
23736 KB |
n=100 |
8 |
Correct |
14 ms |
23844 KB |
n=100 |
9 |
Correct |
14 ms |
23832 KB |
n=100 |
10 |
Correct |
14 ms |
23792 KB |
n=100 |
11 |
Correct |
13 ms |
23716 KB |
n=100 |
12 |
Correct |
13 ms |
23832 KB |
n=100 |
13 |
Correct |
14 ms |
23756 KB |
n=100 |
14 |
Correct |
14 ms |
23756 KB |
n=100 |
15 |
Correct |
14 ms |
23756 KB |
n=100 |
16 |
Correct |
19 ms |
23764 KB |
n=100 |
17 |
Correct |
16 ms |
23756 KB |
n=100 |
18 |
Correct |
14 ms |
23756 KB |
n=100 |
19 |
Correct |
15 ms |
23756 KB |
n=100 |
20 |
Correct |
16 ms |
23820 KB |
n=100 |
21 |
Correct |
14 ms |
23732 KB |
n=100 |
22 |
Correct |
15 ms |
23800 KB |
n=100 |
23 |
Correct |
15 ms |
23756 KB |
n=100 |
24 |
Correct |
15 ms |
23756 KB |
n=100 |
25 |
Correct |
19 ms |
23776 KB |
n=100 |
26 |
Correct |
15 ms |
23756 KB |
n=12 |
27 |
Correct |
15 ms |
23808 KB |
n=100 |
28 |
Correct |
16 ms |
23884 KB |
n=500 |
29 |
Correct |
14 ms |
23920 KB |
n=500 |
30 |
Correct |
14 ms |
23928 KB |
n=500 |
31 |
Correct |
14 ms |
23884 KB |
n=500 |
32 |
Correct |
15 ms |
23828 KB |
n=500 |
33 |
Correct |
15 ms |
23884 KB |
n=500 |
34 |
Correct |
16 ms |
23924 KB |
n=500 |
35 |
Correct |
17 ms |
23884 KB |
n=500 |
36 |
Correct |
15 ms |
23812 KB |
n=500 |
37 |
Correct |
16 ms |
23840 KB |
n=500 |
38 |
Correct |
15 ms |
23884 KB |
n=500 |
39 |
Correct |
15 ms |
23848 KB |
n=500 |
40 |
Correct |
14 ms |
23884 KB |
n=500 |
41 |
Correct |
15 ms |
23884 KB |
n=500 |
42 |
Correct |
16 ms |
23868 KB |
n=500 |
43 |
Correct |
17 ms |
23884 KB |
n=500 |
44 |
Correct |
16 ms |
23908 KB |
n=500 |
45 |
Correct |
15 ms |
23884 KB |
n=500 |
46 |
Correct |
15 ms |
23940 KB |
n=500 |
47 |
Correct |
16 ms |
23936 KB |
n=500 |
48 |
Correct |
16 ms |
23888 KB |
n=500 |
49 |
Correct |
14 ms |
23884 KB |
n=500 |
50 |
Correct |
15 ms |
23884 KB |
n=500 |
51 |
Correct |
16 ms |
23924 KB |
n=500 |
52 |
Correct |
15 ms |
23884 KB |
n=500 |
53 |
Correct |
15 ms |
23940 KB |
n=500 |
54 |
Correct |
15 ms |
23940 KB |
n=500 |
55 |
Correct |
19 ms |
23888 KB |
n=278 |
56 |
Correct |
15 ms |
23884 KB |
n=500 |
57 |
Correct |
16 ms |
23936 KB |
n=500 |
58 |
Correct |
15 ms |
23936 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23780 KB |
n=5 |
2 |
Correct |
16 ms |
23732 KB |
n=100 |
3 |
Correct |
14 ms |
23756 KB |
n=100 |
4 |
Correct |
13 ms |
23756 KB |
n=100 |
5 |
Correct |
14 ms |
23756 KB |
n=100 |
6 |
Correct |
14 ms |
23756 KB |
n=100 |
7 |
Correct |
15 ms |
23736 KB |
n=100 |
8 |
Correct |
14 ms |
23844 KB |
n=100 |
9 |
Correct |
14 ms |
23832 KB |
n=100 |
10 |
Correct |
14 ms |
23792 KB |
n=100 |
11 |
Correct |
13 ms |
23716 KB |
n=100 |
12 |
Correct |
13 ms |
23832 KB |
n=100 |
13 |
Correct |
14 ms |
23756 KB |
n=100 |
14 |
Correct |
14 ms |
23756 KB |
n=100 |
15 |
Correct |
14 ms |
23756 KB |
n=100 |
16 |
Correct |
19 ms |
23764 KB |
n=100 |
17 |
Correct |
16 ms |
23756 KB |
n=100 |
18 |
Correct |
14 ms |
23756 KB |
n=100 |
19 |
Correct |
15 ms |
23756 KB |
n=100 |
20 |
Correct |
16 ms |
23820 KB |
n=100 |
21 |
Correct |
14 ms |
23732 KB |
n=100 |
22 |
Correct |
15 ms |
23800 KB |
n=100 |
23 |
Correct |
15 ms |
23756 KB |
n=100 |
24 |
Correct |
15 ms |
23756 KB |
n=100 |
25 |
Correct |
19 ms |
23776 KB |
n=100 |
26 |
Correct |
15 ms |
23756 KB |
n=12 |
27 |
Correct |
15 ms |
23808 KB |
n=100 |
28 |
Correct |
16 ms |
23884 KB |
n=500 |
29 |
Correct |
14 ms |
23920 KB |
n=500 |
30 |
Correct |
14 ms |
23928 KB |
n=500 |
31 |
Correct |
14 ms |
23884 KB |
n=500 |
32 |
Correct |
15 ms |
23828 KB |
n=500 |
33 |
Correct |
15 ms |
23884 KB |
n=500 |
34 |
Correct |
16 ms |
23924 KB |
n=500 |
35 |
Correct |
17 ms |
23884 KB |
n=500 |
36 |
Correct |
15 ms |
23812 KB |
n=500 |
37 |
Correct |
16 ms |
23840 KB |
n=500 |
38 |
Correct |
15 ms |
23884 KB |
n=500 |
39 |
Correct |
15 ms |
23848 KB |
n=500 |
40 |
Correct |
14 ms |
23884 KB |
n=500 |
41 |
Correct |
15 ms |
23884 KB |
n=500 |
42 |
Correct |
16 ms |
23868 KB |
n=500 |
43 |
Correct |
17 ms |
23884 KB |
n=500 |
44 |
Correct |
16 ms |
23908 KB |
n=500 |
45 |
Correct |
15 ms |
23884 KB |
n=500 |
46 |
Correct |
15 ms |
23940 KB |
n=500 |
47 |
Correct |
16 ms |
23936 KB |
n=500 |
48 |
Correct |
16 ms |
23888 KB |
n=500 |
49 |
Correct |
14 ms |
23884 KB |
n=500 |
50 |
Correct |
15 ms |
23884 KB |
n=500 |
51 |
Correct |
16 ms |
23924 KB |
n=500 |
52 |
Correct |
15 ms |
23884 KB |
n=500 |
53 |
Correct |
15 ms |
23940 KB |
n=500 |
54 |
Correct |
15 ms |
23940 KB |
n=500 |
55 |
Correct |
19 ms |
23888 KB |
n=278 |
56 |
Correct |
15 ms |
23884 KB |
n=500 |
57 |
Correct |
16 ms |
23936 KB |
n=500 |
58 |
Correct |
15 ms |
23936 KB |
n=500 |
59 |
Correct |
18 ms |
24268 KB |
n=2000 |
60 |
Correct |
17 ms |
24360 KB |
n=2000 |
61 |
Correct |
20 ms |
24328 KB |
n=2000 |
62 |
Correct |
19 ms |
24304 KB |
n=2000 |
63 |
Correct |
17 ms |
24240 KB |
n=2000 |
64 |
Correct |
17 ms |
24248 KB |
n=2000 |
65 |
Correct |
18 ms |
24268 KB |
n=2000 |
66 |
Correct |
18 ms |
24272 KB |
n=2000 |
67 |
Correct |
21 ms |
24264 KB |
n=2000 |
68 |
Correct |
17 ms |
24268 KB |
n=2000 |
69 |
Correct |
19 ms |
24192 KB |
n=2000 |
70 |
Correct |
16 ms |
24288 KB |
n=2000 |
71 |
Correct |
17 ms |
24284 KB |
n=2000 |
72 |
Correct |
16 ms |
24268 KB |
n=2000 |
73 |
Correct |
16 ms |
24268 KB |
n=2000 |
74 |
Correct |
16 ms |
24196 KB |
n=1844 |
75 |
Correct |
16 ms |
24268 KB |
n=2000 |
76 |
Correct |
20 ms |
24196 KB |
n=2000 |
77 |
Correct |
18 ms |
24264 KB |
n=2000 |
78 |
Correct |
18 ms |
24232 KB |
n=2000 |
79 |
Correct |
18 ms |
24272 KB |
n=2000 |
80 |
Correct |
16 ms |
24268 KB |
n=2000 |
81 |
Correct |
18 ms |
24320 KB |
n=2000 |
82 |
Correct |
17 ms |
24272 KB |
n=2000 |
83 |
Correct |
18 ms |
24260 KB |
n=2000 |
84 |
Correct |
19 ms |
24268 KB |
n=2000 |
85 |
Correct |
18 ms |
24268 KB |
n=2000 |
86 |
Correct |
17 ms |
24268 KB |
n=2000 |
87 |
Correct |
20 ms |
24176 KB |
n=2000 |
88 |
Correct |
16 ms |
24396 KB |
n=2000 |
89 |
Correct |
17 ms |
24288 KB |
n=2000 |
90 |
Correct |
17 ms |
24256 KB |
n=2000 |
91 |
Correct |
16 ms |
24252 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23780 KB |
n=5 |
2 |
Correct |
16 ms |
23732 KB |
n=100 |
3 |
Correct |
14 ms |
23756 KB |
n=100 |
4 |
Correct |
13 ms |
23756 KB |
n=100 |
5 |
Correct |
14 ms |
23756 KB |
n=100 |
6 |
Correct |
14 ms |
23756 KB |
n=100 |
7 |
Correct |
15 ms |
23736 KB |
n=100 |
8 |
Correct |
14 ms |
23844 KB |
n=100 |
9 |
Correct |
14 ms |
23832 KB |
n=100 |
10 |
Correct |
14 ms |
23792 KB |
n=100 |
11 |
Correct |
13 ms |
23716 KB |
n=100 |
12 |
Correct |
13 ms |
23832 KB |
n=100 |
13 |
Correct |
14 ms |
23756 KB |
n=100 |
14 |
Correct |
14 ms |
23756 KB |
n=100 |
15 |
Correct |
14 ms |
23756 KB |
n=100 |
16 |
Correct |
19 ms |
23764 KB |
n=100 |
17 |
Correct |
16 ms |
23756 KB |
n=100 |
18 |
Correct |
14 ms |
23756 KB |
n=100 |
19 |
Correct |
15 ms |
23756 KB |
n=100 |
20 |
Correct |
16 ms |
23820 KB |
n=100 |
21 |
Correct |
14 ms |
23732 KB |
n=100 |
22 |
Correct |
15 ms |
23800 KB |
n=100 |
23 |
Correct |
15 ms |
23756 KB |
n=100 |
24 |
Correct |
15 ms |
23756 KB |
n=100 |
25 |
Correct |
19 ms |
23776 KB |
n=100 |
26 |
Correct |
15 ms |
23756 KB |
n=12 |
27 |
Correct |
15 ms |
23808 KB |
n=100 |
28 |
Correct |
16 ms |
23884 KB |
n=500 |
29 |
Correct |
14 ms |
23920 KB |
n=500 |
30 |
Correct |
14 ms |
23928 KB |
n=500 |
31 |
Correct |
14 ms |
23884 KB |
n=500 |
32 |
Correct |
15 ms |
23828 KB |
n=500 |
33 |
Correct |
15 ms |
23884 KB |
n=500 |
34 |
Correct |
16 ms |
23924 KB |
n=500 |
35 |
Correct |
17 ms |
23884 KB |
n=500 |
36 |
Correct |
15 ms |
23812 KB |
n=500 |
37 |
Correct |
16 ms |
23840 KB |
n=500 |
38 |
Correct |
15 ms |
23884 KB |
n=500 |
39 |
Correct |
15 ms |
23848 KB |
n=500 |
40 |
Correct |
14 ms |
23884 KB |
n=500 |
41 |
Correct |
15 ms |
23884 KB |
n=500 |
42 |
Correct |
16 ms |
23868 KB |
n=500 |
43 |
Correct |
17 ms |
23884 KB |
n=500 |
44 |
Correct |
16 ms |
23908 KB |
n=500 |
45 |
Correct |
15 ms |
23884 KB |
n=500 |
46 |
Correct |
15 ms |
23940 KB |
n=500 |
47 |
Correct |
16 ms |
23936 KB |
n=500 |
48 |
Correct |
16 ms |
23888 KB |
n=500 |
49 |
Correct |
14 ms |
23884 KB |
n=500 |
50 |
Correct |
15 ms |
23884 KB |
n=500 |
51 |
Correct |
16 ms |
23924 KB |
n=500 |
52 |
Correct |
15 ms |
23884 KB |
n=500 |
53 |
Correct |
15 ms |
23940 KB |
n=500 |
54 |
Correct |
15 ms |
23940 KB |
n=500 |
55 |
Correct |
19 ms |
23888 KB |
n=278 |
56 |
Correct |
15 ms |
23884 KB |
n=500 |
57 |
Correct |
16 ms |
23936 KB |
n=500 |
58 |
Correct |
15 ms |
23936 KB |
n=500 |
59 |
Correct |
18 ms |
24268 KB |
n=2000 |
60 |
Correct |
17 ms |
24360 KB |
n=2000 |
61 |
Correct |
20 ms |
24328 KB |
n=2000 |
62 |
Correct |
19 ms |
24304 KB |
n=2000 |
63 |
Correct |
17 ms |
24240 KB |
n=2000 |
64 |
Correct |
17 ms |
24248 KB |
n=2000 |
65 |
Correct |
18 ms |
24268 KB |
n=2000 |
66 |
Correct |
18 ms |
24272 KB |
n=2000 |
67 |
Correct |
21 ms |
24264 KB |
n=2000 |
68 |
Correct |
17 ms |
24268 KB |
n=2000 |
69 |
Correct |
19 ms |
24192 KB |
n=2000 |
70 |
Correct |
16 ms |
24288 KB |
n=2000 |
71 |
Correct |
17 ms |
24284 KB |
n=2000 |
72 |
Correct |
16 ms |
24268 KB |
n=2000 |
73 |
Correct |
16 ms |
24268 KB |
n=2000 |
74 |
Correct |
16 ms |
24196 KB |
n=1844 |
75 |
Correct |
16 ms |
24268 KB |
n=2000 |
76 |
Correct |
20 ms |
24196 KB |
n=2000 |
77 |
Correct |
18 ms |
24264 KB |
n=2000 |
78 |
Correct |
18 ms |
24232 KB |
n=2000 |
79 |
Correct |
18 ms |
24272 KB |
n=2000 |
80 |
Correct |
16 ms |
24268 KB |
n=2000 |
81 |
Correct |
18 ms |
24320 KB |
n=2000 |
82 |
Correct |
17 ms |
24272 KB |
n=2000 |
83 |
Correct |
18 ms |
24260 KB |
n=2000 |
84 |
Correct |
19 ms |
24268 KB |
n=2000 |
85 |
Correct |
18 ms |
24268 KB |
n=2000 |
86 |
Correct |
17 ms |
24268 KB |
n=2000 |
87 |
Correct |
20 ms |
24176 KB |
n=2000 |
88 |
Correct |
16 ms |
24396 KB |
n=2000 |
89 |
Correct |
17 ms |
24288 KB |
n=2000 |
90 |
Correct |
17 ms |
24256 KB |
n=2000 |
91 |
Correct |
16 ms |
24252 KB |
n=2000 |
92 |
Correct |
710 ms |
69656 KB |
n=200000 |
93 |
Correct |
832 ms |
74880 KB |
n=200000 |
94 |
Correct |
591 ms |
79324 KB |
n=200000 |
95 |
Correct |
641 ms |
69412 KB |
n=200000 |
96 |
Correct |
704 ms |
69476 KB |
n=200000 |
97 |
Correct |
882 ms |
73668 KB |
n=200000 |
98 |
Correct |
768 ms |
69460 KB |
n=200000 |
99 |
Correct |
967 ms |
68916 KB |
n=200000 |
100 |
Correct |
735 ms |
69544 KB |
n=200000 |
101 |
Correct |
604 ms |
80980 KB |
n=200000 |
102 |
Correct |
476 ms |
70388 KB |
n=200000 |
103 |
Correct |
454 ms |
70396 KB |
n=200000 |
104 |
Correct |
493 ms |
70328 KB |
n=200000 |
105 |
Correct |
426 ms |
70156 KB |
n=200000 |
106 |
Correct |
473 ms |
70164 KB |
n=200000 |
107 |
Correct |
433 ms |
70176 KB |
n=200000 |
108 |
Correct |
763 ms |
69068 KB |
n=200000 |
109 |
Correct |
920 ms |
69124 KB |
n=200000 |
110 |
Correct |
911 ms |
69144 KB |
n=200000 |
111 |
Correct |
818 ms |
69336 KB |
n=200000 |
112 |
Correct |
698 ms |
79616 KB |
n=200000 |
113 |
Correct |
1088 ms |
73620 KB |
n=200000 |
114 |
Correct |
871 ms |
69528 KB |
n=200000 |
115 |
Correct |
1228 ms |
70908 KB |
n=200000 |
116 |
Correct |
759 ms |
69732 KB |
n=200000 |
117 |
Correct |
638 ms |
80940 KB |
n=200000 |
118 |
Correct |
1217 ms |
73288 KB |
n=200000 |
119 |
Correct |
723 ms |
70456 KB |
n=200000 |
120 |
Correct |
526 ms |
81976 KB |
n=200000 |
121 |
Correct |
477 ms |
81996 KB |
n=200000 |
122 |
Correct |
453 ms |
82532 KB |
n=200000 |
123 |
Correct |
423 ms |
71040 KB |
n=200000 |
124 |
Correct |
191 ms |
38592 KB |
n=25264 |