#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];
set<int>s[N], ss[N];
void dfs(int v, int pred){
tin[v] = ++timer;
up[v][0] = pred;
for(int i=1; i<=22; 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=22; i>=0; i--){
if(!upper(up[a][i], b))
a = up[a][i];
}
ret up[a][0];
}
map<int, int>mp;
main(){
NeedForSpeed
cin>>m>>n>>o;
m--;
while(m--){
cin>>x>>y;
g[x].pb(y);
g[y].pb(x);
}
dfs(1,1);
for(int i=1; i<=n; i++){
cin>>a[i];
ss[a[i]].ins(i);
}
for(int i=1; i<=n; i++)
s[lca(a[i], a[i+1])].ins(i);
while(o--){
cin>>ok;
if(ok == 1){
cin>>l>>r;
ss[a[l]].erase(l);
s[lca(a[l], a[l+1])].erase(l);
s[lca(a[l-1], a[l])].erase(l-1);
a[l] = r;
ss[a[l]].ins(l);
if(l < n)s[lca(a[l], a[l+1])].ins(l);
if(1 < l)s[lca(a[l-1], a[l])].ins(l-1);
}
else{
ans = -1, res = -1;
cin>>l>>r>>x;
auto it = ss[x].lower_bound(l);
if(it != ss[x].end() && *it <= r)ans = *it, res = *it;
it = s[x].lower_bound(l);
if(it != s[x].end() && *it < r)ans = *it, res = *it+1;
cout<<ans<<" "<<res<<endl;
}
}
return 0;
}
Compilation message
treearray.cpp:63:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
63 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
117620 KB |
n=5 |
2 |
Correct |
56 ms |
117760 KB |
n=100 |
3 |
Correct |
56 ms |
117700 KB |
n=100 |
4 |
Correct |
55 ms |
117680 KB |
n=100 |
5 |
Correct |
67 ms |
117684 KB |
n=100 |
6 |
Correct |
61 ms |
117736 KB |
n=100 |
7 |
Correct |
59 ms |
117700 KB |
n=100 |
8 |
Correct |
57 ms |
117700 KB |
n=100 |
9 |
Correct |
56 ms |
117700 KB |
n=100 |
10 |
Correct |
60 ms |
117688 KB |
n=100 |
11 |
Correct |
58 ms |
117700 KB |
n=100 |
12 |
Correct |
56 ms |
117656 KB |
n=100 |
13 |
Correct |
58 ms |
117748 KB |
n=100 |
14 |
Correct |
61 ms |
117696 KB |
n=100 |
15 |
Correct |
56 ms |
117772 KB |
n=100 |
16 |
Correct |
57 ms |
117712 KB |
n=100 |
17 |
Correct |
55 ms |
117776 KB |
n=100 |
18 |
Correct |
55 ms |
117688 KB |
n=100 |
19 |
Correct |
73 ms |
117696 KB |
n=100 |
20 |
Correct |
57 ms |
117752 KB |
n=100 |
21 |
Correct |
59 ms |
117700 KB |
n=100 |
22 |
Correct |
54 ms |
117700 KB |
n=100 |
23 |
Correct |
55 ms |
117656 KB |
n=100 |
24 |
Correct |
63 ms |
117692 KB |
n=100 |
25 |
Correct |
70 ms |
117780 KB |
n=100 |
26 |
Correct |
59 ms |
117724 KB |
n=12 |
27 |
Correct |
58 ms |
117708 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
117620 KB |
n=5 |
2 |
Correct |
56 ms |
117760 KB |
n=100 |
3 |
Correct |
56 ms |
117700 KB |
n=100 |
4 |
Correct |
55 ms |
117680 KB |
n=100 |
5 |
Correct |
67 ms |
117684 KB |
n=100 |
6 |
Correct |
61 ms |
117736 KB |
n=100 |
7 |
Correct |
59 ms |
117700 KB |
n=100 |
8 |
Correct |
57 ms |
117700 KB |
n=100 |
9 |
Correct |
56 ms |
117700 KB |
n=100 |
10 |
Correct |
60 ms |
117688 KB |
n=100 |
11 |
Correct |
58 ms |
117700 KB |
n=100 |
12 |
Correct |
56 ms |
117656 KB |
n=100 |
13 |
Correct |
58 ms |
117748 KB |
n=100 |
14 |
Correct |
61 ms |
117696 KB |
n=100 |
15 |
Correct |
56 ms |
117772 KB |
n=100 |
16 |
Correct |
57 ms |
117712 KB |
n=100 |
17 |
Correct |
55 ms |
117776 KB |
n=100 |
18 |
Correct |
55 ms |
117688 KB |
n=100 |
19 |
Correct |
73 ms |
117696 KB |
n=100 |
20 |
Correct |
57 ms |
117752 KB |
n=100 |
21 |
Correct |
59 ms |
117700 KB |
n=100 |
22 |
Correct |
54 ms |
117700 KB |
n=100 |
23 |
Correct |
55 ms |
117656 KB |
n=100 |
24 |
Correct |
63 ms |
117692 KB |
n=100 |
25 |
Correct |
70 ms |
117780 KB |
n=100 |
26 |
Correct |
59 ms |
117724 KB |
n=12 |
27 |
Correct |
58 ms |
117708 KB |
n=100 |
28 |
Correct |
57 ms |
117888 KB |
n=500 |
29 |
Correct |
64 ms |
117948 KB |
n=500 |
30 |
Correct |
69 ms |
117840 KB |
n=500 |
31 |
Correct |
58 ms |
117956 KB |
n=500 |
32 |
Correct |
55 ms |
117828 KB |
n=500 |
33 |
Correct |
55 ms |
117844 KB |
n=500 |
34 |
Correct |
57 ms |
117840 KB |
n=500 |
35 |
Correct |
56 ms |
117932 KB |
n=500 |
36 |
Correct |
71 ms |
117880 KB |
n=500 |
37 |
Correct |
64 ms |
117924 KB |
n=500 |
38 |
Correct |
55 ms |
117964 KB |
n=500 |
39 |
Correct |
56 ms |
117964 KB |
n=500 |
40 |
Correct |
56 ms |
117856 KB |
n=500 |
41 |
Correct |
55 ms |
117900 KB |
n=500 |
42 |
Correct |
59 ms |
117880 KB |
n=500 |
43 |
Correct |
56 ms |
117912 KB |
n=500 |
44 |
Correct |
70 ms |
117872 KB |
n=500 |
45 |
Correct |
55 ms |
117932 KB |
n=500 |
46 |
Correct |
55 ms |
117956 KB |
n=500 |
47 |
Correct |
55 ms |
117896 KB |
n=500 |
48 |
Correct |
56 ms |
117956 KB |
n=500 |
49 |
Correct |
78 ms |
117964 KB |
n=500 |
50 |
Correct |
62 ms |
117828 KB |
n=500 |
51 |
Correct |
63 ms |
117956 KB |
n=500 |
52 |
Correct |
55 ms |
117976 KB |
n=500 |
53 |
Correct |
57 ms |
117920 KB |
n=500 |
54 |
Correct |
66 ms |
117956 KB |
n=500 |
55 |
Correct |
66 ms |
117828 KB |
n=278 |
56 |
Correct |
56 ms |
117880 KB |
n=500 |
57 |
Correct |
55 ms |
117956 KB |
n=500 |
58 |
Correct |
54 ms |
117860 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
117620 KB |
n=5 |
2 |
Correct |
56 ms |
117760 KB |
n=100 |
3 |
Correct |
56 ms |
117700 KB |
n=100 |
4 |
Correct |
55 ms |
117680 KB |
n=100 |
5 |
Correct |
67 ms |
117684 KB |
n=100 |
6 |
Correct |
61 ms |
117736 KB |
n=100 |
7 |
Correct |
59 ms |
117700 KB |
n=100 |
8 |
Correct |
57 ms |
117700 KB |
n=100 |
9 |
Correct |
56 ms |
117700 KB |
n=100 |
10 |
Correct |
60 ms |
117688 KB |
n=100 |
11 |
Correct |
58 ms |
117700 KB |
n=100 |
12 |
Correct |
56 ms |
117656 KB |
n=100 |
13 |
Correct |
58 ms |
117748 KB |
n=100 |
14 |
Correct |
61 ms |
117696 KB |
n=100 |
15 |
Correct |
56 ms |
117772 KB |
n=100 |
16 |
Correct |
57 ms |
117712 KB |
n=100 |
17 |
Correct |
55 ms |
117776 KB |
n=100 |
18 |
Correct |
55 ms |
117688 KB |
n=100 |
19 |
Correct |
73 ms |
117696 KB |
n=100 |
20 |
Correct |
57 ms |
117752 KB |
n=100 |
21 |
Correct |
59 ms |
117700 KB |
n=100 |
22 |
Correct |
54 ms |
117700 KB |
n=100 |
23 |
Correct |
55 ms |
117656 KB |
n=100 |
24 |
Correct |
63 ms |
117692 KB |
n=100 |
25 |
Correct |
70 ms |
117780 KB |
n=100 |
26 |
Correct |
59 ms |
117724 KB |
n=12 |
27 |
Correct |
58 ms |
117708 KB |
n=100 |
28 |
Correct |
57 ms |
117888 KB |
n=500 |
29 |
Correct |
64 ms |
117948 KB |
n=500 |
30 |
Correct |
69 ms |
117840 KB |
n=500 |
31 |
Correct |
58 ms |
117956 KB |
n=500 |
32 |
Correct |
55 ms |
117828 KB |
n=500 |
33 |
Correct |
55 ms |
117844 KB |
n=500 |
34 |
Correct |
57 ms |
117840 KB |
n=500 |
35 |
Correct |
56 ms |
117932 KB |
n=500 |
36 |
Correct |
71 ms |
117880 KB |
n=500 |
37 |
Correct |
64 ms |
117924 KB |
n=500 |
38 |
Correct |
55 ms |
117964 KB |
n=500 |
39 |
Correct |
56 ms |
117964 KB |
n=500 |
40 |
Correct |
56 ms |
117856 KB |
n=500 |
41 |
Correct |
55 ms |
117900 KB |
n=500 |
42 |
Correct |
59 ms |
117880 KB |
n=500 |
43 |
Correct |
56 ms |
117912 KB |
n=500 |
44 |
Correct |
70 ms |
117872 KB |
n=500 |
45 |
Correct |
55 ms |
117932 KB |
n=500 |
46 |
Correct |
55 ms |
117956 KB |
n=500 |
47 |
Correct |
55 ms |
117896 KB |
n=500 |
48 |
Correct |
56 ms |
117956 KB |
n=500 |
49 |
Correct |
78 ms |
117964 KB |
n=500 |
50 |
Correct |
62 ms |
117828 KB |
n=500 |
51 |
Correct |
63 ms |
117956 KB |
n=500 |
52 |
Correct |
55 ms |
117976 KB |
n=500 |
53 |
Correct |
57 ms |
117920 KB |
n=500 |
54 |
Correct |
66 ms |
117956 KB |
n=500 |
55 |
Correct |
66 ms |
117828 KB |
n=278 |
56 |
Correct |
56 ms |
117880 KB |
n=500 |
57 |
Correct |
55 ms |
117956 KB |
n=500 |
58 |
Correct |
54 ms |
117860 KB |
n=500 |
59 |
Correct |
58 ms |
118552 KB |
n=2000 |
60 |
Correct |
61 ms |
118636 KB |
n=2000 |
61 |
Correct |
60 ms |
118504 KB |
n=2000 |
62 |
Correct |
59 ms |
118548 KB |
n=2000 |
63 |
Correct |
62 ms |
118540 KB |
n=2000 |
64 |
Correct |
70 ms |
118544 KB |
n=2000 |
65 |
Correct |
60 ms |
118468 KB |
n=2000 |
66 |
Correct |
64 ms |
118716 KB |
n=2000 |
67 |
Correct |
61 ms |
118520 KB |
n=2000 |
68 |
Correct |
68 ms |
118588 KB |
n=2000 |
69 |
Correct |
60 ms |
118516 KB |
n=2000 |
70 |
Correct |
62 ms |
118504 KB |
n=2000 |
71 |
Correct |
59 ms |
118596 KB |
n=2000 |
72 |
Correct |
59 ms |
118560 KB |
n=2000 |
73 |
Correct |
72 ms |
118584 KB |
n=2000 |
74 |
Correct |
60 ms |
118464 KB |
n=1844 |
75 |
Correct |
62 ms |
118508 KB |
n=2000 |
76 |
Correct |
64 ms |
118584 KB |
n=2000 |
77 |
Correct |
72 ms |
118528 KB |
n=2000 |
78 |
Correct |
66 ms |
118528 KB |
n=2000 |
79 |
Correct |
59 ms |
118464 KB |
n=2000 |
80 |
Correct |
59 ms |
118596 KB |
n=2000 |
81 |
Correct |
59 ms |
118504 KB |
n=2000 |
82 |
Correct |
66 ms |
118596 KB |
n=2000 |
83 |
Correct |
59 ms |
118600 KB |
n=2000 |
84 |
Correct |
59 ms |
118492 KB |
n=2000 |
85 |
Correct |
62 ms |
118504 KB |
n=2000 |
86 |
Correct |
61 ms |
118596 KB |
n=2000 |
87 |
Correct |
70 ms |
118472 KB |
n=2000 |
88 |
Correct |
61 ms |
118896 KB |
n=2000 |
89 |
Correct |
59 ms |
118540 KB |
n=2000 |
90 |
Correct |
57 ms |
118596 KB |
n=2000 |
91 |
Correct |
60 ms |
118480 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
117620 KB |
n=5 |
2 |
Correct |
56 ms |
117760 KB |
n=100 |
3 |
Correct |
56 ms |
117700 KB |
n=100 |
4 |
Correct |
55 ms |
117680 KB |
n=100 |
5 |
Correct |
67 ms |
117684 KB |
n=100 |
6 |
Correct |
61 ms |
117736 KB |
n=100 |
7 |
Correct |
59 ms |
117700 KB |
n=100 |
8 |
Correct |
57 ms |
117700 KB |
n=100 |
9 |
Correct |
56 ms |
117700 KB |
n=100 |
10 |
Correct |
60 ms |
117688 KB |
n=100 |
11 |
Correct |
58 ms |
117700 KB |
n=100 |
12 |
Correct |
56 ms |
117656 KB |
n=100 |
13 |
Correct |
58 ms |
117748 KB |
n=100 |
14 |
Correct |
61 ms |
117696 KB |
n=100 |
15 |
Correct |
56 ms |
117772 KB |
n=100 |
16 |
Correct |
57 ms |
117712 KB |
n=100 |
17 |
Correct |
55 ms |
117776 KB |
n=100 |
18 |
Correct |
55 ms |
117688 KB |
n=100 |
19 |
Correct |
73 ms |
117696 KB |
n=100 |
20 |
Correct |
57 ms |
117752 KB |
n=100 |
21 |
Correct |
59 ms |
117700 KB |
n=100 |
22 |
Correct |
54 ms |
117700 KB |
n=100 |
23 |
Correct |
55 ms |
117656 KB |
n=100 |
24 |
Correct |
63 ms |
117692 KB |
n=100 |
25 |
Correct |
70 ms |
117780 KB |
n=100 |
26 |
Correct |
59 ms |
117724 KB |
n=12 |
27 |
Correct |
58 ms |
117708 KB |
n=100 |
28 |
Correct |
57 ms |
117888 KB |
n=500 |
29 |
Correct |
64 ms |
117948 KB |
n=500 |
30 |
Correct |
69 ms |
117840 KB |
n=500 |
31 |
Correct |
58 ms |
117956 KB |
n=500 |
32 |
Correct |
55 ms |
117828 KB |
n=500 |
33 |
Correct |
55 ms |
117844 KB |
n=500 |
34 |
Correct |
57 ms |
117840 KB |
n=500 |
35 |
Correct |
56 ms |
117932 KB |
n=500 |
36 |
Correct |
71 ms |
117880 KB |
n=500 |
37 |
Correct |
64 ms |
117924 KB |
n=500 |
38 |
Correct |
55 ms |
117964 KB |
n=500 |
39 |
Correct |
56 ms |
117964 KB |
n=500 |
40 |
Correct |
56 ms |
117856 KB |
n=500 |
41 |
Correct |
55 ms |
117900 KB |
n=500 |
42 |
Correct |
59 ms |
117880 KB |
n=500 |
43 |
Correct |
56 ms |
117912 KB |
n=500 |
44 |
Correct |
70 ms |
117872 KB |
n=500 |
45 |
Correct |
55 ms |
117932 KB |
n=500 |
46 |
Correct |
55 ms |
117956 KB |
n=500 |
47 |
Correct |
55 ms |
117896 KB |
n=500 |
48 |
Correct |
56 ms |
117956 KB |
n=500 |
49 |
Correct |
78 ms |
117964 KB |
n=500 |
50 |
Correct |
62 ms |
117828 KB |
n=500 |
51 |
Correct |
63 ms |
117956 KB |
n=500 |
52 |
Correct |
55 ms |
117976 KB |
n=500 |
53 |
Correct |
57 ms |
117920 KB |
n=500 |
54 |
Correct |
66 ms |
117956 KB |
n=500 |
55 |
Correct |
66 ms |
117828 KB |
n=278 |
56 |
Correct |
56 ms |
117880 KB |
n=500 |
57 |
Correct |
55 ms |
117956 KB |
n=500 |
58 |
Correct |
54 ms |
117860 KB |
n=500 |
59 |
Correct |
58 ms |
118552 KB |
n=2000 |
60 |
Correct |
61 ms |
118636 KB |
n=2000 |
61 |
Correct |
60 ms |
118504 KB |
n=2000 |
62 |
Correct |
59 ms |
118548 KB |
n=2000 |
63 |
Correct |
62 ms |
118540 KB |
n=2000 |
64 |
Correct |
70 ms |
118544 KB |
n=2000 |
65 |
Correct |
60 ms |
118468 KB |
n=2000 |
66 |
Correct |
64 ms |
118716 KB |
n=2000 |
67 |
Correct |
61 ms |
118520 KB |
n=2000 |
68 |
Correct |
68 ms |
118588 KB |
n=2000 |
69 |
Correct |
60 ms |
118516 KB |
n=2000 |
70 |
Correct |
62 ms |
118504 KB |
n=2000 |
71 |
Correct |
59 ms |
118596 KB |
n=2000 |
72 |
Correct |
59 ms |
118560 KB |
n=2000 |
73 |
Correct |
72 ms |
118584 KB |
n=2000 |
74 |
Correct |
60 ms |
118464 KB |
n=1844 |
75 |
Correct |
62 ms |
118508 KB |
n=2000 |
76 |
Correct |
64 ms |
118584 KB |
n=2000 |
77 |
Correct |
72 ms |
118528 KB |
n=2000 |
78 |
Correct |
66 ms |
118528 KB |
n=2000 |
79 |
Correct |
59 ms |
118464 KB |
n=2000 |
80 |
Correct |
59 ms |
118596 KB |
n=2000 |
81 |
Correct |
59 ms |
118504 KB |
n=2000 |
82 |
Correct |
66 ms |
118596 KB |
n=2000 |
83 |
Correct |
59 ms |
118600 KB |
n=2000 |
84 |
Correct |
59 ms |
118492 KB |
n=2000 |
85 |
Correct |
62 ms |
118504 KB |
n=2000 |
86 |
Correct |
61 ms |
118596 KB |
n=2000 |
87 |
Correct |
70 ms |
118472 KB |
n=2000 |
88 |
Correct |
61 ms |
118896 KB |
n=2000 |
89 |
Correct |
59 ms |
118540 KB |
n=2000 |
90 |
Correct |
57 ms |
118596 KB |
n=2000 |
91 |
Correct |
60 ms |
118480 KB |
n=2000 |
92 |
Correct |
957 ms |
203692 KB |
n=200000 |
93 |
Correct |
1068 ms |
208552 KB |
n=200000 |
94 |
Correct |
788 ms |
211672 KB |
n=200000 |
95 |
Correct |
878 ms |
203428 KB |
n=200000 |
96 |
Correct |
915 ms |
203484 KB |
n=200000 |
97 |
Correct |
1144 ms |
207728 KB |
n=200000 |
98 |
Correct |
930 ms |
203416 KB |
n=200000 |
99 |
Correct |
1051 ms |
203848 KB |
n=200000 |
100 |
Correct |
904 ms |
203704 KB |
n=200000 |
101 |
Correct |
706 ms |
212392 KB |
n=200000 |
102 |
Correct |
679 ms |
204912 KB |
n=200000 |
103 |
Correct |
687 ms |
204896 KB |
n=200000 |
104 |
Correct |
734 ms |
204924 KB |
n=200000 |
105 |
Correct |
706 ms |
205368 KB |
n=200000 |
106 |
Correct |
719 ms |
205356 KB |
n=200000 |
107 |
Correct |
720 ms |
205292 KB |
n=200000 |
108 |
Correct |
1050 ms |
203800 KB |
n=200000 |
109 |
Correct |
1014 ms |
203748 KB |
n=200000 |
110 |
Correct |
986 ms |
203792 KB |
n=200000 |
111 |
Correct |
921 ms |
203040 KB |
n=200000 |
112 |
Correct |
742 ms |
211652 KB |
n=200000 |
113 |
Correct |
1161 ms |
207588 KB |
n=200000 |
114 |
Correct |
920 ms |
203128 KB |
n=200000 |
115 |
Correct |
1373 ms |
205676 KB |
n=200000 |
116 |
Correct |
930 ms |
203696 KB |
n=200000 |
117 |
Correct |
751 ms |
211952 KB |
n=200000 |
118 |
Correct |
1232 ms |
206616 KB |
n=200000 |
119 |
Correct |
918 ms |
203760 KB |
n=200000 |
120 |
Correct |
695 ms |
211308 KB |
n=200000 |
121 |
Correct |
675 ms |
211392 KB |
n=200000 |
122 |
Correct |
679 ms |
211792 KB |
n=200000 |
123 |
Correct |
765 ms |
205092 KB |
n=200000 |
124 |
Correct |
249 ms |
137292 KB |
n=25264 |