#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(x) x.begin(),x.end()
#define pb push_back
#define ent "\n"
const int maxn = (int)2e5 + 13;
const ll inf = (long long)1e18 + 20;
const int mod = (int)1e9 + 7;
ll n,m,q;
ll a[maxn];
ll up[maxn][16];
ll sz[maxn];
ll b[maxn];
vector<int>g[maxn];
void calc(int v,int p ){
for(int to : g[v]){
if(to != p){
up[to][0] = v;
sz[to] = sz[v] + 1;
calc(to,v);
}
}
}
int lca(int x,int y){
if(sz[x] > sz[y])swap(x,y);
int dif = sz[y] - sz[x];
for(int i = 0 ; i <= 15 ; i ++){
if((dif >> i)&1){
y = up[y][i];
}
}
if(x == y)return x;
for(int i = 15 ; i >= 0 ; i --){
if(up[x][i]!=up[y][i] && min(up[x][i],up[y][i]) > 0){
x = up[x][i];
y = up[y][i];
}
}
return up[x][0];
}
void solve(){
cin >> n >> m >> q;
map<int,int>mp;
for(int i = 1 ; i < n ; i ++){
int x,y;cin >> x >> y;
g[x].pb(y);
g[y].pb(x);
}
for(int i = 1 ; i <= m ; i ++){
cin >> a[i];
b[i] = a[i];
}
for(int i = 1 ; i <= n ; i ++){
mp[i] = i;
}
calc(1,0);
for(int i = 1 ; i <= 15 ; i ++){
for(int j = 1 ; j <= n ; j ++){
up[j][i] = up[up[j][i - 1]][i - 1];
}
}
while(q--){
int tp;cin >> tp;
if(tp == 2){
int l,r,v;cin >> l >> r >> v;
int lc,ok = 0;
for(int i = l ; i <= r ; i ++){
for(int j = i ; j <= r ; j ++){
if(i == j){
lc = a[i];
}
lc = lca(lc,a[j]);
if(lc == v){
cout << i << ' ' << j << ent;
ok = 1;
break;
}
}
if(ok)break;
}
if(!ok){
cout << "-1 -1\n";
}
}
else{
int pos,v;cin >> pos >> v;
mp[a[pos]] = v;
a[pos] = v;
}
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
//cin >> t;
while(t --){
solve();
}
return 0;
}
Compilation message
treearray.cpp: In function 'void solve()':
treearray.cpp:106:14: warning: 'lc' may be used uninitialized in this function [-Wmaybe-uninitialized]
106 | lc = lca(lc,a[j]);
| ~~~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10844 KB |
n=5 |
2 |
Correct |
3 ms |
10840 KB |
n=100 |
3 |
Correct |
3 ms |
10844 KB |
n=100 |
4 |
Correct |
2 ms |
10844 KB |
n=100 |
5 |
Correct |
2 ms |
10844 KB |
n=100 |
6 |
Correct |
12 ms |
10904 KB |
n=100 |
7 |
Correct |
9 ms |
10900 KB |
n=100 |
8 |
Correct |
3 ms |
10844 KB |
n=100 |
9 |
Correct |
2 ms |
10840 KB |
n=100 |
10 |
Correct |
6 ms |
10844 KB |
n=100 |
11 |
Correct |
5 ms |
10844 KB |
n=100 |
12 |
Correct |
2 ms |
10844 KB |
n=100 |
13 |
Correct |
2 ms |
10840 KB |
n=100 |
14 |
Correct |
2 ms |
10844 KB |
n=100 |
15 |
Correct |
2 ms |
10844 KB |
n=100 |
16 |
Correct |
2 ms |
10840 KB |
n=100 |
17 |
Correct |
3 ms |
10844 KB |
n=100 |
18 |
Correct |
2 ms |
10840 KB |
n=100 |
19 |
Correct |
2 ms |
10840 KB |
n=100 |
20 |
Correct |
2 ms |
10848 KB |
n=100 |
21 |
Correct |
2 ms |
10844 KB |
n=100 |
22 |
Correct |
2 ms |
10844 KB |
n=100 |
23 |
Correct |
3 ms |
10844 KB |
n=100 |
24 |
Correct |
3 ms |
10844 KB |
n=100 |
25 |
Correct |
2 ms |
10844 KB |
n=100 |
26 |
Correct |
2 ms |
10844 KB |
n=12 |
27 |
Correct |
4 ms |
10844 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10844 KB |
n=5 |
2 |
Correct |
3 ms |
10840 KB |
n=100 |
3 |
Correct |
3 ms |
10844 KB |
n=100 |
4 |
Correct |
2 ms |
10844 KB |
n=100 |
5 |
Correct |
2 ms |
10844 KB |
n=100 |
6 |
Correct |
12 ms |
10904 KB |
n=100 |
7 |
Correct |
9 ms |
10900 KB |
n=100 |
8 |
Correct |
3 ms |
10844 KB |
n=100 |
9 |
Correct |
2 ms |
10840 KB |
n=100 |
10 |
Correct |
6 ms |
10844 KB |
n=100 |
11 |
Correct |
5 ms |
10844 KB |
n=100 |
12 |
Correct |
2 ms |
10844 KB |
n=100 |
13 |
Correct |
2 ms |
10840 KB |
n=100 |
14 |
Correct |
2 ms |
10844 KB |
n=100 |
15 |
Correct |
2 ms |
10844 KB |
n=100 |
16 |
Correct |
2 ms |
10840 KB |
n=100 |
17 |
Correct |
3 ms |
10844 KB |
n=100 |
18 |
Correct |
2 ms |
10840 KB |
n=100 |
19 |
Correct |
2 ms |
10840 KB |
n=100 |
20 |
Correct |
2 ms |
10848 KB |
n=100 |
21 |
Correct |
2 ms |
10844 KB |
n=100 |
22 |
Correct |
2 ms |
10844 KB |
n=100 |
23 |
Correct |
3 ms |
10844 KB |
n=100 |
24 |
Correct |
3 ms |
10844 KB |
n=100 |
25 |
Correct |
2 ms |
10844 KB |
n=100 |
26 |
Correct |
2 ms |
10844 KB |
n=12 |
27 |
Correct |
4 ms |
10844 KB |
n=100 |
28 |
Correct |
3 ms |
10844 KB |
n=500 |
29 |
Correct |
103 ms |
10840 KB |
n=500 |
30 |
Correct |
66 ms |
10924 KB |
n=500 |
31 |
Correct |
79 ms |
10928 KB |
n=500 |
32 |
Correct |
4 ms |
10844 KB |
n=500 |
33 |
Correct |
61 ms |
10844 KB |
n=500 |
34 |
Correct |
3 ms |
11096 KB |
n=500 |
35 |
Correct |
83 ms |
10840 KB |
n=500 |
36 |
Correct |
1067 ms |
10916 KB |
n=500 |
37 |
Correct |
1078 ms |
11088 KB |
n=500 |
38 |
Correct |
1058 ms |
10912 KB |
n=500 |
39 |
Correct |
112 ms |
10840 KB |
n=500 |
40 |
Correct |
103 ms |
10920 KB |
n=500 |
41 |
Correct |
105 ms |
10844 KB |
n=500 |
42 |
Correct |
534 ms |
11088 KB |
n=500 |
43 |
Correct |
523 ms |
10912 KB |
n=500 |
44 |
Correct |
504 ms |
10916 KB |
n=500 |
45 |
Correct |
4 ms |
10840 KB |
n=500 |
46 |
Correct |
90 ms |
10944 KB |
n=500 |
47 |
Correct |
73 ms |
10840 KB |
n=500 |
48 |
Correct |
2 ms |
10844 KB |
n=500 |
49 |
Correct |
70 ms |
10840 KB |
n=500 |
50 |
Correct |
75 ms |
11096 KB |
n=500 |
51 |
Correct |
122 ms |
10924 KB |
n=500 |
52 |
Correct |
156 ms |
10844 KB |
n=500 |
53 |
Correct |
113 ms |
10844 KB |
n=500 |
54 |
Correct |
63 ms |
10940 KB |
n=500 |
55 |
Correct |
16 ms |
10844 KB |
n=278 |
56 |
Correct |
567 ms |
10948 KB |
n=500 |
57 |
Correct |
594 ms |
10844 KB |
n=500 |
58 |
Correct |
409 ms |
10920 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10844 KB |
n=5 |
2 |
Correct |
3 ms |
10840 KB |
n=100 |
3 |
Correct |
3 ms |
10844 KB |
n=100 |
4 |
Correct |
2 ms |
10844 KB |
n=100 |
5 |
Correct |
2 ms |
10844 KB |
n=100 |
6 |
Correct |
12 ms |
10904 KB |
n=100 |
7 |
Correct |
9 ms |
10900 KB |
n=100 |
8 |
Correct |
3 ms |
10844 KB |
n=100 |
9 |
Correct |
2 ms |
10840 KB |
n=100 |
10 |
Correct |
6 ms |
10844 KB |
n=100 |
11 |
Correct |
5 ms |
10844 KB |
n=100 |
12 |
Correct |
2 ms |
10844 KB |
n=100 |
13 |
Correct |
2 ms |
10840 KB |
n=100 |
14 |
Correct |
2 ms |
10844 KB |
n=100 |
15 |
Correct |
2 ms |
10844 KB |
n=100 |
16 |
Correct |
2 ms |
10840 KB |
n=100 |
17 |
Correct |
3 ms |
10844 KB |
n=100 |
18 |
Correct |
2 ms |
10840 KB |
n=100 |
19 |
Correct |
2 ms |
10840 KB |
n=100 |
20 |
Correct |
2 ms |
10848 KB |
n=100 |
21 |
Correct |
2 ms |
10844 KB |
n=100 |
22 |
Correct |
2 ms |
10844 KB |
n=100 |
23 |
Correct |
3 ms |
10844 KB |
n=100 |
24 |
Correct |
3 ms |
10844 KB |
n=100 |
25 |
Correct |
2 ms |
10844 KB |
n=100 |
26 |
Correct |
2 ms |
10844 KB |
n=12 |
27 |
Correct |
4 ms |
10844 KB |
n=100 |
28 |
Correct |
3 ms |
10844 KB |
n=500 |
29 |
Correct |
103 ms |
10840 KB |
n=500 |
30 |
Correct |
66 ms |
10924 KB |
n=500 |
31 |
Correct |
79 ms |
10928 KB |
n=500 |
32 |
Correct |
4 ms |
10844 KB |
n=500 |
33 |
Correct |
61 ms |
10844 KB |
n=500 |
34 |
Correct |
3 ms |
11096 KB |
n=500 |
35 |
Correct |
83 ms |
10840 KB |
n=500 |
36 |
Correct |
1067 ms |
10916 KB |
n=500 |
37 |
Correct |
1078 ms |
11088 KB |
n=500 |
38 |
Correct |
1058 ms |
10912 KB |
n=500 |
39 |
Correct |
112 ms |
10840 KB |
n=500 |
40 |
Correct |
103 ms |
10920 KB |
n=500 |
41 |
Correct |
105 ms |
10844 KB |
n=500 |
42 |
Correct |
534 ms |
11088 KB |
n=500 |
43 |
Correct |
523 ms |
10912 KB |
n=500 |
44 |
Correct |
504 ms |
10916 KB |
n=500 |
45 |
Correct |
4 ms |
10840 KB |
n=500 |
46 |
Correct |
90 ms |
10944 KB |
n=500 |
47 |
Correct |
73 ms |
10840 KB |
n=500 |
48 |
Correct |
2 ms |
10844 KB |
n=500 |
49 |
Correct |
70 ms |
10840 KB |
n=500 |
50 |
Correct |
75 ms |
11096 KB |
n=500 |
51 |
Correct |
122 ms |
10924 KB |
n=500 |
52 |
Correct |
156 ms |
10844 KB |
n=500 |
53 |
Correct |
113 ms |
10844 KB |
n=500 |
54 |
Correct |
63 ms |
10940 KB |
n=500 |
55 |
Correct |
16 ms |
10844 KB |
n=278 |
56 |
Correct |
567 ms |
10948 KB |
n=500 |
57 |
Correct |
594 ms |
10844 KB |
n=500 |
58 |
Correct |
409 ms |
10920 KB |
n=500 |
59 |
Correct |
55 ms |
10844 KB |
n=2000 |
60 |
Execution timed out |
4072 ms |
11152 KB |
Time limit exceeded |
61 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10844 KB |
n=5 |
2 |
Correct |
3 ms |
10840 KB |
n=100 |
3 |
Correct |
3 ms |
10844 KB |
n=100 |
4 |
Correct |
2 ms |
10844 KB |
n=100 |
5 |
Correct |
2 ms |
10844 KB |
n=100 |
6 |
Correct |
12 ms |
10904 KB |
n=100 |
7 |
Correct |
9 ms |
10900 KB |
n=100 |
8 |
Correct |
3 ms |
10844 KB |
n=100 |
9 |
Correct |
2 ms |
10840 KB |
n=100 |
10 |
Correct |
6 ms |
10844 KB |
n=100 |
11 |
Correct |
5 ms |
10844 KB |
n=100 |
12 |
Correct |
2 ms |
10844 KB |
n=100 |
13 |
Correct |
2 ms |
10840 KB |
n=100 |
14 |
Correct |
2 ms |
10844 KB |
n=100 |
15 |
Correct |
2 ms |
10844 KB |
n=100 |
16 |
Correct |
2 ms |
10840 KB |
n=100 |
17 |
Correct |
3 ms |
10844 KB |
n=100 |
18 |
Correct |
2 ms |
10840 KB |
n=100 |
19 |
Correct |
2 ms |
10840 KB |
n=100 |
20 |
Correct |
2 ms |
10848 KB |
n=100 |
21 |
Correct |
2 ms |
10844 KB |
n=100 |
22 |
Correct |
2 ms |
10844 KB |
n=100 |
23 |
Correct |
3 ms |
10844 KB |
n=100 |
24 |
Correct |
3 ms |
10844 KB |
n=100 |
25 |
Correct |
2 ms |
10844 KB |
n=100 |
26 |
Correct |
2 ms |
10844 KB |
n=12 |
27 |
Correct |
4 ms |
10844 KB |
n=100 |
28 |
Correct |
3 ms |
10844 KB |
n=500 |
29 |
Correct |
103 ms |
10840 KB |
n=500 |
30 |
Correct |
66 ms |
10924 KB |
n=500 |
31 |
Correct |
79 ms |
10928 KB |
n=500 |
32 |
Correct |
4 ms |
10844 KB |
n=500 |
33 |
Correct |
61 ms |
10844 KB |
n=500 |
34 |
Correct |
3 ms |
11096 KB |
n=500 |
35 |
Correct |
83 ms |
10840 KB |
n=500 |
36 |
Correct |
1067 ms |
10916 KB |
n=500 |
37 |
Correct |
1078 ms |
11088 KB |
n=500 |
38 |
Correct |
1058 ms |
10912 KB |
n=500 |
39 |
Correct |
112 ms |
10840 KB |
n=500 |
40 |
Correct |
103 ms |
10920 KB |
n=500 |
41 |
Correct |
105 ms |
10844 KB |
n=500 |
42 |
Correct |
534 ms |
11088 KB |
n=500 |
43 |
Correct |
523 ms |
10912 KB |
n=500 |
44 |
Correct |
504 ms |
10916 KB |
n=500 |
45 |
Correct |
4 ms |
10840 KB |
n=500 |
46 |
Correct |
90 ms |
10944 KB |
n=500 |
47 |
Correct |
73 ms |
10840 KB |
n=500 |
48 |
Correct |
2 ms |
10844 KB |
n=500 |
49 |
Correct |
70 ms |
10840 KB |
n=500 |
50 |
Correct |
75 ms |
11096 KB |
n=500 |
51 |
Correct |
122 ms |
10924 KB |
n=500 |
52 |
Correct |
156 ms |
10844 KB |
n=500 |
53 |
Correct |
113 ms |
10844 KB |
n=500 |
54 |
Correct |
63 ms |
10940 KB |
n=500 |
55 |
Correct |
16 ms |
10844 KB |
n=278 |
56 |
Correct |
567 ms |
10948 KB |
n=500 |
57 |
Correct |
594 ms |
10844 KB |
n=500 |
58 |
Correct |
409 ms |
10920 KB |
n=500 |
59 |
Correct |
55 ms |
10844 KB |
n=2000 |
60 |
Execution timed out |
4072 ms |
11152 KB |
Time limit exceeded |
61 |
Halted |
0 ms |
0 KB |
- |