#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define ll long long
const int nmax = 2e5 + 100;
const ll oo = 1e18, base = 311;
const int lg = 19, M =2e2 + 5;
const ll mod = 1e9 + 7;
#define pii pair<ll, int>
#define fi first
#define se second
#define debug(a, n) for(int i = 1; i <= n; ++i) cout << a[i] << ' ';
using namespace std;
int n, m, q, a[nmax], h[nmax], up[nmax][lg + 1];
set<int> mt[nmax][2];
vector<int> adj[nmax];
void dfs(int u, int p){
for(auto v : adj[u]){
if(v == p) continue;
h[v] = h[u] + 1;
up[v][0] = u;
for(int j = 1; j <= lg; ++j) up[v][j] = up[up[v][j - 1]][j - 1];
dfs(v, u);
}
}
int lca(int u, int v){
if(h[u] != h[v]){
if(h[u] < h[v]) swap(u, v);
int k = h[u] - h[v];
for(int j = 0; j <= __lg(k); ++j){
if(k >> j & 1){
u = up[u][j];
}
}
}
if(u == v) return u;
int k = h[u];
for(int j = __lg(k); j >= 0; --j){
if(up[u][j] != up[v][j]){
u = up[u][j];
v = up[v][j];
}
}
return up[u][0];
}
void update(int i, int val){
int x = a[i];
mt[x][0].erase(i);
mt[val][0].insert(i);
if(i > 1){
x = lca(a[i], a[i - 1]);
mt[x][1].erase(i);
x = lca(val, a[i - 1]);
mt[x][1].insert(i);
}
if(i < n){
x = lca(a[i + 1], a[i]);
mt[x][1].erase(i + 1);
x = lca(val, a[i + 1]);
mt[x][1].insert(i + 1);
}
a[i] = val;
}
pii get(int l, int r, int v){
if(mt[v][0].size()){
auto x = mt[v][0].lower_bound(l);
auto y = *x;
if(x != mt[v][0].end() && y <= r) return {y, y};
}
if(mt[v][1].size()){
auto x = mt[v][1].upper_bound(l);
auto y = *x;
if(x != mt[v][1].end() && y <= r) return {y - 1, y};
}
// cout << y << ' ';
return {-1, -1};
}
main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
// freopen("code.inp", "r", stdin);
// freopen("code.out", "w", stdout);
cin >> n >> m >> q;
for(int i = 1, u, v; i < n; ++i){
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(1, -1);
for(int i = 1; i <= m; ++i){
cin >> a[i];
mt[a[i]][0].insert(i);
if(i > 1) mt[lca(a[i], a[i - 1])][1].insert(i);
}
// cout << *mt[1][1].lower_bound(1);
int t, u, x, l, r;
while(q--){
cin >> t;
if(t == 1){
cin >> u >> x;
update(u, x);
}
else{
cin >> l >> r >> x;
pii tmp = get(l, r, x);
cout << tmp.fi << ' ' << tmp.se << "\n";
}
}
}
/*
5 4 4
1 2
3 1
3 4
5 3
4 5 2 3
2 1 3 1
1 3 5
2 3 4 5
2 1 3 1
*/
Compilation message
treearray.cpp:84:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
84 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
25180 KB |
n=5 |
2 |
Correct |
7 ms |
25180 KB |
n=100 |
3 |
Correct |
8 ms |
25180 KB |
n=100 |
4 |
Correct |
7 ms |
25176 KB |
n=100 |
5 |
Correct |
7 ms |
25180 KB |
n=100 |
6 |
Correct |
7 ms |
25176 KB |
n=100 |
7 |
Correct |
8 ms |
25048 KB |
n=100 |
8 |
Correct |
8 ms |
25180 KB |
n=100 |
9 |
Correct |
7 ms |
25180 KB |
n=100 |
10 |
Correct |
7 ms |
25180 KB |
n=100 |
11 |
Correct |
7 ms |
25180 KB |
n=100 |
12 |
Correct |
8 ms |
25176 KB |
n=100 |
13 |
Correct |
7 ms |
25176 KB |
n=100 |
14 |
Correct |
7 ms |
25180 KB |
n=100 |
15 |
Correct |
8 ms |
25180 KB |
n=100 |
16 |
Correct |
7 ms |
25176 KB |
n=100 |
17 |
Correct |
7 ms |
25176 KB |
n=100 |
18 |
Correct |
8 ms |
25436 KB |
n=100 |
19 |
Correct |
7 ms |
25180 KB |
n=100 |
20 |
Correct |
7 ms |
25176 KB |
n=100 |
21 |
Correct |
7 ms |
25180 KB |
n=100 |
22 |
Correct |
7 ms |
25180 KB |
n=100 |
23 |
Correct |
8 ms |
25180 KB |
n=100 |
24 |
Correct |
7 ms |
25176 KB |
n=100 |
25 |
Correct |
7 ms |
25180 KB |
n=100 |
26 |
Correct |
7 ms |
25180 KB |
n=12 |
27 |
Correct |
7 ms |
25436 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
25180 KB |
n=5 |
2 |
Correct |
7 ms |
25180 KB |
n=100 |
3 |
Correct |
8 ms |
25180 KB |
n=100 |
4 |
Correct |
7 ms |
25176 KB |
n=100 |
5 |
Correct |
7 ms |
25180 KB |
n=100 |
6 |
Correct |
7 ms |
25176 KB |
n=100 |
7 |
Correct |
8 ms |
25048 KB |
n=100 |
8 |
Correct |
8 ms |
25180 KB |
n=100 |
9 |
Correct |
7 ms |
25180 KB |
n=100 |
10 |
Correct |
7 ms |
25180 KB |
n=100 |
11 |
Correct |
7 ms |
25180 KB |
n=100 |
12 |
Correct |
8 ms |
25176 KB |
n=100 |
13 |
Correct |
7 ms |
25176 KB |
n=100 |
14 |
Correct |
7 ms |
25180 KB |
n=100 |
15 |
Correct |
8 ms |
25180 KB |
n=100 |
16 |
Correct |
7 ms |
25176 KB |
n=100 |
17 |
Correct |
7 ms |
25176 KB |
n=100 |
18 |
Correct |
8 ms |
25436 KB |
n=100 |
19 |
Correct |
7 ms |
25180 KB |
n=100 |
20 |
Correct |
7 ms |
25176 KB |
n=100 |
21 |
Correct |
7 ms |
25180 KB |
n=100 |
22 |
Correct |
7 ms |
25180 KB |
n=100 |
23 |
Correct |
8 ms |
25180 KB |
n=100 |
24 |
Correct |
7 ms |
25176 KB |
n=100 |
25 |
Correct |
7 ms |
25180 KB |
n=100 |
26 |
Correct |
7 ms |
25180 KB |
n=12 |
27 |
Correct |
7 ms |
25436 KB |
n=100 |
28 |
Correct |
8 ms |
25180 KB |
n=500 |
29 |
Correct |
8 ms |
25432 KB |
n=500 |
30 |
Correct |
8 ms |
25180 KB |
n=500 |
31 |
Correct |
7 ms |
25180 KB |
n=500 |
32 |
Correct |
7 ms |
25180 KB |
n=500 |
33 |
Correct |
8 ms |
25180 KB |
n=500 |
34 |
Correct |
9 ms |
25432 KB |
n=500 |
35 |
Correct |
7 ms |
25180 KB |
n=500 |
36 |
Correct |
9 ms |
25180 KB |
n=500 |
37 |
Correct |
8 ms |
25176 KB |
n=500 |
38 |
Correct |
7 ms |
25176 KB |
n=500 |
39 |
Correct |
7 ms |
25180 KB |
n=500 |
40 |
Correct |
8 ms |
25176 KB |
n=500 |
41 |
Correct |
8 ms |
25332 KB |
n=500 |
42 |
Correct |
8 ms |
25180 KB |
n=500 |
43 |
Correct |
7 ms |
25180 KB |
n=500 |
44 |
Correct |
8 ms |
25180 KB |
n=500 |
45 |
Correct |
8 ms |
25180 KB |
n=500 |
46 |
Correct |
8 ms |
25180 KB |
n=500 |
47 |
Correct |
7 ms |
25180 KB |
n=500 |
48 |
Correct |
8 ms |
25180 KB |
n=500 |
49 |
Correct |
8 ms |
25364 KB |
n=500 |
50 |
Correct |
7 ms |
25176 KB |
n=500 |
51 |
Correct |
8 ms |
25176 KB |
n=500 |
52 |
Correct |
8 ms |
25180 KB |
n=500 |
53 |
Correct |
8 ms |
25176 KB |
n=500 |
54 |
Correct |
7 ms |
25180 KB |
n=500 |
55 |
Correct |
7 ms |
25180 KB |
n=278 |
56 |
Correct |
9 ms |
25180 KB |
n=500 |
57 |
Correct |
7 ms |
25176 KB |
n=500 |
58 |
Correct |
8 ms |
25364 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
25180 KB |
n=5 |
2 |
Correct |
7 ms |
25180 KB |
n=100 |
3 |
Correct |
8 ms |
25180 KB |
n=100 |
4 |
Correct |
7 ms |
25176 KB |
n=100 |
5 |
Correct |
7 ms |
25180 KB |
n=100 |
6 |
Correct |
7 ms |
25176 KB |
n=100 |
7 |
Correct |
8 ms |
25048 KB |
n=100 |
8 |
Correct |
8 ms |
25180 KB |
n=100 |
9 |
Correct |
7 ms |
25180 KB |
n=100 |
10 |
Correct |
7 ms |
25180 KB |
n=100 |
11 |
Correct |
7 ms |
25180 KB |
n=100 |
12 |
Correct |
8 ms |
25176 KB |
n=100 |
13 |
Correct |
7 ms |
25176 KB |
n=100 |
14 |
Correct |
7 ms |
25180 KB |
n=100 |
15 |
Correct |
8 ms |
25180 KB |
n=100 |
16 |
Correct |
7 ms |
25176 KB |
n=100 |
17 |
Correct |
7 ms |
25176 KB |
n=100 |
18 |
Correct |
8 ms |
25436 KB |
n=100 |
19 |
Correct |
7 ms |
25180 KB |
n=100 |
20 |
Correct |
7 ms |
25176 KB |
n=100 |
21 |
Correct |
7 ms |
25180 KB |
n=100 |
22 |
Correct |
7 ms |
25180 KB |
n=100 |
23 |
Correct |
8 ms |
25180 KB |
n=100 |
24 |
Correct |
7 ms |
25176 KB |
n=100 |
25 |
Correct |
7 ms |
25180 KB |
n=100 |
26 |
Correct |
7 ms |
25180 KB |
n=12 |
27 |
Correct |
7 ms |
25436 KB |
n=100 |
28 |
Correct |
8 ms |
25180 KB |
n=500 |
29 |
Correct |
8 ms |
25432 KB |
n=500 |
30 |
Correct |
8 ms |
25180 KB |
n=500 |
31 |
Correct |
7 ms |
25180 KB |
n=500 |
32 |
Correct |
7 ms |
25180 KB |
n=500 |
33 |
Correct |
8 ms |
25180 KB |
n=500 |
34 |
Correct |
9 ms |
25432 KB |
n=500 |
35 |
Correct |
7 ms |
25180 KB |
n=500 |
36 |
Correct |
9 ms |
25180 KB |
n=500 |
37 |
Correct |
8 ms |
25176 KB |
n=500 |
38 |
Correct |
7 ms |
25176 KB |
n=500 |
39 |
Correct |
7 ms |
25180 KB |
n=500 |
40 |
Correct |
8 ms |
25176 KB |
n=500 |
41 |
Correct |
8 ms |
25332 KB |
n=500 |
42 |
Correct |
8 ms |
25180 KB |
n=500 |
43 |
Correct |
7 ms |
25180 KB |
n=500 |
44 |
Correct |
8 ms |
25180 KB |
n=500 |
45 |
Correct |
8 ms |
25180 KB |
n=500 |
46 |
Correct |
8 ms |
25180 KB |
n=500 |
47 |
Correct |
7 ms |
25180 KB |
n=500 |
48 |
Correct |
8 ms |
25180 KB |
n=500 |
49 |
Correct |
8 ms |
25364 KB |
n=500 |
50 |
Correct |
7 ms |
25176 KB |
n=500 |
51 |
Correct |
8 ms |
25176 KB |
n=500 |
52 |
Correct |
8 ms |
25180 KB |
n=500 |
53 |
Correct |
8 ms |
25176 KB |
n=500 |
54 |
Correct |
7 ms |
25180 KB |
n=500 |
55 |
Correct |
7 ms |
25180 KB |
n=278 |
56 |
Correct |
9 ms |
25180 KB |
n=500 |
57 |
Correct |
7 ms |
25176 KB |
n=500 |
58 |
Correct |
8 ms |
25364 KB |
n=500 |
59 |
Correct |
9 ms |
25436 KB |
n=2000 |
60 |
Correct |
9 ms |
25432 KB |
n=2000 |
61 |
Correct |
9 ms |
25432 KB |
n=2000 |
62 |
Correct |
11 ms |
25620 KB |
n=2000 |
63 |
Correct |
10 ms |
25432 KB |
n=2000 |
64 |
Correct |
11 ms |
25436 KB |
n=2000 |
65 |
Correct |
10 ms |
25436 KB |
n=2000 |
66 |
Correct |
10 ms |
25436 KB |
n=2000 |
67 |
Correct |
10 ms |
25432 KB |
n=2000 |
68 |
Correct |
10 ms |
25432 KB |
n=2000 |
69 |
Correct |
9 ms |
25432 KB |
n=2000 |
70 |
Correct |
9 ms |
25436 KB |
n=2000 |
71 |
Correct |
9 ms |
25432 KB |
n=2000 |
72 |
Correct |
9 ms |
25436 KB |
n=2000 |
73 |
Correct |
9 ms |
25432 KB |
n=2000 |
74 |
Correct |
9 ms |
25432 KB |
n=1844 |
75 |
Correct |
9 ms |
25436 KB |
n=2000 |
76 |
Correct |
10 ms |
25432 KB |
n=2000 |
77 |
Correct |
10 ms |
25436 KB |
n=2000 |
78 |
Correct |
9 ms |
25436 KB |
n=2000 |
79 |
Correct |
11 ms |
25432 KB |
n=2000 |
80 |
Correct |
10 ms |
25436 KB |
n=2000 |
81 |
Correct |
10 ms |
25436 KB |
n=2000 |
82 |
Correct |
9 ms |
25436 KB |
n=2000 |
83 |
Correct |
9 ms |
25640 KB |
n=2000 |
84 |
Correct |
10 ms |
25436 KB |
n=2000 |
85 |
Correct |
11 ms |
25688 KB |
n=2000 |
86 |
Correct |
10 ms |
25432 KB |
n=2000 |
87 |
Correct |
10 ms |
25436 KB |
n=2000 |
88 |
Correct |
10 ms |
25436 KB |
n=2000 |
89 |
Correct |
9 ms |
25552 KB |
n=2000 |
90 |
Correct |
10 ms |
25432 KB |
n=2000 |
91 |
Correct |
8 ms |
25436 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
25180 KB |
n=5 |
2 |
Correct |
7 ms |
25180 KB |
n=100 |
3 |
Correct |
8 ms |
25180 KB |
n=100 |
4 |
Correct |
7 ms |
25176 KB |
n=100 |
5 |
Correct |
7 ms |
25180 KB |
n=100 |
6 |
Correct |
7 ms |
25176 KB |
n=100 |
7 |
Correct |
8 ms |
25048 KB |
n=100 |
8 |
Correct |
8 ms |
25180 KB |
n=100 |
9 |
Correct |
7 ms |
25180 KB |
n=100 |
10 |
Correct |
7 ms |
25180 KB |
n=100 |
11 |
Correct |
7 ms |
25180 KB |
n=100 |
12 |
Correct |
8 ms |
25176 KB |
n=100 |
13 |
Correct |
7 ms |
25176 KB |
n=100 |
14 |
Correct |
7 ms |
25180 KB |
n=100 |
15 |
Correct |
8 ms |
25180 KB |
n=100 |
16 |
Correct |
7 ms |
25176 KB |
n=100 |
17 |
Correct |
7 ms |
25176 KB |
n=100 |
18 |
Correct |
8 ms |
25436 KB |
n=100 |
19 |
Correct |
7 ms |
25180 KB |
n=100 |
20 |
Correct |
7 ms |
25176 KB |
n=100 |
21 |
Correct |
7 ms |
25180 KB |
n=100 |
22 |
Correct |
7 ms |
25180 KB |
n=100 |
23 |
Correct |
8 ms |
25180 KB |
n=100 |
24 |
Correct |
7 ms |
25176 KB |
n=100 |
25 |
Correct |
7 ms |
25180 KB |
n=100 |
26 |
Correct |
7 ms |
25180 KB |
n=12 |
27 |
Correct |
7 ms |
25436 KB |
n=100 |
28 |
Correct |
8 ms |
25180 KB |
n=500 |
29 |
Correct |
8 ms |
25432 KB |
n=500 |
30 |
Correct |
8 ms |
25180 KB |
n=500 |
31 |
Correct |
7 ms |
25180 KB |
n=500 |
32 |
Correct |
7 ms |
25180 KB |
n=500 |
33 |
Correct |
8 ms |
25180 KB |
n=500 |
34 |
Correct |
9 ms |
25432 KB |
n=500 |
35 |
Correct |
7 ms |
25180 KB |
n=500 |
36 |
Correct |
9 ms |
25180 KB |
n=500 |
37 |
Correct |
8 ms |
25176 KB |
n=500 |
38 |
Correct |
7 ms |
25176 KB |
n=500 |
39 |
Correct |
7 ms |
25180 KB |
n=500 |
40 |
Correct |
8 ms |
25176 KB |
n=500 |
41 |
Correct |
8 ms |
25332 KB |
n=500 |
42 |
Correct |
8 ms |
25180 KB |
n=500 |
43 |
Correct |
7 ms |
25180 KB |
n=500 |
44 |
Correct |
8 ms |
25180 KB |
n=500 |
45 |
Correct |
8 ms |
25180 KB |
n=500 |
46 |
Correct |
8 ms |
25180 KB |
n=500 |
47 |
Correct |
7 ms |
25180 KB |
n=500 |
48 |
Correct |
8 ms |
25180 KB |
n=500 |
49 |
Correct |
8 ms |
25364 KB |
n=500 |
50 |
Correct |
7 ms |
25176 KB |
n=500 |
51 |
Correct |
8 ms |
25176 KB |
n=500 |
52 |
Correct |
8 ms |
25180 KB |
n=500 |
53 |
Correct |
8 ms |
25176 KB |
n=500 |
54 |
Correct |
7 ms |
25180 KB |
n=500 |
55 |
Correct |
7 ms |
25180 KB |
n=278 |
56 |
Correct |
9 ms |
25180 KB |
n=500 |
57 |
Correct |
7 ms |
25176 KB |
n=500 |
58 |
Correct |
8 ms |
25364 KB |
n=500 |
59 |
Correct |
9 ms |
25436 KB |
n=2000 |
60 |
Correct |
9 ms |
25432 KB |
n=2000 |
61 |
Correct |
9 ms |
25432 KB |
n=2000 |
62 |
Correct |
11 ms |
25620 KB |
n=2000 |
63 |
Correct |
10 ms |
25432 KB |
n=2000 |
64 |
Correct |
11 ms |
25436 KB |
n=2000 |
65 |
Correct |
10 ms |
25436 KB |
n=2000 |
66 |
Correct |
10 ms |
25436 KB |
n=2000 |
67 |
Correct |
10 ms |
25432 KB |
n=2000 |
68 |
Correct |
10 ms |
25432 KB |
n=2000 |
69 |
Correct |
9 ms |
25432 KB |
n=2000 |
70 |
Correct |
9 ms |
25436 KB |
n=2000 |
71 |
Correct |
9 ms |
25432 KB |
n=2000 |
72 |
Correct |
9 ms |
25436 KB |
n=2000 |
73 |
Correct |
9 ms |
25432 KB |
n=2000 |
74 |
Correct |
9 ms |
25432 KB |
n=1844 |
75 |
Correct |
9 ms |
25436 KB |
n=2000 |
76 |
Correct |
10 ms |
25432 KB |
n=2000 |
77 |
Correct |
10 ms |
25436 KB |
n=2000 |
78 |
Correct |
9 ms |
25436 KB |
n=2000 |
79 |
Correct |
11 ms |
25432 KB |
n=2000 |
80 |
Correct |
10 ms |
25436 KB |
n=2000 |
81 |
Correct |
10 ms |
25436 KB |
n=2000 |
82 |
Correct |
9 ms |
25436 KB |
n=2000 |
83 |
Correct |
9 ms |
25640 KB |
n=2000 |
84 |
Correct |
10 ms |
25436 KB |
n=2000 |
85 |
Correct |
11 ms |
25688 KB |
n=2000 |
86 |
Correct |
10 ms |
25432 KB |
n=2000 |
87 |
Correct |
10 ms |
25436 KB |
n=2000 |
88 |
Correct |
10 ms |
25436 KB |
n=2000 |
89 |
Correct |
9 ms |
25552 KB |
n=2000 |
90 |
Correct |
10 ms |
25432 KB |
n=2000 |
91 |
Correct |
8 ms |
25436 KB |
n=2000 |
92 |
Correct |
789 ms |
71688 KB |
n=200000 |
93 |
Correct |
804 ms |
74636 KB |
n=200000 |
94 |
Correct |
895 ms |
76900 KB |
n=200000 |
95 |
Correct |
509 ms |
71596 KB |
n=200000 |
96 |
Correct |
492 ms |
72100 KB |
n=200000 |
97 |
Correct |
869 ms |
74012 KB |
n=200000 |
98 |
Correct |
531 ms |
71616 KB |
n=200000 |
99 |
Correct |
702 ms |
71388 KB |
n=200000 |
100 |
Correct |
597 ms |
71752 KB |
n=200000 |
101 |
Correct |
814 ms |
73952 KB |
n=200000 |
102 |
Correct |
348 ms |
68952 KB |
n=200000 |
103 |
Correct |
352 ms |
68948 KB |
n=200000 |
104 |
Correct |
391 ms |
68940 KB |
n=200000 |
105 |
Correct |
361 ms |
68776 KB |
n=200000 |
106 |
Correct |
398 ms |
68740 KB |
n=200000 |
107 |
Correct |
343 ms |
68632 KB |
n=200000 |
108 |
Correct |
648 ms |
67800 KB |
n=200000 |
109 |
Correct |
670 ms |
67576 KB |
n=200000 |
110 |
Correct |
661 ms |
67912 KB |
n=200000 |
111 |
Correct |
548 ms |
67872 KB |
n=200000 |
112 |
Correct |
779 ms |
72856 KB |
n=200000 |
113 |
Correct |
778 ms |
70024 KB |
n=200000 |
114 |
Correct |
590 ms |
67892 KB |
n=200000 |
115 |
Correct |
988 ms |
68324 KB |
n=200000 |
116 |
Correct |
512 ms |
68184 KB |
n=200000 |
117 |
Correct |
745 ms |
73180 KB |
n=200000 |
118 |
Correct |
851 ms |
68872 KB |
n=200000 |
119 |
Correct |
531 ms |
67800 KB |
n=200000 |
120 |
Correct |
766 ms |
73400 KB |
n=200000 |
121 |
Correct |
722 ms |
73808 KB |
n=200000 |
122 |
Correct |
657 ms |
73808 KB |
n=200000 |
123 |
Correct |
374 ms |
68360 KB |
n=200000 |
124 |
Incorrect |
106 ms |
37968 KB |
Wrong range. |
125 |
Halted |
0 ms |
0 KB |
- |