/// tree bends in youth
/// 24 .10.2023
/// success is doing same thing in every single day!!!
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(x) x.begin(), x.end()
#define F first
#define S second
using namespace std;
const ll N =1e5+ 5;
const ll NN =2e6 + 5;
const ll INF = -1e1;
const ll MOD = 1e9 + 7;
const ll LG = 18;
const ll k = 316;
vector <int> g[N];
int tin[N],tout[N],a[N],cnt,used[N];
int p[N][18];
void dfs(int v){
cnt++;
used[v] = 1;
tin[v] = cnt;
for(int to : g[v]){
if(used[to] == 0){
p[to][0] = v;
dfs(to);
}
}
tout[v] = cnt;
}
bool upper(int x,int y){
if(tin[x] <= tin[y] && tout[x] >= tout[y])return 1;
else return 0;
}
int lca(int x,int y){
if(upper(x,y) == 1){
return x;
}
if(upper(y,x) == 1){
return y;
}
for(int j = 16;j >= 0;j--){
int h = p[x][j];
if(upper(h,y) == 0){
x = h;
}
}
return p[x][0];
}
void solve(){
int n,m,q;
cin >> n >> m >> q;
for(int i = 1;i < n;i++){
int u,v;
cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
}
p[1][0] = 1;
dfs(1);
for(int i = 1;i <= 16;i++){
for(int j = 1;j <= n;j++){
p[j][i] = p[p[j][i - 1]][i - 1];
}
}
cout << '\n';
for(int i = 1;i <= m;i++){
cin >> a[i];
}
bool was = 1;
while(q--){
int tp,l,r,x;
cin >> tp >> l >> r;
if(tp == 1){
a[l] = r;
}
else{
cin >> x;
bool ok = 0;
for(int j = l;j <= r;j++){
int lc = a[j];
if(lc == x){
cout << j << " " << j << '\n';
ok = 1;
break;
}
int i = j + 1;
while(i <= r){
int lcc= lca(lc,a[i]);
if(lcc == x){
cout << j << ' ' << i << '\n';
ok = 1;
break;
}
lc = lcc;
i++;
}
if(ok)break;
}
if(!ok)cout << "-1 -1\n";
was = 0;
}
}
}
main (){
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
ll abd= 1;
// cin >> abd;
for(ll i = 1;i <= abd;i++){
// cout << "Case " << i << ":\n";
solve();
}
}
Compilation message
treearray.cpp: In function 'void solve()':
treearray.cpp:73:10: warning: variable 'was' set but not used [-Wunused-but-set-variable]
73 | bool was = 1;
| ^~~
treearray.cpp: At global scope:
treearray.cpp:109:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
109 | main (){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2904 KB |
n=5 |
2 |
Correct |
1 ms |
2904 KB |
n=100 |
3 |
Correct |
1 ms |
2908 KB |
n=100 |
4 |
Correct |
1 ms |
2992 KB |
n=100 |
5 |
Correct |
1 ms |
2908 KB |
n=100 |
6 |
Correct |
2 ms |
2908 KB |
n=100 |
7 |
Correct |
2 ms |
2908 KB |
n=100 |
8 |
Correct |
1 ms |
2908 KB |
n=100 |
9 |
Correct |
1 ms |
2908 KB |
n=100 |
10 |
Correct |
2 ms |
2908 KB |
n=100 |
11 |
Correct |
1 ms |
2908 KB |
n=100 |
12 |
Correct |
1 ms |
2908 KB |
n=100 |
13 |
Correct |
1 ms |
2908 KB |
n=100 |
14 |
Correct |
1 ms |
2908 KB |
n=100 |
15 |
Correct |
1 ms |
2904 KB |
n=100 |
16 |
Correct |
1 ms |
2904 KB |
n=100 |
17 |
Correct |
1 ms |
2908 KB |
n=100 |
18 |
Correct |
1 ms |
2908 KB |
n=100 |
19 |
Correct |
1 ms |
2908 KB |
n=100 |
20 |
Correct |
1 ms |
2908 KB |
n=100 |
21 |
Correct |
1 ms |
2908 KB |
n=100 |
22 |
Correct |
1 ms |
2908 KB |
n=100 |
23 |
Correct |
1 ms |
2908 KB |
n=100 |
24 |
Correct |
1 ms |
2908 KB |
n=100 |
25 |
Correct |
1 ms |
2908 KB |
n=100 |
26 |
Correct |
1 ms |
2908 KB |
n=12 |
27 |
Correct |
2 ms |
2908 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2904 KB |
n=5 |
2 |
Correct |
1 ms |
2904 KB |
n=100 |
3 |
Correct |
1 ms |
2908 KB |
n=100 |
4 |
Correct |
1 ms |
2992 KB |
n=100 |
5 |
Correct |
1 ms |
2908 KB |
n=100 |
6 |
Correct |
2 ms |
2908 KB |
n=100 |
7 |
Correct |
2 ms |
2908 KB |
n=100 |
8 |
Correct |
1 ms |
2908 KB |
n=100 |
9 |
Correct |
1 ms |
2908 KB |
n=100 |
10 |
Correct |
2 ms |
2908 KB |
n=100 |
11 |
Correct |
1 ms |
2908 KB |
n=100 |
12 |
Correct |
1 ms |
2908 KB |
n=100 |
13 |
Correct |
1 ms |
2908 KB |
n=100 |
14 |
Correct |
1 ms |
2908 KB |
n=100 |
15 |
Correct |
1 ms |
2904 KB |
n=100 |
16 |
Correct |
1 ms |
2904 KB |
n=100 |
17 |
Correct |
1 ms |
2908 KB |
n=100 |
18 |
Correct |
1 ms |
2908 KB |
n=100 |
19 |
Correct |
1 ms |
2908 KB |
n=100 |
20 |
Correct |
1 ms |
2908 KB |
n=100 |
21 |
Correct |
1 ms |
2908 KB |
n=100 |
22 |
Correct |
1 ms |
2908 KB |
n=100 |
23 |
Correct |
1 ms |
2908 KB |
n=100 |
24 |
Correct |
1 ms |
2908 KB |
n=100 |
25 |
Correct |
1 ms |
2908 KB |
n=100 |
26 |
Correct |
1 ms |
2908 KB |
n=12 |
27 |
Correct |
2 ms |
2908 KB |
n=100 |
28 |
Correct |
2 ms |
3160 KB |
n=500 |
29 |
Correct |
11 ms |
2908 KB |
n=500 |
30 |
Correct |
8 ms |
2904 KB |
n=500 |
31 |
Correct |
10 ms |
3132 KB |
n=500 |
32 |
Correct |
1 ms |
2904 KB |
n=500 |
33 |
Correct |
8 ms |
2904 KB |
n=500 |
34 |
Correct |
1 ms |
2904 KB |
n=500 |
35 |
Correct |
9 ms |
2908 KB |
n=500 |
36 |
Correct |
101 ms |
2908 KB |
n=500 |
37 |
Correct |
108 ms |
2908 KB |
n=500 |
38 |
Correct |
99 ms |
2904 KB |
n=500 |
39 |
Correct |
18 ms |
2908 KB |
n=500 |
40 |
Correct |
17 ms |
3312 KB |
n=500 |
41 |
Correct |
17 ms |
3112 KB |
n=500 |
42 |
Correct |
51 ms |
2904 KB |
n=500 |
43 |
Correct |
51 ms |
2904 KB |
n=500 |
44 |
Correct |
52 ms |
2908 KB |
n=500 |
45 |
Correct |
1 ms |
2908 KB |
n=500 |
46 |
Correct |
10 ms |
3144 KB |
n=500 |
47 |
Correct |
8 ms |
2908 KB |
n=500 |
48 |
Correct |
1 ms |
2908 KB |
n=500 |
49 |
Correct |
8 ms |
2908 KB |
n=500 |
50 |
Correct |
14 ms |
2908 KB |
n=500 |
51 |
Correct |
15 ms |
2908 KB |
n=500 |
52 |
Correct |
19 ms |
2908 KB |
n=500 |
53 |
Correct |
17 ms |
2904 KB |
n=500 |
54 |
Correct |
7 ms |
2904 KB |
n=500 |
55 |
Correct |
3 ms |
2908 KB |
n=278 |
56 |
Correct |
53 ms |
2908 KB |
n=500 |
57 |
Correct |
56 ms |
2908 KB |
n=500 |
58 |
Correct |
51 ms |
2904 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2904 KB |
n=5 |
2 |
Correct |
1 ms |
2904 KB |
n=100 |
3 |
Correct |
1 ms |
2908 KB |
n=100 |
4 |
Correct |
1 ms |
2992 KB |
n=100 |
5 |
Correct |
1 ms |
2908 KB |
n=100 |
6 |
Correct |
2 ms |
2908 KB |
n=100 |
7 |
Correct |
2 ms |
2908 KB |
n=100 |
8 |
Correct |
1 ms |
2908 KB |
n=100 |
9 |
Correct |
1 ms |
2908 KB |
n=100 |
10 |
Correct |
2 ms |
2908 KB |
n=100 |
11 |
Correct |
1 ms |
2908 KB |
n=100 |
12 |
Correct |
1 ms |
2908 KB |
n=100 |
13 |
Correct |
1 ms |
2908 KB |
n=100 |
14 |
Correct |
1 ms |
2908 KB |
n=100 |
15 |
Correct |
1 ms |
2904 KB |
n=100 |
16 |
Correct |
1 ms |
2904 KB |
n=100 |
17 |
Correct |
1 ms |
2908 KB |
n=100 |
18 |
Correct |
1 ms |
2908 KB |
n=100 |
19 |
Correct |
1 ms |
2908 KB |
n=100 |
20 |
Correct |
1 ms |
2908 KB |
n=100 |
21 |
Correct |
1 ms |
2908 KB |
n=100 |
22 |
Correct |
1 ms |
2908 KB |
n=100 |
23 |
Correct |
1 ms |
2908 KB |
n=100 |
24 |
Correct |
1 ms |
2908 KB |
n=100 |
25 |
Correct |
1 ms |
2908 KB |
n=100 |
26 |
Correct |
1 ms |
2908 KB |
n=12 |
27 |
Correct |
2 ms |
2908 KB |
n=100 |
28 |
Correct |
2 ms |
3160 KB |
n=500 |
29 |
Correct |
11 ms |
2908 KB |
n=500 |
30 |
Correct |
8 ms |
2904 KB |
n=500 |
31 |
Correct |
10 ms |
3132 KB |
n=500 |
32 |
Correct |
1 ms |
2904 KB |
n=500 |
33 |
Correct |
8 ms |
2904 KB |
n=500 |
34 |
Correct |
1 ms |
2904 KB |
n=500 |
35 |
Correct |
9 ms |
2908 KB |
n=500 |
36 |
Correct |
101 ms |
2908 KB |
n=500 |
37 |
Correct |
108 ms |
2908 KB |
n=500 |
38 |
Correct |
99 ms |
2904 KB |
n=500 |
39 |
Correct |
18 ms |
2908 KB |
n=500 |
40 |
Correct |
17 ms |
3312 KB |
n=500 |
41 |
Correct |
17 ms |
3112 KB |
n=500 |
42 |
Correct |
51 ms |
2904 KB |
n=500 |
43 |
Correct |
51 ms |
2904 KB |
n=500 |
44 |
Correct |
52 ms |
2908 KB |
n=500 |
45 |
Correct |
1 ms |
2908 KB |
n=500 |
46 |
Correct |
10 ms |
3144 KB |
n=500 |
47 |
Correct |
8 ms |
2908 KB |
n=500 |
48 |
Correct |
1 ms |
2908 KB |
n=500 |
49 |
Correct |
8 ms |
2908 KB |
n=500 |
50 |
Correct |
14 ms |
2908 KB |
n=500 |
51 |
Correct |
15 ms |
2908 KB |
n=500 |
52 |
Correct |
19 ms |
2908 KB |
n=500 |
53 |
Correct |
17 ms |
2904 KB |
n=500 |
54 |
Correct |
7 ms |
2904 KB |
n=500 |
55 |
Correct |
3 ms |
2908 KB |
n=278 |
56 |
Correct |
53 ms |
2908 KB |
n=500 |
57 |
Correct |
56 ms |
2908 KB |
n=500 |
58 |
Correct |
51 ms |
2904 KB |
n=500 |
59 |
Correct |
8 ms |
3164 KB |
n=2000 |
60 |
Correct |
496 ms |
3164 KB |
n=2000 |
61 |
Correct |
486 ms |
3412 KB |
n=2000 |
62 |
Correct |
335 ms |
3164 KB |
n=2000 |
63 |
Correct |
12 ms |
3164 KB |
n=2000 |
64 |
Correct |
445 ms |
3160 KB |
n=2000 |
65 |
Correct |
3 ms |
3164 KB |
n=2000 |
66 |
Correct |
555 ms |
3420 KB |
n=2000 |
67 |
Correct |
26 ms |
3160 KB |
n=2000 |
68 |
Correct |
449 ms |
3380 KB |
n=2000 |
69 |
Execution timed out |
4041 ms |
3416 KB |
Time limit exceeded |
70 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2904 KB |
n=5 |
2 |
Correct |
1 ms |
2904 KB |
n=100 |
3 |
Correct |
1 ms |
2908 KB |
n=100 |
4 |
Correct |
1 ms |
2992 KB |
n=100 |
5 |
Correct |
1 ms |
2908 KB |
n=100 |
6 |
Correct |
2 ms |
2908 KB |
n=100 |
7 |
Correct |
2 ms |
2908 KB |
n=100 |
8 |
Correct |
1 ms |
2908 KB |
n=100 |
9 |
Correct |
1 ms |
2908 KB |
n=100 |
10 |
Correct |
2 ms |
2908 KB |
n=100 |
11 |
Correct |
1 ms |
2908 KB |
n=100 |
12 |
Correct |
1 ms |
2908 KB |
n=100 |
13 |
Correct |
1 ms |
2908 KB |
n=100 |
14 |
Correct |
1 ms |
2908 KB |
n=100 |
15 |
Correct |
1 ms |
2904 KB |
n=100 |
16 |
Correct |
1 ms |
2904 KB |
n=100 |
17 |
Correct |
1 ms |
2908 KB |
n=100 |
18 |
Correct |
1 ms |
2908 KB |
n=100 |
19 |
Correct |
1 ms |
2908 KB |
n=100 |
20 |
Correct |
1 ms |
2908 KB |
n=100 |
21 |
Correct |
1 ms |
2908 KB |
n=100 |
22 |
Correct |
1 ms |
2908 KB |
n=100 |
23 |
Correct |
1 ms |
2908 KB |
n=100 |
24 |
Correct |
1 ms |
2908 KB |
n=100 |
25 |
Correct |
1 ms |
2908 KB |
n=100 |
26 |
Correct |
1 ms |
2908 KB |
n=12 |
27 |
Correct |
2 ms |
2908 KB |
n=100 |
28 |
Correct |
2 ms |
3160 KB |
n=500 |
29 |
Correct |
11 ms |
2908 KB |
n=500 |
30 |
Correct |
8 ms |
2904 KB |
n=500 |
31 |
Correct |
10 ms |
3132 KB |
n=500 |
32 |
Correct |
1 ms |
2904 KB |
n=500 |
33 |
Correct |
8 ms |
2904 KB |
n=500 |
34 |
Correct |
1 ms |
2904 KB |
n=500 |
35 |
Correct |
9 ms |
2908 KB |
n=500 |
36 |
Correct |
101 ms |
2908 KB |
n=500 |
37 |
Correct |
108 ms |
2908 KB |
n=500 |
38 |
Correct |
99 ms |
2904 KB |
n=500 |
39 |
Correct |
18 ms |
2908 KB |
n=500 |
40 |
Correct |
17 ms |
3312 KB |
n=500 |
41 |
Correct |
17 ms |
3112 KB |
n=500 |
42 |
Correct |
51 ms |
2904 KB |
n=500 |
43 |
Correct |
51 ms |
2904 KB |
n=500 |
44 |
Correct |
52 ms |
2908 KB |
n=500 |
45 |
Correct |
1 ms |
2908 KB |
n=500 |
46 |
Correct |
10 ms |
3144 KB |
n=500 |
47 |
Correct |
8 ms |
2908 KB |
n=500 |
48 |
Correct |
1 ms |
2908 KB |
n=500 |
49 |
Correct |
8 ms |
2908 KB |
n=500 |
50 |
Correct |
14 ms |
2908 KB |
n=500 |
51 |
Correct |
15 ms |
2908 KB |
n=500 |
52 |
Correct |
19 ms |
2908 KB |
n=500 |
53 |
Correct |
17 ms |
2904 KB |
n=500 |
54 |
Correct |
7 ms |
2904 KB |
n=500 |
55 |
Correct |
3 ms |
2908 KB |
n=278 |
56 |
Correct |
53 ms |
2908 KB |
n=500 |
57 |
Correct |
56 ms |
2908 KB |
n=500 |
58 |
Correct |
51 ms |
2904 KB |
n=500 |
59 |
Correct |
8 ms |
3164 KB |
n=2000 |
60 |
Correct |
496 ms |
3164 KB |
n=2000 |
61 |
Correct |
486 ms |
3412 KB |
n=2000 |
62 |
Correct |
335 ms |
3164 KB |
n=2000 |
63 |
Correct |
12 ms |
3164 KB |
n=2000 |
64 |
Correct |
445 ms |
3160 KB |
n=2000 |
65 |
Correct |
3 ms |
3164 KB |
n=2000 |
66 |
Correct |
555 ms |
3420 KB |
n=2000 |
67 |
Correct |
26 ms |
3160 KB |
n=2000 |
68 |
Correct |
449 ms |
3380 KB |
n=2000 |
69 |
Execution timed out |
4041 ms |
3416 KB |
Time limit exceeded |
70 |
Halted |
0 ms |
0 KB |
- |