#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define pii pair<int,int>
#define ret return
#define fr first
#define sc second
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define nosol puts("-1");
#define pb push_back
#define endi puts("");
#define ordered_set tree <int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const int N = 5e5+12,INF = 1e9+7;
int a[N],der[N],cnt,up[20][N],tin[N],tout[N];
vector <int> g[N];
set <pii> s[N];
void dfs(int x,int p){
up[0][x] = p;
tin[x] = cnt++;
for (int i=1;i<20;++i)
up[i][x] = up[i-1][up[i-1][x]];
for (auto to: g[x]){
if (to == p)continue;
dfs(to,x);
}
tout[x] = cnt++;
}
bool is_up(int a,int b){
ret ((tin[a] <= tin[b]) && (tout[a] >= tout[b]));
}
int lca(int a,int b){
if (is_up(a,b))ret a;
if (is_up(b,a))ret b;
for (int i=19;i>=0;--i){
if (!is_up(up[i][a],b)){
a = up[i][a];
}
}
ret up[0][a];
}
main(){
int n,m,i,j,t;
cin>>n>>m>>t;
for (i=1;i<n;++i){
int x,y;
cin>>x>>y;
g[x].pb(y);
g[y].pb(x);
}
dfs(1,1);
for (i=1;i<=m;++i){
cin>>a[i];
if (i > 1){
int lc = lca(a[i],a[i-1]);
s[lc].insert({i-1,i});
}
s[a[i]].insert({i,i});
}
while (t--){
int type;
cin>>type;
if (type == 2){
int l,r,v;
cin>>l>>r>>v;
auto it = s[v].lower_bound({l,0});
if (it == s[v].end() || (it->sc) > r ){
cout <<"-1 -1\n";
}
else {
cout <<it->fr<<" "<<it->sc<<"\n";
}
}
else {
int pos,x;
cin>>pos>>x;
s[a[pos]].erase({pos,pos});
if (pos > 1){
int lc = lca(a[pos],a[pos-1]);
s[lc].erase({pos-1,pos});
}
if (pos < m){
int lc = lca(a[pos],a[pos+1]);
s[lc].erase({pos,pos+1});
}
a[pos] = x;
s[a[pos]].insert({pos,pos});
if (pos > 1){
int lc = lca(a[pos],a[pos-1]);
s[lc].insert({pos-1,pos});
}
if (pos < m){
int lc = lca(a[pos],a[pos+1]);
s[lc].insert({pos,pos+1});
}
}
}
}
Compilation message
treearray.cpp:56:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
56 | main(){
| ^~~~
treearray.cpp: In function 'int main()':
treearray.cpp:57:12: warning: unused variable 'j' [-Wunused-variable]
57 | int n,m,i,j,t;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
35656 KB |
n=5 |
2 |
Correct |
21 ms |
35740 KB |
n=100 |
3 |
Correct |
19 ms |
35708 KB |
n=100 |
4 |
Correct |
19 ms |
35660 KB |
n=100 |
5 |
Correct |
18 ms |
35712 KB |
n=100 |
6 |
Correct |
18 ms |
35744 KB |
n=100 |
7 |
Correct |
23 ms |
35756 KB |
n=100 |
8 |
Correct |
19 ms |
35628 KB |
n=100 |
9 |
Correct |
22 ms |
35700 KB |
n=100 |
10 |
Correct |
18 ms |
35660 KB |
n=100 |
11 |
Correct |
23 ms |
35660 KB |
n=100 |
12 |
Correct |
20 ms |
35660 KB |
n=100 |
13 |
Correct |
18 ms |
35660 KB |
n=100 |
14 |
Correct |
18 ms |
35632 KB |
n=100 |
15 |
Correct |
19 ms |
35688 KB |
n=100 |
16 |
Correct |
17 ms |
35660 KB |
n=100 |
17 |
Correct |
19 ms |
35648 KB |
n=100 |
18 |
Correct |
27 ms |
35660 KB |
n=100 |
19 |
Correct |
20 ms |
35676 KB |
n=100 |
20 |
Correct |
22 ms |
35752 KB |
n=100 |
21 |
Correct |
20 ms |
35660 KB |
n=100 |
22 |
Correct |
23 ms |
35660 KB |
n=100 |
23 |
Correct |
20 ms |
35672 KB |
n=100 |
24 |
Correct |
19 ms |
35636 KB |
n=100 |
25 |
Correct |
19 ms |
35660 KB |
n=100 |
26 |
Correct |
24 ms |
35652 KB |
n=12 |
27 |
Correct |
19 ms |
35660 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
35656 KB |
n=5 |
2 |
Correct |
21 ms |
35740 KB |
n=100 |
3 |
Correct |
19 ms |
35708 KB |
n=100 |
4 |
Correct |
19 ms |
35660 KB |
n=100 |
5 |
Correct |
18 ms |
35712 KB |
n=100 |
6 |
Correct |
18 ms |
35744 KB |
n=100 |
7 |
Correct |
23 ms |
35756 KB |
n=100 |
8 |
Correct |
19 ms |
35628 KB |
n=100 |
9 |
Correct |
22 ms |
35700 KB |
n=100 |
10 |
Correct |
18 ms |
35660 KB |
n=100 |
11 |
Correct |
23 ms |
35660 KB |
n=100 |
12 |
Correct |
20 ms |
35660 KB |
n=100 |
13 |
Correct |
18 ms |
35660 KB |
n=100 |
14 |
Correct |
18 ms |
35632 KB |
n=100 |
15 |
Correct |
19 ms |
35688 KB |
n=100 |
16 |
Correct |
17 ms |
35660 KB |
n=100 |
17 |
Correct |
19 ms |
35648 KB |
n=100 |
18 |
Correct |
27 ms |
35660 KB |
n=100 |
19 |
Correct |
20 ms |
35676 KB |
n=100 |
20 |
Correct |
22 ms |
35752 KB |
n=100 |
21 |
Correct |
20 ms |
35660 KB |
n=100 |
22 |
Correct |
23 ms |
35660 KB |
n=100 |
23 |
Correct |
20 ms |
35672 KB |
n=100 |
24 |
Correct |
19 ms |
35636 KB |
n=100 |
25 |
Correct |
19 ms |
35660 KB |
n=100 |
26 |
Correct |
24 ms |
35652 KB |
n=12 |
27 |
Correct |
19 ms |
35660 KB |
n=100 |
28 |
Correct |
23 ms |
35836 KB |
n=500 |
29 |
Correct |
19 ms |
35804 KB |
n=500 |
30 |
Correct |
20 ms |
35788 KB |
n=500 |
31 |
Correct |
23 ms |
35872 KB |
n=500 |
32 |
Correct |
21 ms |
35868 KB |
n=500 |
33 |
Correct |
23 ms |
35836 KB |
n=500 |
34 |
Correct |
22 ms |
35788 KB |
n=500 |
35 |
Correct |
21 ms |
35848 KB |
n=500 |
36 |
Correct |
20 ms |
35784 KB |
n=500 |
37 |
Correct |
26 ms |
35780 KB |
n=500 |
38 |
Correct |
22 ms |
35788 KB |
n=500 |
39 |
Correct |
19 ms |
35788 KB |
n=500 |
40 |
Correct |
21 ms |
35868 KB |
n=500 |
41 |
Correct |
24 ms |
35780 KB |
n=500 |
42 |
Correct |
22 ms |
35840 KB |
n=500 |
43 |
Correct |
19 ms |
35788 KB |
n=500 |
44 |
Correct |
20 ms |
35804 KB |
n=500 |
45 |
Correct |
18 ms |
35796 KB |
n=500 |
46 |
Correct |
26 ms |
35800 KB |
n=500 |
47 |
Correct |
22 ms |
35816 KB |
n=500 |
48 |
Correct |
25 ms |
35784 KB |
n=500 |
49 |
Correct |
21 ms |
35916 KB |
n=500 |
50 |
Correct |
20 ms |
35900 KB |
n=500 |
51 |
Correct |
23 ms |
35848 KB |
n=500 |
52 |
Correct |
19 ms |
35788 KB |
n=500 |
53 |
Correct |
21 ms |
35788 KB |
n=500 |
54 |
Correct |
24 ms |
35788 KB |
n=500 |
55 |
Correct |
24 ms |
35748 KB |
n=278 |
56 |
Correct |
20 ms |
35796 KB |
n=500 |
57 |
Correct |
19 ms |
35788 KB |
n=500 |
58 |
Correct |
20 ms |
35788 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
35656 KB |
n=5 |
2 |
Correct |
21 ms |
35740 KB |
n=100 |
3 |
Correct |
19 ms |
35708 KB |
n=100 |
4 |
Correct |
19 ms |
35660 KB |
n=100 |
5 |
Correct |
18 ms |
35712 KB |
n=100 |
6 |
Correct |
18 ms |
35744 KB |
n=100 |
7 |
Correct |
23 ms |
35756 KB |
n=100 |
8 |
Correct |
19 ms |
35628 KB |
n=100 |
9 |
Correct |
22 ms |
35700 KB |
n=100 |
10 |
Correct |
18 ms |
35660 KB |
n=100 |
11 |
Correct |
23 ms |
35660 KB |
n=100 |
12 |
Correct |
20 ms |
35660 KB |
n=100 |
13 |
Correct |
18 ms |
35660 KB |
n=100 |
14 |
Correct |
18 ms |
35632 KB |
n=100 |
15 |
Correct |
19 ms |
35688 KB |
n=100 |
16 |
Correct |
17 ms |
35660 KB |
n=100 |
17 |
Correct |
19 ms |
35648 KB |
n=100 |
18 |
Correct |
27 ms |
35660 KB |
n=100 |
19 |
Correct |
20 ms |
35676 KB |
n=100 |
20 |
Correct |
22 ms |
35752 KB |
n=100 |
21 |
Correct |
20 ms |
35660 KB |
n=100 |
22 |
Correct |
23 ms |
35660 KB |
n=100 |
23 |
Correct |
20 ms |
35672 KB |
n=100 |
24 |
Correct |
19 ms |
35636 KB |
n=100 |
25 |
Correct |
19 ms |
35660 KB |
n=100 |
26 |
Correct |
24 ms |
35652 KB |
n=12 |
27 |
Correct |
19 ms |
35660 KB |
n=100 |
28 |
Correct |
23 ms |
35836 KB |
n=500 |
29 |
Correct |
19 ms |
35804 KB |
n=500 |
30 |
Correct |
20 ms |
35788 KB |
n=500 |
31 |
Correct |
23 ms |
35872 KB |
n=500 |
32 |
Correct |
21 ms |
35868 KB |
n=500 |
33 |
Correct |
23 ms |
35836 KB |
n=500 |
34 |
Correct |
22 ms |
35788 KB |
n=500 |
35 |
Correct |
21 ms |
35848 KB |
n=500 |
36 |
Correct |
20 ms |
35784 KB |
n=500 |
37 |
Correct |
26 ms |
35780 KB |
n=500 |
38 |
Correct |
22 ms |
35788 KB |
n=500 |
39 |
Correct |
19 ms |
35788 KB |
n=500 |
40 |
Correct |
21 ms |
35868 KB |
n=500 |
41 |
Correct |
24 ms |
35780 KB |
n=500 |
42 |
Correct |
22 ms |
35840 KB |
n=500 |
43 |
Correct |
19 ms |
35788 KB |
n=500 |
44 |
Correct |
20 ms |
35804 KB |
n=500 |
45 |
Correct |
18 ms |
35796 KB |
n=500 |
46 |
Correct |
26 ms |
35800 KB |
n=500 |
47 |
Correct |
22 ms |
35816 KB |
n=500 |
48 |
Correct |
25 ms |
35784 KB |
n=500 |
49 |
Correct |
21 ms |
35916 KB |
n=500 |
50 |
Correct |
20 ms |
35900 KB |
n=500 |
51 |
Correct |
23 ms |
35848 KB |
n=500 |
52 |
Correct |
19 ms |
35788 KB |
n=500 |
53 |
Correct |
21 ms |
35788 KB |
n=500 |
54 |
Correct |
24 ms |
35788 KB |
n=500 |
55 |
Correct |
24 ms |
35748 KB |
n=278 |
56 |
Correct |
20 ms |
35796 KB |
n=500 |
57 |
Correct |
19 ms |
35788 KB |
n=500 |
58 |
Correct |
20 ms |
35788 KB |
n=500 |
59 |
Correct |
24 ms |
36432 KB |
n=2000 |
60 |
Correct |
24 ms |
36440 KB |
n=2000 |
61 |
Correct |
28 ms |
36436 KB |
n=2000 |
62 |
Correct |
31 ms |
36356 KB |
n=2000 |
63 |
Correct |
28 ms |
36428 KB |
n=2000 |
64 |
Correct |
25 ms |
36396 KB |
n=2000 |
65 |
Correct |
25 ms |
36388 KB |
n=2000 |
66 |
Correct |
23 ms |
36444 KB |
n=2000 |
67 |
Correct |
26 ms |
36428 KB |
n=2000 |
68 |
Correct |
25 ms |
36484 KB |
n=2000 |
69 |
Correct |
30 ms |
36460 KB |
n=2000 |
70 |
Correct |
33 ms |
36380 KB |
n=2000 |
71 |
Correct |
26 ms |
36440 KB |
n=2000 |
72 |
Correct |
25 ms |
36428 KB |
n=2000 |
73 |
Correct |
26 ms |
36400 KB |
n=2000 |
74 |
Correct |
25 ms |
36288 KB |
n=1844 |
75 |
Correct |
26 ms |
36348 KB |
n=2000 |
76 |
Correct |
26 ms |
36392 KB |
n=2000 |
77 |
Correct |
28 ms |
36480 KB |
n=2000 |
78 |
Correct |
25 ms |
36516 KB |
n=2000 |
79 |
Correct |
25 ms |
36436 KB |
n=2000 |
80 |
Correct |
28 ms |
36428 KB |
n=2000 |
81 |
Correct |
27 ms |
36472 KB |
n=2000 |
82 |
Correct |
27 ms |
36428 KB |
n=2000 |
83 |
Correct |
26 ms |
36504 KB |
n=2000 |
84 |
Correct |
29 ms |
36428 KB |
n=2000 |
85 |
Correct |
25 ms |
36428 KB |
n=2000 |
86 |
Correct |
25 ms |
36440 KB |
n=2000 |
87 |
Correct |
25 ms |
36444 KB |
n=2000 |
88 |
Correct |
29 ms |
36448 KB |
n=2000 |
89 |
Correct |
27 ms |
36428 KB |
n=2000 |
90 |
Correct |
22 ms |
36428 KB |
n=2000 |
91 |
Correct |
25 ms |
36420 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
35656 KB |
n=5 |
2 |
Correct |
21 ms |
35740 KB |
n=100 |
3 |
Correct |
19 ms |
35708 KB |
n=100 |
4 |
Correct |
19 ms |
35660 KB |
n=100 |
5 |
Correct |
18 ms |
35712 KB |
n=100 |
6 |
Correct |
18 ms |
35744 KB |
n=100 |
7 |
Correct |
23 ms |
35756 KB |
n=100 |
8 |
Correct |
19 ms |
35628 KB |
n=100 |
9 |
Correct |
22 ms |
35700 KB |
n=100 |
10 |
Correct |
18 ms |
35660 KB |
n=100 |
11 |
Correct |
23 ms |
35660 KB |
n=100 |
12 |
Correct |
20 ms |
35660 KB |
n=100 |
13 |
Correct |
18 ms |
35660 KB |
n=100 |
14 |
Correct |
18 ms |
35632 KB |
n=100 |
15 |
Correct |
19 ms |
35688 KB |
n=100 |
16 |
Correct |
17 ms |
35660 KB |
n=100 |
17 |
Correct |
19 ms |
35648 KB |
n=100 |
18 |
Correct |
27 ms |
35660 KB |
n=100 |
19 |
Correct |
20 ms |
35676 KB |
n=100 |
20 |
Correct |
22 ms |
35752 KB |
n=100 |
21 |
Correct |
20 ms |
35660 KB |
n=100 |
22 |
Correct |
23 ms |
35660 KB |
n=100 |
23 |
Correct |
20 ms |
35672 KB |
n=100 |
24 |
Correct |
19 ms |
35636 KB |
n=100 |
25 |
Correct |
19 ms |
35660 KB |
n=100 |
26 |
Correct |
24 ms |
35652 KB |
n=12 |
27 |
Correct |
19 ms |
35660 KB |
n=100 |
28 |
Correct |
23 ms |
35836 KB |
n=500 |
29 |
Correct |
19 ms |
35804 KB |
n=500 |
30 |
Correct |
20 ms |
35788 KB |
n=500 |
31 |
Correct |
23 ms |
35872 KB |
n=500 |
32 |
Correct |
21 ms |
35868 KB |
n=500 |
33 |
Correct |
23 ms |
35836 KB |
n=500 |
34 |
Correct |
22 ms |
35788 KB |
n=500 |
35 |
Correct |
21 ms |
35848 KB |
n=500 |
36 |
Correct |
20 ms |
35784 KB |
n=500 |
37 |
Correct |
26 ms |
35780 KB |
n=500 |
38 |
Correct |
22 ms |
35788 KB |
n=500 |
39 |
Correct |
19 ms |
35788 KB |
n=500 |
40 |
Correct |
21 ms |
35868 KB |
n=500 |
41 |
Correct |
24 ms |
35780 KB |
n=500 |
42 |
Correct |
22 ms |
35840 KB |
n=500 |
43 |
Correct |
19 ms |
35788 KB |
n=500 |
44 |
Correct |
20 ms |
35804 KB |
n=500 |
45 |
Correct |
18 ms |
35796 KB |
n=500 |
46 |
Correct |
26 ms |
35800 KB |
n=500 |
47 |
Correct |
22 ms |
35816 KB |
n=500 |
48 |
Correct |
25 ms |
35784 KB |
n=500 |
49 |
Correct |
21 ms |
35916 KB |
n=500 |
50 |
Correct |
20 ms |
35900 KB |
n=500 |
51 |
Correct |
23 ms |
35848 KB |
n=500 |
52 |
Correct |
19 ms |
35788 KB |
n=500 |
53 |
Correct |
21 ms |
35788 KB |
n=500 |
54 |
Correct |
24 ms |
35788 KB |
n=500 |
55 |
Correct |
24 ms |
35748 KB |
n=278 |
56 |
Correct |
20 ms |
35796 KB |
n=500 |
57 |
Correct |
19 ms |
35788 KB |
n=500 |
58 |
Correct |
20 ms |
35788 KB |
n=500 |
59 |
Correct |
24 ms |
36432 KB |
n=2000 |
60 |
Correct |
24 ms |
36440 KB |
n=2000 |
61 |
Correct |
28 ms |
36436 KB |
n=2000 |
62 |
Correct |
31 ms |
36356 KB |
n=2000 |
63 |
Correct |
28 ms |
36428 KB |
n=2000 |
64 |
Correct |
25 ms |
36396 KB |
n=2000 |
65 |
Correct |
25 ms |
36388 KB |
n=2000 |
66 |
Correct |
23 ms |
36444 KB |
n=2000 |
67 |
Correct |
26 ms |
36428 KB |
n=2000 |
68 |
Correct |
25 ms |
36484 KB |
n=2000 |
69 |
Correct |
30 ms |
36460 KB |
n=2000 |
70 |
Correct |
33 ms |
36380 KB |
n=2000 |
71 |
Correct |
26 ms |
36440 KB |
n=2000 |
72 |
Correct |
25 ms |
36428 KB |
n=2000 |
73 |
Correct |
26 ms |
36400 KB |
n=2000 |
74 |
Correct |
25 ms |
36288 KB |
n=1844 |
75 |
Correct |
26 ms |
36348 KB |
n=2000 |
76 |
Correct |
26 ms |
36392 KB |
n=2000 |
77 |
Correct |
28 ms |
36480 KB |
n=2000 |
78 |
Correct |
25 ms |
36516 KB |
n=2000 |
79 |
Correct |
25 ms |
36436 KB |
n=2000 |
80 |
Correct |
28 ms |
36428 KB |
n=2000 |
81 |
Correct |
27 ms |
36472 KB |
n=2000 |
82 |
Correct |
27 ms |
36428 KB |
n=2000 |
83 |
Correct |
26 ms |
36504 KB |
n=2000 |
84 |
Correct |
29 ms |
36428 KB |
n=2000 |
85 |
Correct |
25 ms |
36428 KB |
n=2000 |
86 |
Correct |
25 ms |
36440 KB |
n=2000 |
87 |
Correct |
25 ms |
36444 KB |
n=2000 |
88 |
Correct |
29 ms |
36448 KB |
n=2000 |
89 |
Correct |
27 ms |
36428 KB |
n=2000 |
90 |
Correct |
22 ms |
36428 KB |
n=2000 |
91 |
Correct |
25 ms |
36420 KB |
n=2000 |
92 |
Correct |
2087 ms |
112280 KB |
n=200000 |
93 |
Correct |
1619 ms |
117136 KB |
n=200000 |
94 |
Correct |
1164 ms |
120160 KB |
n=200000 |
95 |
Correct |
1969 ms |
111988 KB |
n=200000 |
96 |
Correct |
2019 ms |
111952 KB |
n=200000 |
97 |
Correct |
1667 ms |
116304 KB |
n=200000 |
98 |
Correct |
1958 ms |
111984 KB |
n=200000 |
99 |
Correct |
1969 ms |
112368 KB |
n=200000 |
100 |
Correct |
2009 ms |
112112 KB |
n=200000 |
101 |
Correct |
942 ms |
120996 KB |
n=200000 |
102 |
Correct |
1296 ms |
113480 KB |
n=200000 |
103 |
Correct |
1296 ms |
113520 KB |
n=200000 |
104 |
Correct |
1212 ms |
113452 KB |
n=200000 |
105 |
Correct |
1284 ms |
113868 KB |
n=200000 |
106 |
Correct |
1381 ms |
113860 KB |
n=200000 |
107 |
Correct |
1275 ms |
113864 KB |
n=200000 |
108 |
Correct |
1802 ms |
112320 KB |
n=200000 |
109 |
Correct |
1795 ms |
112416 KB |
n=200000 |
110 |
Correct |
1785 ms |
112608 KB |
n=200000 |
111 |
Correct |
1659 ms |
111680 KB |
n=200000 |
112 |
Correct |
917 ms |
120348 KB |
n=200000 |
113 |
Correct |
1584 ms |
116188 KB |
n=200000 |
114 |
Correct |
1629 ms |
111828 KB |
n=200000 |
115 |
Correct |
2029 ms |
114392 KB |
n=200000 |
116 |
Correct |
1824 ms |
112244 KB |
n=200000 |
117 |
Correct |
898 ms |
120372 KB |
n=200000 |
118 |
Correct |
1786 ms |
115344 KB |
n=200000 |
119 |
Correct |
1833 ms |
112224 KB |
n=200000 |
120 |
Correct |
779 ms |
119932 KB |
n=200000 |
121 |
Correct |
850 ms |
119852 KB |
n=200000 |
122 |
Correct |
783 ms |
120296 KB |
n=200000 |
123 |
Correct |
1270 ms |
113820 KB |
n=200000 |
124 |
Correct |
317 ms |
56104 KB |
n=25264 |