#include<bits/stdc++.h>
using namespace std;
#define ar array
#define fr first
#define sc second
#define vec vector
#define ret return
#define ins insert
#define mk make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define int long long
#define pii pair<int,int>
#define all(s) s.begin(), s.end()
#define allr(s) s.rbegin(), s.rend()
#define NeedForSpeed ios::sync_with_stdio(0),cin.tie(0);
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const int N=1e6+12,INF=1e9,mod = 1e9+7;
bool iswowel(char n){ n = toupper(n); if(n == 'A' || n == 'O' || n == 'U' || n == 'E' || n == 'I') return true; else return false;}
int n,m,k,x,y,l,ll,r,o,ans,res,timer,ok,mx,mn = INF;
int a[N], tin[N], tout[N];
vec<int>g[N];
int up[N][30];
void dfs(int v, int pred){
tin[v] = ++timer;
up[v][0] = pred;
for(int i=1; i<=l; i++)
up[v][i] = up[up[v][i-1]][i-1];
for(int to : g[v]){
if(to != pred){
dfs(to, v);
}
}
tout[v] = ++timer;
}
bool upper(int a, int b){
ret tin[a] <= tin[b] && tout[b] <= tout[a];
}
int lca(int a, int b){
if(upper(a, b))ret a;
if(upper(b, a))ret b;
for(int i=l; i>=0; i--){
if(!upper(up[a][i], b))
a = up[a][i];
}
ret up[a][0];
}
main(){
NeedForSpeed
cin>>m>>n>>o;
m--;
while(m--){
cin>>x>>y;
g[x].pb(y);
g[y].pb(x);
}
for(int i=1; i<=n; i++)cin>>a[i];
l = 1;
while((1<<l) <= n)l++;
dfs(1,1);
while(o--){
cin>>ok;
if(ok == 1){
cin>>ll>>r;
a[ll] = r;
}
else{
y = 0;
cin>>ll>>r>>x;
for(int i=ll; i<=r; i++){
res = a[i], ans = 0;
for(int j=i; j<=r; j++){
res = lca(res, a[j]);
if(res == x){
cout<<i<<" "<<j<<endl;
y = 1;
ans = 1;
break;
}
}
if(ans)break;
}
if(!y)cout<<"-1 -1"<<endl;
}
}
return 0;
}
Compilation message
treearray.cpp:59:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
59 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23756 KB |
n=5 |
2 |
Correct |
12 ms |
23780 KB |
n=100 |
3 |
Correct |
12 ms |
23808 KB |
n=100 |
4 |
Correct |
12 ms |
23808 KB |
n=100 |
5 |
Correct |
12 ms |
23796 KB |
n=100 |
6 |
Correct |
13 ms |
23816 KB |
n=100 |
7 |
Correct |
13 ms |
23756 KB |
n=100 |
8 |
Correct |
12 ms |
23756 KB |
n=100 |
9 |
Correct |
13 ms |
23816 KB |
n=100 |
10 |
Correct |
12 ms |
23756 KB |
n=100 |
11 |
Correct |
13 ms |
23756 KB |
n=100 |
12 |
Correct |
12 ms |
23816 KB |
n=100 |
13 |
Correct |
12 ms |
23756 KB |
n=100 |
14 |
Correct |
12 ms |
23756 KB |
n=100 |
15 |
Correct |
12 ms |
23756 KB |
n=100 |
16 |
Correct |
12 ms |
23756 KB |
n=100 |
17 |
Correct |
12 ms |
23760 KB |
n=100 |
18 |
Correct |
12 ms |
23856 KB |
n=100 |
19 |
Correct |
12 ms |
23840 KB |
n=100 |
20 |
Correct |
12 ms |
23756 KB |
n=100 |
21 |
Correct |
12 ms |
23812 KB |
n=100 |
22 |
Correct |
12 ms |
23816 KB |
n=100 |
23 |
Correct |
12 ms |
23752 KB |
n=100 |
24 |
Correct |
12 ms |
23756 KB |
n=100 |
25 |
Correct |
13 ms |
23756 KB |
n=100 |
26 |
Correct |
12 ms |
23772 KB |
n=12 |
27 |
Correct |
12 ms |
23756 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23756 KB |
n=5 |
2 |
Correct |
12 ms |
23780 KB |
n=100 |
3 |
Correct |
12 ms |
23808 KB |
n=100 |
4 |
Correct |
12 ms |
23808 KB |
n=100 |
5 |
Correct |
12 ms |
23796 KB |
n=100 |
6 |
Correct |
13 ms |
23816 KB |
n=100 |
7 |
Correct |
13 ms |
23756 KB |
n=100 |
8 |
Correct |
12 ms |
23756 KB |
n=100 |
9 |
Correct |
13 ms |
23816 KB |
n=100 |
10 |
Correct |
12 ms |
23756 KB |
n=100 |
11 |
Correct |
13 ms |
23756 KB |
n=100 |
12 |
Correct |
12 ms |
23816 KB |
n=100 |
13 |
Correct |
12 ms |
23756 KB |
n=100 |
14 |
Correct |
12 ms |
23756 KB |
n=100 |
15 |
Correct |
12 ms |
23756 KB |
n=100 |
16 |
Correct |
12 ms |
23756 KB |
n=100 |
17 |
Correct |
12 ms |
23760 KB |
n=100 |
18 |
Correct |
12 ms |
23856 KB |
n=100 |
19 |
Correct |
12 ms |
23840 KB |
n=100 |
20 |
Correct |
12 ms |
23756 KB |
n=100 |
21 |
Correct |
12 ms |
23812 KB |
n=100 |
22 |
Correct |
12 ms |
23816 KB |
n=100 |
23 |
Correct |
12 ms |
23752 KB |
n=100 |
24 |
Correct |
12 ms |
23756 KB |
n=100 |
25 |
Correct |
13 ms |
23756 KB |
n=100 |
26 |
Correct |
12 ms |
23772 KB |
n=12 |
27 |
Correct |
12 ms |
23756 KB |
n=100 |
28 |
Correct |
13 ms |
23972 KB |
n=500 |
29 |
Correct |
27 ms |
23956 KB |
n=500 |
30 |
Correct |
23 ms |
23884 KB |
n=500 |
31 |
Correct |
24 ms |
23948 KB |
n=500 |
32 |
Correct |
13 ms |
23964 KB |
n=500 |
33 |
Correct |
23 ms |
23884 KB |
n=500 |
34 |
Correct |
12 ms |
23932 KB |
n=500 |
35 |
Correct |
24 ms |
23960 KB |
n=500 |
36 |
Correct |
166 ms |
23944 KB |
n=500 |
37 |
Correct |
165 ms |
23884 KB |
n=500 |
38 |
Correct |
159 ms |
23884 KB |
n=500 |
39 |
Correct |
33 ms |
23884 KB |
n=500 |
40 |
Correct |
32 ms |
23884 KB |
n=500 |
41 |
Correct |
32 ms |
23884 KB |
n=500 |
42 |
Correct |
88 ms |
23952 KB |
n=500 |
43 |
Correct |
84 ms |
23884 KB |
n=500 |
44 |
Correct |
85 ms |
23944 KB |
n=500 |
45 |
Correct |
13 ms |
23884 KB |
n=500 |
46 |
Correct |
25 ms |
24012 KB |
n=500 |
47 |
Correct |
23 ms |
23884 KB |
n=500 |
48 |
Correct |
12 ms |
23884 KB |
n=500 |
49 |
Correct |
23 ms |
24000 KB |
n=500 |
50 |
Correct |
30 ms |
23884 KB |
n=500 |
51 |
Correct |
31 ms |
23976 KB |
n=500 |
52 |
Correct |
35 ms |
23884 KB |
n=500 |
53 |
Correct |
33 ms |
23876 KB |
n=500 |
54 |
Correct |
21 ms |
23948 KB |
n=500 |
55 |
Correct |
16 ms |
23896 KB |
n=278 |
56 |
Correct |
90 ms |
23884 KB |
n=500 |
57 |
Correct |
93 ms |
23884 KB |
n=500 |
58 |
Correct |
75 ms |
23884 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23756 KB |
n=5 |
2 |
Correct |
12 ms |
23780 KB |
n=100 |
3 |
Correct |
12 ms |
23808 KB |
n=100 |
4 |
Correct |
12 ms |
23808 KB |
n=100 |
5 |
Correct |
12 ms |
23796 KB |
n=100 |
6 |
Correct |
13 ms |
23816 KB |
n=100 |
7 |
Correct |
13 ms |
23756 KB |
n=100 |
8 |
Correct |
12 ms |
23756 KB |
n=100 |
9 |
Correct |
13 ms |
23816 KB |
n=100 |
10 |
Correct |
12 ms |
23756 KB |
n=100 |
11 |
Correct |
13 ms |
23756 KB |
n=100 |
12 |
Correct |
12 ms |
23816 KB |
n=100 |
13 |
Correct |
12 ms |
23756 KB |
n=100 |
14 |
Correct |
12 ms |
23756 KB |
n=100 |
15 |
Correct |
12 ms |
23756 KB |
n=100 |
16 |
Correct |
12 ms |
23756 KB |
n=100 |
17 |
Correct |
12 ms |
23760 KB |
n=100 |
18 |
Correct |
12 ms |
23856 KB |
n=100 |
19 |
Correct |
12 ms |
23840 KB |
n=100 |
20 |
Correct |
12 ms |
23756 KB |
n=100 |
21 |
Correct |
12 ms |
23812 KB |
n=100 |
22 |
Correct |
12 ms |
23816 KB |
n=100 |
23 |
Correct |
12 ms |
23752 KB |
n=100 |
24 |
Correct |
12 ms |
23756 KB |
n=100 |
25 |
Correct |
13 ms |
23756 KB |
n=100 |
26 |
Correct |
12 ms |
23772 KB |
n=12 |
27 |
Correct |
12 ms |
23756 KB |
n=100 |
28 |
Correct |
13 ms |
23972 KB |
n=500 |
29 |
Correct |
27 ms |
23956 KB |
n=500 |
30 |
Correct |
23 ms |
23884 KB |
n=500 |
31 |
Correct |
24 ms |
23948 KB |
n=500 |
32 |
Correct |
13 ms |
23964 KB |
n=500 |
33 |
Correct |
23 ms |
23884 KB |
n=500 |
34 |
Correct |
12 ms |
23932 KB |
n=500 |
35 |
Correct |
24 ms |
23960 KB |
n=500 |
36 |
Correct |
166 ms |
23944 KB |
n=500 |
37 |
Correct |
165 ms |
23884 KB |
n=500 |
38 |
Correct |
159 ms |
23884 KB |
n=500 |
39 |
Correct |
33 ms |
23884 KB |
n=500 |
40 |
Correct |
32 ms |
23884 KB |
n=500 |
41 |
Correct |
32 ms |
23884 KB |
n=500 |
42 |
Correct |
88 ms |
23952 KB |
n=500 |
43 |
Correct |
84 ms |
23884 KB |
n=500 |
44 |
Correct |
85 ms |
23944 KB |
n=500 |
45 |
Correct |
13 ms |
23884 KB |
n=500 |
46 |
Correct |
25 ms |
24012 KB |
n=500 |
47 |
Correct |
23 ms |
23884 KB |
n=500 |
48 |
Correct |
12 ms |
23884 KB |
n=500 |
49 |
Correct |
23 ms |
24000 KB |
n=500 |
50 |
Correct |
30 ms |
23884 KB |
n=500 |
51 |
Correct |
31 ms |
23976 KB |
n=500 |
52 |
Correct |
35 ms |
23884 KB |
n=500 |
53 |
Correct |
33 ms |
23876 KB |
n=500 |
54 |
Correct |
21 ms |
23948 KB |
n=500 |
55 |
Correct |
16 ms |
23896 KB |
n=278 |
56 |
Correct |
90 ms |
23884 KB |
n=500 |
57 |
Correct |
93 ms |
23884 KB |
n=500 |
58 |
Correct |
75 ms |
23884 KB |
n=500 |
59 |
Correct |
25 ms |
24472 KB |
n=2000 |
60 |
Correct |
796 ms |
24548 KB |
n=2000 |
61 |
Correct |
755 ms |
24524 KB |
n=2000 |
62 |
Correct |
516 ms |
24516 KB |
n=2000 |
63 |
Correct |
29 ms |
24396 KB |
n=2000 |
64 |
Correct |
661 ms |
24500 KB |
n=2000 |
65 |
Correct |
16 ms |
24396 KB |
n=2000 |
66 |
Correct |
858 ms |
24524 KB |
n=2000 |
67 |
Correct |
51 ms |
24396 KB |
n=2000 |
68 |
Correct |
684 ms |
24456 KB |
n=2000 |
69 |
Execution timed out |
4082 ms |
24480 KB |
Time limit exceeded |
70 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23756 KB |
n=5 |
2 |
Correct |
12 ms |
23780 KB |
n=100 |
3 |
Correct |
12 ms |
23808 KB |
n=100 |
4 |
Correct |
12 ms |
23808 KB |
n=100 |
5 |
Correct |
12 ms |
23796 KB |
n=100 |
6 |
Correct |
13 ms |
23816 KB |
n=100 |
7 |
Correct |
13 ms |
23756 KB |
n=100 |
8 |
Correct |
12 ms |
23756 KB |
n=100 |
9 |
Correct |
13 ms |
23816 KB |
n=100 |
10 |
Correct |
12 ms |
23756 KB |
n=100 |
11 |
Correct |
13 ms |
23756 KB |
n=100 |
12 |
Correct |
12 ms |
23816 KB |
n=100 |
13 |
Correct |
12 ms |
23756 KB |
n=100 |
14 |
Correct |
12 ms |
23756 KB |
n=100 |
15 |
Correct |
12 ms |
23756 KB |
n=100 |
16 |
Correct |
12 ms |
23756 KB |
n=100 |
17 |
Correct |
12 ms |
23760 KB |
n=100 |
18 |
Correct |
12 ms |
23856 KB |
n=100 |
19 |
Correct |
12 ms |
23840 KB |
n=100 |
20 |
Correct |
12 ms |
23756 KB |
n=100 |
21 |
Correct |
12 ms |
23812 KB |
n=100 |
22 |
Correct |
12 ms |
23816 KB |
n=100 |
23 |
Correct |
12 ms |
23752 KB |
n=100 |
24 |
Correct |
12 ms |
23756 KB |
n=100 |
25 |
Correct |
13 ms |
23756 KB |
n=100 |
26 |
Correct |
12 ms |
23772 KB |
n=12 |
27 |
Correct |
12 ms |
23756 KB |
n=100 |
28 |
Correct |
13 ms |
23972 KB |
n=500 |
29 |
Correct |
27 ms |
23956 KB |
n=500 |
30 |
Correct |
23 ms |
23884 KB |
n=500 |
31 |
Correct |
24 ms |
23948 KB |
n=500 |
32 |
Correct |
13 ms |
23964 KB |
n=500 |
33 |
Correct |
23 ms |
23884 KB |
n=500 |
34 |
Correct |
12 ms |
23932 KB |
n=500 |
35 |
Correct |
24 ms |
23960 KB |
n=500 |
36 |
Correct |
166 ms |
23944 KB |
n=500 |
37 |
Correct |
165 ms |
23884 KB |
n=500 |
38 |
Correct |
159 ms |
23884 KB |
n=500 |
39 |
Correct |
33 ms |
23884 KB |
n=500 |
40 |
Correct |
32 ms |
23884 KB |
n=500 |
41 |
Correct |
32 ms |
23884 KB |
n=500 |
42 |
Correct |
88 ms |
23952 KB |
n=500 |
43 |
Correct |
84 ms |
23884 KB |
n=500 |
44 |
Correct |
85 ms |
23944 KB |
n=500 |
45 |
Correct |
13 ms |
23884 KB |
n=500 |
46 |
Correct |
25 ms |
24012 KB |
n=500 |
47 |
Correct |
23 ms |
23884 KB |
n=500 |
48 |
Correct |
12 ms |
23884 KB |
n=500 |
49 |
Correct |
23 ms |
24000 KB |
n=500 |
50 |
Correct |
30 ms |
23884 KB |
n=500 |
51 |
Correct |
31 ms |
23976 KB |
n=500 |
52 |
Correct |
35 ms |
23884 KB |
n=500 |
53 |
Correct |
33 ms |
23876 KB |
n=500 |
54 |
Correct |
21 ms |
23948 KB |
n=500 |
55 |
Correct |
16 ms |
23896 KB |
n=278 |
56 |
Correct |
90 ms |
23884 KB |
n=500 |
57 |
Correct |
93 ms |
23884 KB |
n=500 |
58 |
Correct |
75 ms |
23884 KB |
n=500 |
59 |
Correct |
25 ms |
24472 KB |
n=2000 |
60 |
Correct |
796 ms |
24548 KB |
n=2000 |
61 |
Correct |
755 ms |
24524 KB |
n=2000 |
62 |
Correct |
516 ms |
24516 KB |
n=2000 |
63 |
Correct |
29 ms |
24396 KB |
n=2000 |
64 |
Correct |
661 ms |
24500 KB |
n=2000 |
65 |
Correct |
16 ms |
24396 KB |
n=2000 |
66 |
Correct |
858 ms |
24524 KB |
n=2000 |
67 |
Correct |
51 ms |
24396 KB |
n=2000 |
68 |
Correct |
684 ms |
24456 KB |
n=2000 |
69 |
Execution timed out |
4082 ms |
24480 KB |
Time limit exceeded |
70 |
Halted |
0 ms |
0 KB |
- |