#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
const int N = 2e5;
const int LOG = 15;
int up[N + 1][LOG], depth[N+1];
vector<int> g[N+1];
vector< set<int> > LCA(N+1);
vector< set<int> > where(N+1);
int n, m, q;
vector<int> a;
void dfs(int v, int p){
up[v][0] = p;
for(int j = 1;j < LOG; j++){
up[v][j] = up[up[v][j-1]][j-1];
}
for(int to : g[v]){
if(to == p) continue;
depth[to] = depth[v]+1;
dfs(to, v);
}
}
int lca(int a, int b){
if(depth[a] > depth[b]) swap(a, b);
int k = depth[b]-depth[a];
for(int i = 0;i < LOG; i++){
if(k&(1<<i)){
b = up[b][i];
}
}
if(a == b) return b;
for(int i = LOG-1; i >= 0; i--){
if(up[a][i] != up[b][i]){
a = up[a][i], b = up[b][i];
}
}
return up[a][0];
}
main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m >> q;
a.resize(m);
for(int i = 1;i < n; i++){
int a, b; cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
for(int i = 0;i < m; i++){
cin >> a[i];
where[a[i]].insert(i);
}
dfs(1, 1);
for(int i = 0;i < m-1; i++){
LCA[lca(a[i], a[i+1])].insert(i);
}
while(q--){
int type; cin >> type;
if(type == 1){
int pos, v; cin >> pos >> v; pos--;
if(pos < m-1){
LCA[lca(a[pos], a[pos+1])].erase(pos);
LCA[lca(v, a[pos+1])].insert(pos);
}
if(pos > 0){
LCA[lca(a[pos], a[pos-1])].erase(pos-1);
LCA[lca(v, a[pos-1])].insert(pos-1);
}
where[a[pos]].erase(pos);
a[pos] = v;
where[v].insert(pos);
}else{
int l, r, v; cin >> l >> r >> v; l--, r--;
auto it = where[v].lower_bound(l);
if(it != where[v].end() and *it >= l and *it <= r){
cout << *it+1 << ' ' << *it+1 << '\n';
continue;
}
it = LCA[v].lower_bound(l);
if(it != LCA[v].end() and *it >=l and *it < r){
cout << *it+1 << ' ' << *it+2 << '\n';
continue;
}
cout << "-1 -1" << '\n';
}
}
return 0;
}
Compilation message
treearray.cpp:46:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
46 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
n=5 |
2 |
Correct |
15 ms |
23836 KB |
n=100 |
3 |
Correct |
14 ms |
23764 KB |
n=100 |
4 |
Correct |
13 ms |
23740 KB |
n=100 |
5 |
Correct |
13 ms |
23764 KB |
n=100 |
6 |
Correct |
13 ms |
23800 KB |
n=100 |
7 |
Correct |
12 ms |
23764 KB |
n=100 |
8 |
Correct |
13 ms |
23772 KB |
n=100 |
9 |
Correct |
13 ms |
23824 KB |
n=100 |
10 |
Correct |
12 ms |
23764 KB |
n=100 |
11 |
Correct |
14 ms |
23800 KB |
n=100 |
12 |
Correct |
15 ms |
23764 KB |
n=100 |
13 |
Correct |
14 ms |
23816 KB |
n=100 |
14 |
Correct |
13 ms |
23764 KB |
n=100 |
15 |
Correct |
13 ms |
23768 KB |
n=100 |
16 |
Correct |
13 ms |
23824 KB |
n=100 |
17 |
Correct |
12 ms |
23828 KB |
n=100 |
18 |
Correct |
13 ms |
23884 KB |
n=100 |
19 |
Correct |
13 ms |
23828 KB |
n=100 |
20 |
Correct |
13 ms |
23888 KB |
n=100 |
21 |
Correct |
13 ms |
23776 KB |
n=100 |
22 |
Correct |
14 ms |
23764 KB |
n=100 |
23 |
Correct |
13 ms |
23796 KB |
n=100 |
24 |
Correct |
12 ms |
23760 KB |
n=100 |
25 |
Correct |
12 ms |
23764 KB |
n=100 |
26 |
Correct |
12 ms |
23764 KB |
n=12 |
27 |
Correct |
12 ms |
23764 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
n=5 |
2 |
Correct |
15 ms |
23836 KB |
n=100 |
3 |
Correct |
14 ms |
23764 KB |
n=100 |
4 |
Correct |
13 ms |
23740 KB |
n=100 |
5 |
Correct |
13 ms |
23764 KB |
n=100 |
6 |
Correct |
13 ms |
23800 KB |
n=100 |
7 |
Correct |
12 ms |
23764 KB |
n=100 |
8 |
Correct |
13 ms |
23772 KB |
n=100 |
9 |
Correct |
13 ms |
23824 KB |
n=100 |
10 |
Correct |
12 ms |
23764 KB |
n=100 |
11 |
Correct |
14 ms |
23800 KB |
n=100 |
12 |
Correct |
15 ms |
23764 KB |
n=100 |
13 |
Correct |
14 ms |
23816 KB |
n=100 |
14 |
Correct |
13 ms |
23764 KB |
n=100 |
15 |
Correct |
13 ms |
23768 KB |
n=100 |
16 |
Correct |
13 ms |
23824 KB |
n=100 |
17 |
Correct |
12 ms |
23828 KB |
n=100 |
18 |
Correct |
13 ms |
23884 KB |
n=100 |
19 |
Correct |
13 ms |
23828 KB |
n=100 |
20 |
Correct |
13 ms |
23888 KB |
n=100 |
21 |
Correct |
13 ms |
23776 KB |
n=100 |
22 |
Correct |
14 ms |
23764 KB |
n=100 |
23 |
Correct |
13 ms |
23796 KB |
n=100 |
24 |
Correct |
12 ms |
23760 KB |
n=100 |
25 |
Correct |
12 ms |
23764 KB |
n=100 |
26 |
Correct |
12 ms |
23764 KB |
n=12 |
27 |
Correct |
12 ms |
23764 KB |
n=100 |
28 |
Correct |
15 ms |
23824 KB |
n=500 |
29 |
Correct |
13 ms |
23892 KB |
n=500 |
30 |
Correct |
13 ms |
23892 KB |
n=500 |
31 |
Correct |
13 ms |
23892 KB |
n=500 |
32 |
Correct |
16 ms |
23880 KB |
n=500 |
33 |
Correct |
14 ms |
23908 KB |
n=500 |
34 |
Correct |
13 ms |
23940 KB |
n=500 |
35 |
Correct |
13 ms |
23840 KB |
n=500 |
36 |
Correct |
13 ms |
23892 KB |
n=500 |
37 |
Correct |
13 ms |
23880 KB |
n=500 |
38 |
Correct |
13 ms |
23844 KB |
n=500 |
39 |
Correct |
13 ms |
23892 KB |
n=500 |
40 |
Correct |
13 ms |
23836 KB |
n=500 |
41 |
Correct |
13 ms |
23828 KB |
n=500 |
42 |
Correct |
13 ms |
23892 KB |
n=500 |
43 |
Correct |
15 ms |
23904 KB |
n=500 |
44 |
Correct |
15 ms |
23832 KB |
n=500 |
45 |
Correct |
13 ms |
23836 KB |
n=500 |
46 |
Correct |
13 ms |
23924 KB |
n=500 |
47 |
Correct |
15 ms |
23892 KB |
n=500 |
48 |
Correct |
13 ms |
23892 KB |
n=500 |
49 |
Correct |
14 ms |
23892 KB |
n=500 |
50 |
Correct |
13 ms |
23892 KB |
n=500 |
51 |
Correct |
13 ms |
23844 KB |
n=500 |
52 |
Correct |
13 ms |
23836 KB |
n=500 |
53 |
Correct |
13 ms |
23892 KB |
n=500 |
54 |
Correct |
13 ms |
23892 KB |
n=500 |
55 |
Correct |
14 ms |
23832 KB |
n=278 |
56 |
Correct |
13 ms |
23932 KB |
n=500 |
57 |
Correct |
14 ms |
23892 KB |
n=500 |
58 |
Correct |
13 ms |
23848 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
n=5 |
2 |
Correct |
15 ms |
23836 KB |
n=100 |
3 |
Correct |
14 ms |
23764 KB |
n=100 |
4 |
Correct |
13 ms |
23740 KB |
n=100 |
5 |
Correct |
13 ms |
23764 KB |
n=100 |
6 |
Correct |
13 ms |
23800 KB |
n=100 |
7 |
Correct |
12 ms |
23764 KB |
n=100 |
8 |
Correct |
13 ms |
23772 KB |
n=100 |
9 |
Correct |
13 ms |
23824 KB |
n=100 |
10 |
Correct |
12 ms |
23764 KB |
n=100 |
11 |
Correct |
14 ms |
23800 KB |
n=100 |
12 |
Correct |
15 ms |
23764 KB |
n=100 |
13 |
Correct |
14 ms |
23816 KB |
n=100 |
14 |
Correct |
13 ms |
23764 KB |
n=100 |
15 |
Correct |
13 ms |
23768 KB |
n=100 |
16 |
Correct |
13 ms |
23824 KB |
n=100 |
17 |
Correct |
12 ms |
23828 KB |
n=100 |
18 |
Correct |
13 ms |
23884 KB |
n=100 |
19 |
Correct |
13 ms |
23828 KB |
n=100 |
20 |
Correct |
13 ms |
23888 KB |
n=100 |
21 |
Correct |
13 ms |
23776 KB |
n=100 |
22 |
Correct |
14 ms |
23764 KB |
n=100 |
23 |
Correct |
13 ms |
23796 KB |
n=100 |
24 |
Correct |
12 ms |
23760 KB |
n=100 |
25 |
Correct |
12 ms |
23764 KB |
n=100 |
26 |
Correct |
12 ms |
23764 KB |
n=12 |
27 |
Correct |
12 ms |
23764 KB |
n=100 |
28 |
Correct |
15 ms |
23824 KB |
n=500 |
29 |
Correct |
13 ms |
23892 KB |
n=500 |
30 |
Correct |
13 ms |
23892 KB |
n=500 |
31 |
Correct |
13 ms |
23892 KB |
n=500 |
32 |
Correct |
16 ms |
23880 KB |
n=500 |
33 |
Correct |
14 ms |
23908 KB |
n=500 |
34 |
Correct |
13 ms |
23940 KB |
n=500 |
35 |
Correct |
13 ms |
23840 KB |
n=500 |
36 |
Correct |
13 ms |
23892 KB |
n=500 |
37 |
Correct |
13 ms |
23880 KB |
n=500 |
38 |
Correct |
13 ms |
23844 KB |
n=500 |
39 |
Correct |
13 ms |
23892 KB |
n=500 |
40 |
Correct |
13 ms |
23836 KB |
n=500 |
41 |
Correct |
13 ms |
23828 KB |
n=500 |
42 |
Correct |
13 ms |
23892 KB |
n=500 |
43 |
Correct |
15 ms |
23904 KB |
n=500 |
44 |
Correct |
15 ms |
23832 KB |
n=500 |
45 |
Correct |
13 ms |
23836 KB |
n=500 |
46 |
Correct |
13 ms |
23924 KB |
n=500 |
47 |
Correct |
15 ms |
23892 KB |
n=500 |
48 |
Correct |
13 ms |
23892 KB |
n=500 |
49 |
Correct |
14 ms |
23892 KB |
n=500 |
50 |
Correct |
13 ms |
23892 KB |
n=500 |
51 |
Correct |
13 ms |
23844 KB |
n=500 |
52 |
Correct |
13 ms |
23836 KB |
n=500 |
53 |
Correct |
13 ms |
23892 KB |
n=500 |
54 |
Correct |
13 ms |
23892 KB |
n=500 |
55 |
Correct |
14 ms |
23832 KB |
n=278 |
56 |
Correct |
13 ms |
23932 KB |
n=500 |
57 |
Correct |
14 ms |
23892 KB |
n=500 |
58 |
Correct |
13 ms |
23848 KB |
n=500 |
59 |
Correct |
16 ms |
24232 KB |
n=2000 |
60 |
Correct |
15 ms |
24352 KB |
n=2000 |
61 |
Correct |
16 ms |
24228 KB |
n=2000 |
62 |
Correct |
18 ms |
24224 KB |
n=2000 |
63 |
Correct |
15 ms |
24156 KB |
n=2000 |
64 |
Correct |
16 ms |
24228 KB |
n=2000 |
65 |
Correct |
15 ms |
24276 KB |
n=2000 |
66 |
Correct |
15 ms |
24288 KB |
n=2000 |
67 |
Correct |
15 ms |
24180 KB |
n=2000 |
68 |
Correct |
15 ms |
24276 KB |
n=2000 |
69 |
Correct |
14 ms |
24276 KB |
n=2000 |
70 |
Correct |
16 ms |
24256 KB |
n=2000 |
71 |
Correct |
15 ms |
24216 KB |
n=2000 |
72 |
Correct |
14 ms |
24276 KB |
n=2000 |
73 |
Correct |
15 ms |
24288 KB |
n=2000 |
74 |
Correct |
14 ms |
24228 KB |
n=1844 |
75 |
Correct |
14 ms |
24184 KB |
n=2000 |
76 |
Correct |
16 ms |
24276 KB |
n=2000 |
77 |
Correct |
17 ms |
24276 KB |
n=2000 |
78 |
Correct |
15 ms |
24172 KB |
n=2000 |
79 |
Correct |
15 ms |
24276 KB |
n=2000 |
80 |
Correct |
16 ms |
24352 KB |
n=2000 |
81 |
Correct |
16 ms |
24276 KB |
n=2000 |
82 |
Correct |
15 ms |
24164 KB |
n=2000 |
83 |
Correct |
15 ms |
24244 KB |
n=2000 |
84 |
Correct |
15 ms |
24148 KB |
n=2000 |
85 |
Correct |
16 ms |
24276 KB |
n=2000 |
86 |
Correct |
18 ms |
24320 KB |
n=2000 |
87 |
Correct |
16 ms |
24228 KB |
n=2000 |
88 |
Correct |
15 ms |
24292 KB |
n=2000 |
89 |
Correct |
15 ms |
24360 KB |
n=2000 |
90 |
Correct |
18 ms |
24260 KB |
n=2000 |
91 |
Correct |
16 ms |
24276 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
n=5 |
2 |
Correct |
15 ms |
23836 KB |
n=100 |
3 |
Correct |
14 ms |
23764 KB |
n=100 |
4 |
Correct |
13 ms |
23740 KB |
n=100 |
5 |
Correct |
13 ms |
23764 KB |
n=100 |
6 |
Correct |
13 ms |
23800 KB |
n=100 |
7 |
Correct |
12 ms |
23764 KB |
n=100 |
8 |
Correct |
13 ms |
23772 KB |
n=100 |
9 |
Correct |
13 ms |
23824 KB |
n=100 |
10 |
Correct |
12 ms |
23764 KB |
n=100 |
11 |
Correct |
14 ms |
23800 KB |
n=100 |
12 |
Correct |
15 ms |
23764 KB |
n=100 |
13 |
Correct |
14 ms |
23816 KB |
n=100 |
14 |
Correct |
13 ms |
23764 KB |
n=100 |
15 |
Correct |
13 ms |
23768 KB |
n=100 |
16 |
Correct |
13 ms |
23824 KB |
n=100 |
17 |
Correct |
12 ms |
23828 KB |
n=100 |
18 |
Correct |
13 ms |
23884 KB |
n=100 |
19 |
Correct |
13 ms |
23828 KB |
n=100 |
20 |
Correct |
13 ms |
23888 KB |
n=100 |
21 |
Correct |
13 ms |
23776 KB |
n=100 |
22 |
Correct |
14 ms |
23764 KB |
n=100 |
23 |
Correct |
13 ms |
23796 KB |
n=100 |
24 |
Correct |
12 ms |
23760 KB |
n=100 |
25 |
Correct |
12 ms |
23764 KB |
n=100 |
26 |
Correct |
12 ms |
23764 KB |
n=12 |
27 |
Correct |
12 ms |
23764 KB |
n=100 |
28 |
Correct |
15 ms |
23824 KB |
n=500 |
29 |
Correct |
13 ms |
23892 KB |
n=500 |
30 |
Correct |
13 ms |
23892 KB |
n=500 |
31 |
Correct |
13 ms |
23892 KB |
n=500 |
32 |
Correct |
16 ms |
23880 KB |
n=500 |
33 |
Correct |
14 ms |
23908 KB |
n=500 |
34 |
Correct |
13 ms |
23940 KB |
n=500 |
35 |
Correct |
13 ms |
23840 KB |
n=500 |
36 |
Correct |
13 ms |
23892 KB |
n=500 |
37 |
Correct |
13 ms |
23880 KB |
n=500 |
38 |
Correct |
13 ms |
23844 KB |
n=500 |
39 |
Correct |
13 ms |
23892 KB |
n=500 |
40 |
Correct |
13 ms |
23836 KB |
n=500 |
41 |
Correct |
13 ms |
23828 KB |
n=500 |
42 |
Correct |
13 ms |
23892 KB |
n=500 |
43 |
Correct |
15 ms |
23904 KB |
n=500 |
44 |
Correct |
15 ms |
23832 KB |
n=500 |
45 |
Correct |
13 ms |
23836 KB |
n=500 |
46 |
Correct |
13 ms |
23924 KB |
n=500 |
47 |
Correct |
15 ms |
23892 KB |
n=500 |
48 |
Correct |
13 ms |
23892 KB |
n=500 |
49 |
Correct |
14 ms |
23892 KB |
n=500 |
50 |
Correct |
13 ms |
23892 KB |
n=500 |
51 |
Correct |
13 ms |
23844 KB |
n=500 |
52 |
Correct |
13 ms |
23836 KB |
n=500 |
53 |
Correct |
13 ms |
23892 KB |
n=500 |
54 |
Correct |
13 ms |
23892 KB |
n=500 |
55 |
Correct |
14 ms |
23832 KB |
n=278 |
56 |
Correct |
13 ms |
23932 KB |
n=500 |
57 |
Correct |
14 ms |
23892 KB |
n=500 |
58 |
Correct |
13 ms |
23848 KB |
n=500 |
59 |
Correct |
16 ms |
24232 KB |
n=2000 |
60 |
Correct |
15 ms |
24352 KB |
n=2000 |
61 |
Correct |
16 ms |
24228 KB |
n=2000 |
62 |
Correct |
18 ms |
24224 KB |
n=2000 |
63 |
Correct |
15 ms |
24156 KB |
n=2000 |
64 |
Correct |
16 ms |
24228 KB |
n=2000 |
65 |
Correct |
15 ms |
24276 KB |
n=2000 |
66 |
Correct |
15 ms |
24288 KB |
n=2000 |
67 |
Correct |
15 ms |
24180 KB |
n=2000 |
68 |
Correct |
15 ms |
24276 KB |
n=2000 |
69 |
Correct |
14 ms |
24276 KB |
n=2000 |
70 |
Correct |
16 ms |
24256 KB |
n=2000 |
71 |
Correct |
15 ms |
24216 KB |
n=2000 |
72 |
Correct |
14 ms |
24276 KB |
n=2000 |
73 |
Correct |
15 ms |
24288 KB |
n=2000 |
74 |
Correct |
14 ms |
24228 KB |
n=1844 |
75 |
Correct |
14 ms |
24184 KB |
n=2000 |
76 |
Correct |
16 ms |
24276 KB |
n=2000 |
77 |
Correct |
17 ms |
24276 KB |
n=2000 |
78 |
Correct |
15 ms |
24172 KB |
n=2000 |
79 |
Correct |
15 ms |
24276 KB |
n=2000 |
80 |
Correct |
16 ms |
24352 KB |
n=2000 |
81 |
Correct |
16 ms |
24276 KB |
n=2000 |
82 |
Correct |
15 ms |
24164 KB |
n=2000 |
83 |
Correct |
15 ms |
24244 KB |
n=2000 |
84 |
Correct |
15 ms |
24148 KB |
n=2000 |
85 |
Correct |
16 ms |
24276 KB |
n=2000 |
86 |
Correct |
18 ms |
24320 KB |
n=2000 |
87 |
Correct |
16 ms |
24228 KB |
n=2000 |
88 |
Correct |
15 ms |
24292 KB |
n=2000 |
89 |
Correct |
15 ms |
24360 KB |
n=2000 |
90 |
Correct |
18 ms |
24260 KB |
n=2000 |
91 |
Correct |
16 ms |
24276 KB |
n=2000 |
92 |
Correct |
608 ms |
70668 KB |
n=200000 |
93 |
Incorrect |
1046 ms |
77044 KB |
Jury has the answer but participant has not |
94 |
Halted |
0 ms |
0 KB |
- |