//UNSTOPPABLE
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define int long long
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define pii pair<int,int>
#define tpii pair <pair <int,int> , int>
#define bruh cout << "NO\n"
using namespace std;
using namespace __gnu_pbds;
const int N = 3e5 + 5;
int mod = 1e9 + 7;
const int INF = 1e18;
int n,m,q,tin[N],tout[N],up[21][N],timer,a[N];
vector <int> g[N];
set <int> st[N],st1[N];
void dfs(int v , int p = 0){
tin[v] = ++ timer;
up[0][v] = p;
for(int i = 1 ; i <= 20 ; i++){
up[i][v] = up[i - 1][up[i - 1][v]];
}
for(auto to : g[v]){
if(to == p) continue;
dfs(to , v);
}
tout[v] = timer;
}
bool upper(int a , int b){
return tin[a] <= tin[b] && tout[b] <= tout[a];
}
int lca(int a , int b){
if(upper(a , b)) return a;
if(upper(b , a)) return b;
for(int i = 20 ; i >= 0 ; i--){
if(!up[i][a]) continue;
if(!upper(up[i][a] , b)){
a = up[i][a];
}
}
return up[0][a];
}
void Goldik(){
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);
}
dfs(1);
for(int i = 1 ; i <= m ; i++){
cin >> a[i];
st1[a[i]].insert(i);
}
for(int i = 1 ; i < m ; i++){
st[lca(a[i] , a[i + 1])].insert(i);
}
for(int i = 1 ; i <= q ; i++){
int tp;
cin >> tp;
if(tp == 1){
int pos , x;
cin >> pos >> x;
st1[a[pos]].erase(pos);
if(pos < m){
st[lca(a[pos] , a[pos + 1])].erase(pos);
}
if(pos > 1){
st[lca(a[pos - 1] , a[pos])].erase(pos - 1);
}
a[pos] = x;
st1[a[pos]].insert(pos);
if(pos < m){
st[lca(a[pos] , a[pos + 1])].insert(pos);
}
if(pos > 1){
st[lca(a[pos - 1] , a[pos])].insert(pos - 1);
}
}
else{
int l,r,v;
cin >> l >> r >> v;
if(st1[v].size()){
auto it = st1[v].lower_bound(l);
if(it != st1[v].end() && (*it) >= l && (*it) <= r){
cout << (*it) << ' ' << (*it) << '\n';
continue;
}
}
if(st[v].size()){
auto it = st[v].lower_bound(l);
if(it != st[v].end() && (*it) >= l && (*it) < r){
cout << (*it) << ' ' << (*it) + 1 << '\n';
continue;
}
}
cout << "-1 -1\n";
}
}
}
//rewai mnogo zadach vozmozhno odna iz nih gde to popadetsya
//returning winter prime?
//chem prowe tem luchshe
signed main(/*AZ AZDAN UZDIKSIZ*/){
//freopen("txt.in","r",stdin);
//freopen("txt.out","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
srand(time(0));
int TT = 1;
// cin >> TT;
for(int i = 1 ; i <= TT ; i++){
//cout << "Case " << i << ": ";
Goldik();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
82520 KB |
n=5 |
2 |
Correct |
11 ms |
82512 KB |
n=100 |
3 |
Correct |
12 ms |
82512 KB |
n=100 |
4 |
Correct |
11 ms |
82512 KB |
n=100 |
5 |
Correct |
12 ms |
82640 KB |
n=100 |
6 |
Correct |
11 ms |
82512 KB |
n=100 |
7 |
Correct |
11 ms |
82524 KB |
n=100 |
8 |
Correct |
12 ms |
82520 KB |
n=100 |
9 |
Correct |
12 ms |
82528 KB |
n=100 |
10 |
Correct |
12 ms |
82524 KB |
n=100 |
11 |
Correct |
12 ms |
82524 KB |
n=100 |
12 |
Correct |
11 ms |
82524 KB |
n=100 |
13 |
Correct |
12 ms |
82528 KB |
n=100 |
14 |
Correct |
11 ms |
82684 KB |
n=100 |
15 |
Correct |
11 ms |
82524 KB |
n=100 |
16 |
Correct |
12 ms |
82656 KB |
n=100 |
17 |
Correct |
12 ms |
82524 KB |
n=100 |
18 |
Correct |
12 ms |
82708 KB |
n=100 |
19 |
Correct |
12 ms |
82524 KB |
n=100 |
20 |
Correct |
15 ms |
82512 KB |
n=100 |
21 |
Correct |
11 ms |
82512 KB |
n=100 |
22 |
Correct |
11 ms |
82512 KB |
n=100 |
23 |
Correct |
11 ms |
82512 KB |
n=100 |
24 |
Correct |
11 ms |
82512 KB |
n=100 |
25 |
Correct |
12 ms |
82512 KB |
n=100 |
26 |
Correct |
13 ms |
82512 KB |
n=12 |
27 |
Correct |
11 ms |
82512 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
82520 KB |
n=5 |
2 |
Correct |
11 ms |
82512 KB |
n=100 |
3 |
Correct |
12 ms |
82512 KB |
n=100 |
4 |
Correct |
11 ms |
82512 KB |
n=100 |
5 |
Correct |
12 ms |
82640 KB |
n=100 |
6 |
Correct |
11 ms |
82512 KB |
n=100 |
7 |
Correct |
11 ms |
82524 KB |
n=100 |
8 |
Correct |
12 ms |
82520 KB |
n=100 |
9 |
Correct |
12 ms |
82528 KB |
n=100 |
10 |
Correct |
12 ms |
82524 KB |
n=100 |
11 |
Correct |
12 ms |
82524 KB |
n=100 |
12 |
Correct |
11 ms |
82524 KB |
n=100 |
13 |
Correct |
12 ms |
82528 KB |
n=100 |
14 |
Correct |
11 ms |
82684 KB |
n=100 |
15 |
Correct |
11 ms |
82524 KB |
n=100 |
16 |
Correct |
12 ms |
82656 KB |
n=100 |
17 |
Correct |
12 ms |
82524 KB |
n=100 |
18 |
Correct |
12 ms |
82708 KB |
n=100 |
19 |
Correct |
12 ms |
82524 KB |
n=100 |
20 |
Correct |
15 ms |
82512 KB |
n=100 |
21 |
Correct |
11 ms |
82512 KB |
n=100 |
22 |
Correct |
11 ms |
82512 KB |
n=100 |
23 |
Correct |
11 ms |
82512 KB |
n=100 |
24 |
Correct |
11 ms |
82512 KB |
n=100 |
25 |
Correct |
12 ms |
82512 KB |
n=100 |
26 |
Correct |
13 ms |
82512 KB |
n=12 |
27 |
Correct |
11 ms |
82512 KB |
n=100 |
28 |
Correct |
13 ms |
82636 KB |
n=500 |
29 |
Correct |
13 ms |
82632 KB |
n=500 |
30 |
Correct |
10 ms |
82768 KB |
n=500 |
31 |
Correct |
10 ms |
82768 KB |
n=500 |
32 |
Correct |
11 ms |
82768 KB |
n=500 |
33 |
Correct |
11 ms |
82768 KB |
n=500 |
34 |
Correct |
11 ms |
82816 KB |
n=500 |
35 |
Correct |
11 ms |
82660 KB |
n=500 |
36 |
Correct |
11 ms |
82768 KB |
n=500 |
37 |
Correct |
10 ms |
82768 KB |
n=500 |
38 |
Correct |
10 ms |
82832 KB |
n=500 |
39 |
Correct |
10 ms |
82784 KB |
n=500 |
40 |
Correct |
11 ms |
82780 KB |
n=500 |
41 |
Correct |
10 ms |
82780 KB |
n=500 |
42 |
Correct |
11 ms |
82780 KB |
n=500 |
43 |
Correct |
11 ms |
82780 KB |
n=500 |
44 |
Correct |
11 ms |
82780 KB |
n=500 |
45 |
Correct |
11 ms |
82780 KB |
n=500 |
46 |
Correct |
10 ms |
82936 KB |
n=500 |
47 |
Correct |
10 ms |
82780 KB |
n=500 |
48 |
Correct |
10 ms |
82776 KB |
n=500 |
49 |
Correct |
11 ms |
82768 KB |
n=500 |
50 |
Correct |
11 ms |
82784 KB |
n=500 |
51 |
Correct |
11 ms |
82936 KB |
n=500 |
52 |
Correct |
10 ms |
82768 KB |
n=500 |
53 |
Correct |
11 ms |
82768 KB |
n=500 |
54 |
Correct |
11 ms |
82936 KB |
n=500 |
55 |
Correct |
12 ms |
82768 KB |
n=278 |
56 |
Correct |
12 ms |
82780 KB |
n=500 |
57 |
Correct |
12 ms |
82780 KB |
n=500 |
58 |
Correct |
13 ms |
82780 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
82520 KB |
n=5 |
2 |
Correct |
11 ms |
82512 KB |
n=100 |
3 |
Correct |
12 ms |
82512 KB |
n=100 |
4 |
Correct |
11 ms |
82512 KB |
n=100 |
5 |
Correct |
12 ms |
82640 KB |
n=100 |
6 |
Correct |
11 ms |
82512 KB |
n=100 |
7 |
Correct |
11 ms |
82524 KB |
n=100 |
8 |
Correct |
12 ms |
82520 KB |
n=100 |
9 |
Correct |
12 ms |
82528 KB |
n=100 |
10 |
Correct |
12 ms |
82524 KB |
n=100 |
11 |
Correct |
12 ms |
82524 KB |
n=100 |
12 |
Correct |
11 ms |
82524 KB |
n=100 |
13 |
Correct |
12 ms |
82528 KB |
n=100 |
14 |
Correct |
11 ms |
82684 KB |
n=100 |
15 |
Correct |
11 ms |
82524 KB |
n=100 |
16 |
Correct |
12 ms |
82656 KB |
n=100 |
17 |
Correct |
12 ms |
82524 KB |
n=100 |
18 |
Correct |
12 ms |
82708 KB |
n=100 |
19 |
Correct |
12 ms |
82524 KB |
n=100 |
20 |
Correct |
15 ms |
82512 KB |
n=100 |
21 |
Correct |
11 ms |
82512 KB |
n=100 |
22 |
Correct |
11 ms |
82512 KB |
n=100 |
23 |
Correct |
11 ms |
82512 KB |
n=100 |
24 |
Correct |
11 ms |
82512 KB |
n=100 |
25 |
Correct |
12 ms |
82512 KB |
n=100 |
26 |
Correct |
13 ms |
82512 KB |
n=12 |
27 |
Correct |
11 ms |
82512 KB |
n=100 |
28 |
Correct |
13 ms |
82636 KB |
n=500 |
29 |
Correct |
13 ms |
82632 KB |
n=500 |
30 |
Correct |
10 ms |
82768 KB |
n=500 |
31 |
Correct |
10 ms |
82768 KB |
n=500 |
32 |
Correct |
11 ms |
82768 KB |
n=500 |
33 |
Correct |
11 ms |
82768 KB |
n=500 |
34 |
Correct |
11 ms |
82816 KB |
n=500 |
35 |
Correct |
11 ms |
82660 KB |
n=500 |
36 |
Correct |
11 ms |
82768 KB |
n=500 |
37 |
Correct |
10 ms |
82768 KB |
n=500 |
38 |
Correct |
10 ms |
82832 KB |
n=500 |
39 |
Correct |
10 ms |
82784 KB |
n=500 |
40 |
Correct |
11 ms |
82780 KB |
n=500 |
41 |
Correct |
10 ms |
82780 KB |
n=500 |
42 |
Correct |
11 ms |
82780 KB |
n=500 |
43 |
Correct |
11 ms |
82780 KB |
n=500 |
44 |
Correct |
11 ms |
82780 KB |
n=500 |
45 |
Correct |
11 ms |
82780 KB |
n=500 |
46 |
Correct |
10 ms |
82936 KB |
n=500 |
47 |
Correct |
10 ms |
82780 KB |
n=500 |
48 |
Correct |
10 ms |
82776 KB |
n=500 |
49 |
Correct |
11 ms |
82768 KB |
n=500 |
50 |
Correct |
11 ms |
82784 KB |
n=500 |
51 |
Correct |
11 ms |
82936 KB |
n=500 |
52 |
Correct |
10 ms |
82768 KB |
n=500 |
53 |
Correct |
11 ms |
82768 KB |
n=500 |
54 |
Correct |
11 ms |
82936 KB |
n=500 |
55 |
Correct |
12 ms |
82768 KB |
n=278 |
56 |
Correct |
12 ms |
82780 KB |
n=500 |
57 |
Correct |
12 ms |
82780 KB |
n=500 |
58 |
Correct |
13 ms |
82780 KB |
n=500 |
59 |
Correct |
14 ms |
82912 KB |
n=2000 |
60 |
Correct |
14 ms |
83036 KB |
n=2000 |
61 |
Correct |
15 ms |
83068 KB |
n=2000 |
62 |
Correct |
14 ms |
83044 KB |
n=2000 |
63 |
Correct |
15 ms |
83040 KB |
n=2000 |
64 |
Correct |
15 ms |
83036 KB |
n=2000 |
65 |
Correct |
14 ms |
83036 KB |
n=2000 |
66 |
Correct |
13 ms |
83024 KB |
n=2000 |
67 |
Correct |
15 ms |
83024 KB |
n=2000 |
68 |
Correct |
14 ms |
83024 KB |
n=2000 |
69 |
Correct |
14 ms |
83192 KB |
n=2000 |
70 |
Correct |
14 ms |
83024 KB |
n=2000 |
71 |
Correct |
14 ms |
83024 KB |
n=2000 |
72 |
Correct |
14 ms |
83024 KB |
n=2000 |
73 |
Correct |
13 ms |
83024 KB |
n=2000 |
74 |
Correct |
13 ms |
83024 KB |
n=1844 |
75 |
Correct |
16 ms |
83024 KB |
n=2000 |
76 |
Correct |
14 ms |
83024 KB |
n=2000 |
77 |
Correct |
15 ms |
83024 KB |
n=2000 |
78 |
Correct |
14 ms |
83024 KB |
n=2000 |
79 |
Correct |
14 ms |
83024 KB |
n=2000 |
80 |
Correct |
14 ms |
83024 KB |
n=2000 |
81 |
Correct |
15 ms |
83024 KB |
n=2000 |
82 |
Correct |
14 ms |
83024 KB |
n=2000 |
83 |
Correct |
15 ms |
82896 KB |
n=2000 |
84 |
Correct |
14 ms |
83068 KB |
n=2000 |
85 |
Correct |
15 ms |
83192 KB |
n=2000 |
86 |
Correct |
15 ms |
83024 KB |
n=2000 |
87 |
Correct |
13 ms |
83028 KB |
n=2000 |
88 |
Correct |
13 ms |
83024 KB |
n=2000 |
89 |
Correct |
13 ms |
83024 KB |
n=2000 |
90 |
Correct |
14 ms |
83024 KB |
n=2000 |
91 |
Correct |
13 ms |
83024 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
82520 KB |
n=5 |
2 |
Correct |
11 ms |
82512 KB |
n=100 |
3 |
Correct |
12 ms |
82512 KB |
n=100 |
4 |
Correct |
11 ms |
82512 KB |
n=100 |
5 |
Correct |
12 ms |
82640 KB |
n=100 |
6 |
Correct |
11 ms |
82512 KB |
n=100 |
7 |
Correct |
11 ms |
82524 KB |
n=100 |
8 |
Correct |
12 ms |
82520 KB |
n=100 |
9 |
Correct |
12 ms |
82528 KB |
n=100 |
10 |
Correct |
12 ms |
82524 KB |
n=100 |
11 |
Correct |
12 ms |
82524 KB |
n=100 |
12 |
Correct |
11 ms |
82524 KB |
n=100 |
13 |
Correct |
12 ms |
82528 KB |
n=100 |
14 |
Correct |
11 ms |
82684 KB |
n=100 |
15 |
Correct |
11 ms |
82524 KB |
n=100 |
16 |
Correct |
12 ms |
82656 KB |
n=100 |
17 |
Correct |
12 ms |
82524 KB |
n=100 |
18 |
Correct |
12 ms |
82708 KB |
n=100 |
19 |
Correct |
12 ms |
82524 KB |
n=100 |
20 |
Correct |
15 ms |
82512 KB |
n=100 |
21 |
Correct |
11 ms |
82512 KB |
n=100 |
22 |
Correct |
11 ms |
82512 KB |
n=100 |
23 |
Correct |
11 ms |
82512 KB |
n=100 |
24 |
Correct |
11 ms |
82512 KB |
n=100 |
25 |
Correct |
12 ms |
82512 KB |
n=100 |
26 |
Correct |
13 ms |
82512 KB |
n=12 |
27 |
Correct |
11 ms |
82512 KB |
n=100 |
28 |
Correct |
13 ms |
82636 KB |
n=500 |
29 |
Correct |
13 ms |
82632 KB |
n=500 |
30 |
Correct |
10 ms |
82768 KB |
n=500 |
31 |
Correct |
10 ms |
82768 KB |
n=500 |
32 |
Correct |
11 ms |
82768 KB |
n=500 |
33 |
Correct |
11 ms |
82768 KB |
n=500 |
34 |
Correct |
11 ms |
82816 KB |
n=500 |
35 |
Correct |
11 ms |
82660 KB |
n=500 |
36 |
Correct |
11 ms |
82768 KB |
n=500 |
37 |
Correct |
10 ms |
82768 KB |
n=500 |
38 |
Correct |
10 ms |
82832 KB |
n=500 |
39 |
Correct |
10 ms |
82784 KB |
n=500 |
40 |
Correct |
11 ms |
82780 KB |
n=500 |
41 |
Correct |
10 ms |
82780 KB |
n=500 |
42 |
Correct |
11 ms |
82780 KB |
n=500 |
43 |
Correct |
11 ms |
82780 KB |
n=500 |
44 |
Correct |
11 ms |
82780 KB |
n=500 |
45 |
Correct |
11 ms |
82780 KB |
n=500 |
46 |
Correct |
10 ms |
82936 KB |
n=500 |
47 |
Correct |
10 ms |
82780 KB |
n=500 |
48 |
Correct |
10 ms |
82776 KB |
n=500 |
49 |
Correct |
11 ms |
82768 KB |
n=500 |
50 |
Correct |
11 ms |
82784 KB |
n=500 |
51 |
Correct |
11 ms |
82936 KB |
n=500 |
52 |
Correct |
10 ms |
82768 KB |
n=500 |
53 |
Correct |
11 ms |
82768 KB |
n=500 |
54 |
Correct |
11 ms |
82936 KB |
n=500 |
55 |
Correct |
12 ms |
82768 KB |
n=278 |
56 |
Correct |
12 ms |
82780 KB |
n=500 |
57 |
Correct |
12 ms |
82780 KB |
n=500 |
58 |
Correct |
13 ms |
82780 KB |
n=500 |
59 |
Correct |
14 ms |
82912 KB |
n=2000 |
60 |
Correct |
14 ms |
83036 KB |
n=2000 |
61 |
Correct |
15 ms |
83068 KB |
n=2000 |
62 |
Correct |
14 ms |
83044 KB |
n=2000 |
63 |
Correct |
15 ms |
83040 KB |
n=2000 |
64 |
Correct |
15 ms |
83036 KB |
n=2000 |
65 |
Correct |
14 ms |
83036 KB |
n=2000 |
66 |
Correct |
13 ms |
83024 KB |
n=2000 |
67 |
Correct |
15 ms |
83024 KB |
n=2000 |
68 |
Correct |
14 ms |
83024 KB |
n=2000 |
69 |
Correct |
14 ms |
83192 KB |
n=2000 |
70 |
Correct |
14 ms |
83024 KB |
n=2000 |
71 |
Correct |
14 ms |
83024 KB |
n=2000 |
72 |
Correct |
14 ms |
83024 KB |
n=2000 |
73 |
Correct |
13 ms |
83024 KB |
n=2000 |
74 |
Correct |
13 ms |
83024 KB |
n=1844 |
75 |
Correct |
16 ms |
83024 KB |
n=2000 |
76 |
Correct |
14 ms |
83024 KB |
n=2000 |
77 |
Correct |
15 ms |
83024 KB |
n=2000 |
78 |
Correct |
14 ms |
83024 KB |
n=2000 |
79 |
Correct |
14 ms |
83024 KB |
n=2000 |
80 |
Correct |
14 ms |
83024 KB |
n=2000 |
81 |
Correct |
15 ms |
83024 KB |
n=2000 |
82 |
Correct |
14 ms |
83024 KB |
n=2000 |
83 |
Correct |
15 ms |
82896 KB |
n=2000 |
84 |
Correct |
14 ms |
83068 KB |
n=2000 |
85 |
Correct |
15 ms |
83192 KB |
n=2000 |
86 |
Correct |
15 ms |
83024 KB |
n=2000 |
87 |
Correct |
13 ms |
83028 KB |
n=2000 |
88 |
Correct |
13 ms |
83024 KB |
n=2000 |
89 |
Correct |
13 ms |
83024 KB |
n=2000 |
90 |
Correct |
14 ms |
83024 KB |
n=2000 |
91 |
Correct |
13 ms |
83024 KB |
n=2000 |
92 |
Correct |
557 ms |
125016 KB |
n=200000 |
93 |
Correct |
706 ms |
129872 KB |
n=200000 |
94 |
Correct |
434 ms |
132936 KB |
n=200000 |
95 |
Correct |
507 ms |
125428 KB |
n=200000 |
96 |
Correct |
492 ms |
125732 KB |
n=200000 |
97 |
Correct |
730 ms |
129096 KB |
n=200000 |
98 |
Correct |
503 ms |
125832 KB |
n=200000 |
99 |
Correct |
489 ms |
125216 KB |
n=200000 |
100 |
Correct |
458 ms |
124988 KB |
n=200000 |
101 |
Correct |
294 ms |
133704 KB |
n=200000 |
102 |
Correct |
277 ms |
126280 KB |
n=200000 |
103 |
Correct |
270 ms |
126280 KB |
n=200000 |
104 |
Correct |
272 ms |
126236 KB |
n=200000 |
105 |
Correct |
284 ms |
126712 KB |
n=200000 |
106 |
Correct |
274 ms |
126528 KB |
n=200000 |
107 |
Correct |
286 ms |
126536 KB |
n=200000 |
108 |
Correct |
559 ms |
125080 KB |
n=200000 |
109 |
Correct |
549 ms |
125084 KB |
n=200000 |
110 |
Correct |
575 ms |
125004 KB |
n=200000 |
111 |
Correct |
534 ms |
124856 KB |
n=200000 |
112 |
Correct |
487 ms |
133036 KB |
n=200000 |
113 |
Correct |
690 ms |
129048 KB |
n=200000 |
114 |
Correct |
474 ms |
125240 KB |
n=200000 |
115 |
Correct |
914 ms |
127048 KB |
n=200000 |
116 |
Correct |
527 ms |
126008 KB |
n=200000 |
117 |
Correct |
398 ms |
133296 KB |
n=200000 |
118 |
Correct |
788 ms |
128072 KB |
n=200000 |
119 |
Correct |
523 ms |
125632 KB |
n=200000 |
120 |
Correct |
347 ms |
132680 KB |
n=200000 |
121 |
Correct |
330 ms |
132680 KB |
n=200000 |
122 |
Correct |
368 ms |
133100 KB |
n=200000 |
123 |
Correct |
289 ms |
126308 KB |
n=200000 |
124 |
Correct |
98 ms |
101448 KB |
n=25264 |