//#pragma GCC target("avx2")
//#pragma GCC optimization("O3")
//#pragma GCC optimization("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
using namespace std;
const int N = 2 * 1e5 + 5;
const int MOD = 1e9 + 7;
const int K = 18;
int n, m, q, a[N], par[N][K], h[N];
vector<int> g[N];
pair<int, int> ans;
set<int> :: iterator it;
set<int> ans1[N], ans2[N];
void dfs(int v, int pr){
par[v][0] = pr;
for(int to : g[v]){
if(to != pr){
h[to] = h[v] + 1;
dfs(to, v);
}
}
}
bool bit(int x, int p){
return x & (1 << p);
}
int lift(int v, int k){
for(int i = 0; i < K; i++){
if (bit(k, i)) {
v = par[v][i];
}
}
return v;
}
int lca(int a, int b){
if(h[a] < h[b]){
swap(a, b);
}
a = lift(a, h[a] - h[b]);
if(a == b){
return a;
}
for(int i = K - 1; i >= 0; --i){
if(par[a][i] != par[b][i]){
a = par[a][i];
b = par[b][i];
}
}
return par[a][0];
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> q;
for(int i = 1, u, v; i < n; i++){
cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
}
dfs(1, 1);
for(int i = 1; i < K; i++){
for(int v = 1; v <= n; v++){
par[v][i] = par[par[v][i - 1]][i - 1];
}
}
for(int i = 1; i <= m; ++i){
cin >> a[i];
ans1[a[i]].insert(i);
if(i > 1) ans2[lca(a[i], a[i - 1])].insert(i - 1);
}
int pos, v, l, r, typ;
for (int j = 1; j <= q; j++) {
cin >> typ;
// cout << q << '\n';
if(typ == 1){
int i;
cin >> i >> v;
ans1[a[i]].erase(i);
if(i > 1) ans2[lca(a[i], a[i - 1])].erase(i - 1);
if(i < m){
ans2[lca(a[i], a[i + 1])].erase(i);
}
a[i] = v;
ans1[a[i]].insert(i);
if(i > 1) ans2[lca(a[i], a[i - 1])].insert(i - 1);
if(i < m){
ans2[lca(a[i], a[i + 1])].insert(i);
}
}
else{
cin >> l >> r >> v;
if(ans1[v].empty() && ans2[v].empty()) {cout << "-1 -1\n"; continue;}
else{
bool ok = 0;
if(ans1[v].size()){
it = ans1[v].lower_bound(l);
if(it != ans1[v].end() && *it <= r) ok = 1;
}
if(ok) {cout << *it << ' ' << *it << '\n'; continue;}
if(ans2[v].size()){
it = ans2[v].lower_bound(l);
if(it != ans2[v].end() && *it < r) ok = 1;
}
if(ok) {cout << *it << ' ' << *it + 1 << '\n'; continue;}
}
cout << "-1 -1\n";
}
}
return 0;
}
Compilation message
treearray.cpp: In function 'int main()':
treearray.cpp:95:9: warning: unused variable 'pos' [-Wunused-variable]
95 | int pos, v, l, r, typ;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23756 KB |
n=5 |
2 |
Correct |
15 ms |
23828 KB |
n=100 |
3 |
Correct |
13 ms |
23792 KB |
n=100 |
4 |
Correct |
13 ms |
23756 KB |
n=100 |
5 |
Correct |
14 ms |
23828 KB |
n=100 |
6 |
Correct |
12 ms |
23756 KB |
n=100 |
7 |
Correct |
11 ms |
23756 KB |
n=100 |
8 |
Correct |
12 ms |
23828 KB |
n=100 |
9 |
Correct |
11 ms |
23824 KB |
n=100 |
10 |
Correct |
17 ms |
23756 KB |
n=100 |
11 |
Correct |
12 ms |
23756 KB |
n=100 |
12 |
Correct |
13 ms |
23756 KB |
n=100 |
13 |
Correct |
14 ms |
23824 KB |
n=100 |
14 |
Correct |
15 ms |
23756 KB |
n=100 |
15 |
Correct |
11 ms |
23768 KB |
n=100 |
16 |
Correct |
17 ms |
23824 KB |
n=100 |
17 |
Correct |
13 ms |
23828 KB |
n=100 |
18 |
Correct |
12 ms |
23828 KB |
n=100 |
19 |
Correct |
13 ms |
23756 KB |
n=100 |
20 |
Correct |
11 ms |
23756 KB |
n=100 |
21 |
Correct |
16 ms |
23832 KB |
n=100 |
22 |
Correct |
15 ms |
23788 KB |
n=100 |
23 |
Correct |
14 ms |
23836 KB |
n=100 |
24 |
Correct |
11 ms |
23756 KB |
n=100 |
25 |
Correct |
12 ms |
23808 KB |
n=100 |
26 |
Correct |
12 ms |
23688 KB |
n=12 |
27 |
Correct |
11 ms |
23756 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23756 KB |
n=5 |
2 |
Correct |
15 ms |
23828 KB |
n=100 |
3 |
Correct |
13 ms |
23792 KB |
n=100 |
4 |
Correct |
13 ms |
23756 KB |
n=100 |
5 |
Correct |
14 ms |
23828 KB |
n=100 |
6 |
Correct |
12 ms |
23756 KB |
n=100 |
7 |
Correct |
11 ms |
23756 KB |
n=100 |
8 |
Correct |
12 ms |
23828 KB |
n=100 |
9 |
Correct |
11 ms |
23824 KB |
n=100 |
10 |
Correct |
17 ms |
23756 KB |
n=100 |
11 |
Correct |
12 ms |
23756 KB |
n=100 |
12 |
Correct |
13 ms |
23756 KB |
n=100 |
13 |
Correct |
14 ms |
23824 KB |
n=100 |
14 |
Correct |
15 ms |
23756 KB |
n=100 |
15 |
Correct |
11 ms |
23768 KB |
n=100 |
16 |
Correct |
17 ms |
23824 KB |
n=100 |
17 |
Correct |
13 ms |
23828 KB |
n=100 |
18 |
Correct |
12 ms |
23828 KB |
n=100 |
19 |
Correct |
13 ms |
23756 KB |
n=100 |
20 |
Correct |
11 ms |
23756 KB |
n=100 |
21 |
Correct |
16 ms |
23832 KB |
n=100 |
22 |
Correct |
15 ms |
23788 KB |
n=100 |
23 |
Correct |
14 ms |
23836 KB |
n=100 |
24 |
Correct |
11 ms |
23756 KB |
n=100 |
25 |
Correct |
12 ms |
23808 KB |
n=100 |
26 |
Correct |
12 ms |
23688 KB |
n=12 |
27 |
Correct |
11 ms |
23756 KB |
n=100 |
28 |
Correct |
12 ms |
23884 KB |
n=500 |
29 |
Correct |
13 ms |
23860 KB |
n=500 |
30 |
Correct |
13 ms |
23904 KB |
n=500 |
31 |
Correct |
12 ms |
23840 KB |
n=500 |
32 |
Correct |
13 ms |
23920 KB |
n=500 |
33 |
Correct |
13 ms |
23884 KB |
n=500 |
34 |
Correct |
12 ms |
23884 KB |
n=500 |
35 |
Correct |
13 ms |
23840 KB |
n=500 |
36 |
Correct |
12 ms |
23884 KB |
n=500 |
37 |
Correct |
17 ms |
23868 KB |
n=500 |
38 |
Correct |
15 ms |
23888 KB |
n=500 |
39 |
Correct |
11 ms |
23884 KB |
n=500 |
40 |
Correct |
12 ms |
23884 KB |
n=500 |
41 |
Correct |
13 ms |
23884 KB |
n=500 |
42 |
Correct |
15 ms |
23908 KB |
n=500 |
43 |
Correct |
16 ms |
23928 KB |
n=500 |
44 |
Correct |
16 ms |
23884 KB |
n=500 |
45 |
Correct |
14 ms |
23844 KB |
n=500 |
46 |
Correct |
14 ms |
23940 KB |
n=500 |
47 |
Correct |
13 ms |
23856 KB |
n=500 |
48 |
Correct |
12 ms |
23884 KB |
n=500 |
49 |
Correct |
13 ms |
23840 KB |
n=500 |
50 |
Correct |
16 ms |
23884 KB |
n=500 |
51 |
Correct |
19 ms |
23952 KB |
n=500 |
52 |
Correct |
14 ms |
23884 KB |
n=500 |
53 |
Correct |
13 ms |
23908 KB |
n=500 |
54 |
Correct |
13 ms |
23844 KB |
n=500 |
55 |
Correct |
12 ms |
23884 KB |
n=278 |
56 |
Correct |
18 ms |
23940 KB |
n=500 |
57 |
Correct |
12 ms |
23928 KB |
n=500 |
58 |
Correct |
16 ms |
23824 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23756 KB |
n=5 |
2 |
Correct |
15 ms |
23828 KB |
n=100 |
3 |
Correct |
13 ms |
23792 KB |
n=100 |
4 |
Correct |
13 ms |
23756 KB |
n=100 |
5 |
Correct |
14 ms |
23828 KB |
n=100 |
6 |
Correct |
12 ms |
23756 KB |
n=100 |
7 |
Correct |
11 ms |
23756 KB |
n=100 |
8 |
Correct |
12 ms |
23828 KB |
n=100 |
9 |
Correct |
11 ms |
23824 KB |
n=100 |
10 |
Correct |
17 ms |
23756 KB |
n=100 |
11 |
Correct |
12 ms |
23756 KB |
n=100 |
12 |
Correct |
13 ms |
23756 KB |
n=100 |
13 |
Correct |
14 ms |
23824 KB |
n=100 |
14 |
Correct |
15 ms |
23756 KB |
n=100 |
15 |
Correct |
11 ms |
23768 KB |
n=100 |
16 |
Correct |
17 ms |
23824 KB |
n=100 |
17 |
Correct |
13 ms |
23828 KB |
n=100 |
18 |
Correct |
12 ms |
23828 KB |
n=100 |
19 |
Correct |
13 ms |
23756 KB |
n=100 |
20 |
Correct |
11 ms |
23756 KB |
n=100 |
21 |
Correct |
16 ms |
23832 KB |
n=100 |
22 |
Correct |
15 ms |
23788 KB |
n=100 |
23 |
Correct |
14 ms |
23836 KB |
n=100 |
24 |
Correct |
11 ms |
23756 KB |
n=100 |
25 |
Correct |
12 ms |
23808 KB |
n=100 |
26 |
Correct |
12 ms |
23688 KB |
n=12 |
27 |
Correct |
11 ms |
23756 KB |
n=100 |
28 |
Correct |
12 ms |
23884 KB |
n=500 |
29 |
Correct |
13 ms |
23860 KB |
n=500 |
30 |
Correct |
13 ms |
23904 KB |
n=500 |
31 |
Correct |
12 ms |
23840 KB |
n=500 |
32 |
Correct |
13 ms |
23920 KB |
n=500 |
33 |
Correct |
13 ms |
23884 KB |
n=500 |
34 |
Correct |
12 ms |
23884 KB |
n=500 |
35 |
Correct |
13 ms |
23840 KB |
n=500 |
36 |
Correct |
12 ms |
23884 KB |
n=500 |
37 |
Correct |
17 ms |
23868 KB |
n=500 |
38 |
Correct |
15 ms |
23888 KB |
n=500 |
39 |
Correct |
11 ms |
23884 KB |
n=500 |
40 |
Correct |
12 ms |
23884 KB |
n=500 |
41 |
Correct |
13 ms |
23884 KB |
n=500 |
42 |
Correct |
15 ms |
23908 KB |
n=500 |
43 |
Correct |
16 ms |
23928 KB |
n=500 |
44 |
Correct |
16 ms |
23884 KB |
n=500 |
45 |
Correct |
14 ms |
23844 KB |
n=500 |
46 |
Correct |
14 ms |
23940 KB |
n=500 |
47 |
Correct |
13 ms |
23856 KB |
n=500 |
48 |
Correct |
12 ms |
23884 KB |
n=500 |
49 |
Correct |
13 ms |
23840 KB |
n=500 |
50 |
Correct |
16 ms |
23884 KB |
n=500 |
51 |
Correct |
19 ms |
23952 KB |
n=500 |
52 |
Correct |
14 ms |
23884 KB |
n=500 |
53 |
Correct |
13 ms |
23908 KB |
n=500 |
54 |
Correct |
13 ms |
23844 KB |
n=500 |
55 |
Correct |
12 ms |
23884 KB |
n=278 |
56 |
Correct |
18 ms |
23940 KB |
n=500 |
57 |
Correct |
12 ms |
23928 KB |
n=500 |
58 |
Correct |
16 ms |
23824 KB |
n=500 |
59 |
Correct |
16 ms |
24140 KB |
n=2000 |
60 |
Correct |
14 ms |
24340 KB |
n=2000 |
61 |
Correct |
15 ms |
24288 KB |
n=2000 |
62 |
Correct |
16 ms |
24260 KB |
n=2000 |
63 |
Correct |
15 ms |
24140 KB |
n=2000 |
64 |
Correct |
17 ms |
24268 KB |
n=2000 |
65 |
Correct |
16 ms |
24204 KB |
n=2000 |
66 |
Correct |
18 ms |
24308 KB |
n=2000 |
67 |
Correct |
16 ms |
24140 KB |
n=2000 |
68 |
Correct |
15 ms |
24248 KB |
n=2000 |
69 |
Correct |
14 ms |
24240 KB |
n=2000 |
70 |
Correct |
14 ms |
24244 KB |
n=2000 |
71 |
Correct |
14 ms |
24140 KB |
n=2000 |
72 |
Correct |
14 ms |
24236 KB |
n=2000 |
73 |
Correct |
14 ms |
24184 KB |
n=2000 |
74 |
Correct |
17 ms |
24168 KB |
n=1844 |
75 |
Correct |
15 ms |
24196 KB |
n=2000 |
76 |
Correct |
17 ms |
24216 KB |
n=2000 |
77 |
Correct |
18 ms |
24140 KB |
n=2000 |
78 |
Correct |
21 ms |
24152 KB |
n=2000 |
79 |
Correct |
16 ms |
24196 KB |
n=2000 |
80 |
Correct |
17 ms |
24268 KB |
n=2000 |
81 |
Correct |
17 ms |
24268 KB |
n=2000 |
82 |
Correct |
15 ms |
24168 KB |
n=2000 |
83 |
Correct |
15 ms |
24268 KB |
n=2000 |
84 |
Correct |
16 ms |
24236 KB |
n=2000 |
85 |
Correct |
16 ms |
24268 KB |
n=2000 |
86 |
Correct |
19 ms |
24268 KB |
n=2000 |
87 |
Correct |
16 ms |
24224 KB |
n=2000 |
88 |
Correct |
16 ms |
24268 KB |
n=2000 |
89 |
Correct |
15 ms |
24268 KB |
n=2000 |
90 |
Correct |
19 ms |
24268 KB |
n=2000 |
91 |
Correct |
15 ms |
24144 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23756 KB |
n=5 |
2 |
Correct |
15 ms |
23828 KB |
n=100 |
3 |
Correct |
13 ms |
23792 KB |
n=100 |
4 |
Correct |
13 ms |
23756 KB |
n=100 |
5 |
Correct |
14 ms |
23828 KB |
n=100 |
6 |
Correct |
12 ms |
23756 KB |
n=100 |
7 |
Correct |
11 ms |
23756 KB |
n=100 |
8 |
Correct |
12 ms |
23828 KB |
n=100 |
9 |
Correct |
11 ms |
23824 KB |
n=100 |
10 |
Correct |
17 ms |
23756 KB |
n=100 |
11 |
Correct |
12 ms |
23756 KB |
n=100 |
12 |
Correct |
13 ms |
23756 KB |
n=100 |
13 |
Correct |
14 ms |
23824 KB |
n=100 |
14 |
Correct |
15 ms |
23756 KB |
n=100 |
15 |
Correct |
11 ms |
23768 KB |
n=100 |
16 |
Correct |
17 ms |
23824 KB |
n=100 |
17 |
Correct |
13 ms |
23828 KB |
n=100 |
18 |
Correct |
12 ms |
23828 KB |
n=100 |
19 |
Correct |
13 ms |
23756 KB |
n=100 |
20 |
Correct |
11 ms |
23756 KB |
n=100 |
21 |
Correct |
16 ms |
23832 KB |
n=100 |
22 |
Correct |
15 ms |
23788 KB |
n=100 |
23 |
Correct |
14 ms |
23836 KB |
n=100 |
24 |
Correct |
11 ms |
23756 KB |
n=100 |
25 |
Correct |
12 ms |
23808 KB |
n=100 |
26 |
Correct |
12 ms |
23688 KB |
n=12 |
27 |
Correct |
11 ms |
23756 KB |
n=100 |
28 |
Correct |
12 ms |
23884 KB |
n=500 |
29 |
Correct |
13 ms |
23860 KB |
n=500 |
30 |
Correct |
13 ms |
23904 KB |
n=500 |
31 |
Correct |
12 ms |
23840 KB |
n=500 |
32 |
Correct |
13 ms |
23920 KB |
n=500 |
33 |
Correct |
13 ms |
23884 KB |
n=500 |
34 |
Correct |
12 ms |
23884 KB |
n=500 |
35 |
Correct |
13 ms |
23840 KB |
n=500 |
36 |
Correct |
12 ms |
23884 KB |
n=500 |
37 |
Correct |
17 ms |
23868 KB |
n=500 |
38 |
Correct |
15 ms |
23888 KB |
n=500 |
39 |
Correct |
11 ms |
23884 KB |
n=500 |
40 |
Correct |
12 ms |
23884 KB |
n=500 |
41 |
Correct |
13 ms |
23884 KB |
n=500 |
42 |
Correct |
15 ms |
23908 KB |
n=500 |
43 |
Correct |
16 ms |
23928 KB |
n=500 |
44 |
Correct |
16 ms |
23884 KB |
n=500 |
45 |
Correct |
14 ms |
23844 KB |
n=500 |
46 |
Correct |
14 ms |
23940 KB |
n=500 |
47 |
Correct |
13 ms |
23856 KB |
n=500 |
48 |
Correct |
12 ms |
23884 KB |
n=500 |
49 |
Correct |
13 ms |
23840 KB |
n=500 |
50 |
Correct |
16 ms |
23884 KB |
n=500 |
51 |
Correct |
19 ms |
23952 KB |
n=500 |
52 |
Correct |
14 ms |
23884 KB |
n=500 |
53 |
Correct |
13 ms |
23908 KB |
n=500 |
54 |
Correct |
13 ms |
23844 KB |
n=500 |
55 |
Correct |
12 ms |
23884 KB |
n=278 |
56 |
Correct |
18 ms |
23940 KB |
n=500 |
57 |
Correct |
12 ms |
23928 KB |
n=500 |
58 |
Correct |
16 ms |
23824 KB |
n=500 |
59 |
Correct |
16 ms |
24140 KB |
n=2000 |
60 |
Correct |
14 ms |
24340 KB |
n=2000 |
61 |
Correct |
15 ms |
24288 KB |
n=2000 |
62 |
Correct |
16 ms |
24260 KB |
n=2000 |
63 |
Correct |
15 ms |
24140 KB |
n=2000 |
64 |
Correct |
17 ms |
24268 KB |
n=2000 |
65 |
Correct |
16 ms |
24204 KB |
n=2000 |
66 |
Correct |
18 ms |
24308 KB |
n=2000 |
67 |
Correct |
16 ms |
24140 KB |
n=2000 |
68 |
Correct |
15 ms |
24248 KB |
n=2000 |
69 |
Correct |
14 ms |
24240 KB |
n=2000 |
70 |
Correct |
14 ms |
24244 KB |
n=2000 |
71 |
Correct |
14 ms |
24140 KB |
n=2000 |
72 |
Correct |
14 ms |
24236 KB |
n=2000 |
73 |
Correct |
14 ms |
24184 KB |
n=2000 |
74 |
Correct |
17 ms |
24168 KB |
n=1844 |
75 |
Correct |
15 ms |
24196 KB |
n=2000 |
76 |
Correct |
17 ms |
24216 KB |
n=2000 |
77 |
Correct |
18 ms |
24140 KB |
n=2000 |
78 |
Correct |
21 ms |
24152 KB |
n=2000 |
79 |
Correct |
16 ms |
24196 KB |
n=2000 |
80 |
Correct |
17 ms |
24268 KB |
n=2000 |
81 |
Correct |
17 ms |
24268 KB |
n=2000 |
82 |
Correct |
15 ms |
24168 KB |
n=2000 |
83 |
Correct |
15 ms |
24268 KB |
n=2000 |
84 |
Correct |
16 ms |
24236 KB |
n=2000 |
85 |
Correct |
16 ms |
24268 KB |
n=2000 |
86 |
Correct |
19 ms |
24268 KB |
n=2000 |
87 |
Correct |
16 ms |
24224 KB |
n=2000 |
88 |
Correct |
16 ms |
24268 KB |
n=2000 |
89 |
Correct |
15 ms |
24268 KB |
n=2000 |
90 |
Correct |
19 ms |
24268 KB |
n=2000 |
91 |
Correct |
15 ms |
24144 KB |
n=2000 |
92 |
Correct |
669 ms |
66492 KB |
n=200000 |
93 |
Correct |
1012 ms |
71816 KB |
n=200000 |
94 |
Correct |
931 ms |
76296 KB |
n=200000 |
95 |
Correct |
731 ms |
66444 KB |
n=200000 |
96 |
Correct |
684 ms |
66360 KB |
n=200000 |
97 |
Correct |
1069 ms |
70448 KB |
n=200000 |
98 |
Correct |
655 ms |
66340 KB |
n=200000 |
99 |
Correct |
831 ms |
65732 KB |
n=200000 |
100 |
Correct |
682 ms |
66368 KB |
n=200000 |
101 |
Correct |
922 ms |
77856 KB |
n=200000 |
102 |
Correct |
399 ms |
67308 KB |
n=200000 |
103 |
Correct |
435 ms |
67264 KB |
n=200000 |
104 |
Correct |
422 ms |
67304 KB |
n=200000 |
105 |
Correct |
459 ms |
66952 KB |
n=200000 |
106 |
Correct |
429 ms |
67004 KB |
n=200000 |
107 |
Correct |
420 ms |
67028 KB |
n=200000 |
108 |
Correct |
761 ms |
65948 KB |
n=200000 |
109 |
Correct |
731 ms |
65976 KB |
n=200000 |
110 |
Correct |
764 ms |
65916 KB |
n=200000 |
111 |
Correct |
713 ms |
66200 KB |
n=200000 |
112 |
Correct |
902 ms |
76564 KB |
n=200000 |
113 |
Correct |
982 ms |
70432 KB |
n=200000 |
114 |
Correct |
676 ms |
66264 KB |
n=200000 |
115 |
Correct |
1065 ms |
67620 KB |
n=200000 |
116 |
Correct |
625 ms |
66172 KB |
n=200000 |
117 |
Correct |
950 ms |
77288 KB |
n=200000 |
118 |
Correct |
976 ms |
69080 KB |
n=200000 |
119 |
Correct |
622 ms |
66060 KB |
n=200000 |
120 |
Correct |
979 ms |
77572 KB |
n=200000 |
121 |
Correct |
941 ms |
77532 KB |
n=200000 |
122 |
Correct |
1078 ms |
78012 KB |
n=200000 |
123 |
Correct |
531 ms |
66632 KB |
n=200000 |
124 |
Correct |
302 ms |
36868 KB |
n=25264 |