#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 + 5;
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(n); ++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){
auto x = mt[v][0].lower_bound(l);
auto y = *x;
if(x != mt[v][0].end() && y <= r) return {y, y};
x = mt[v][1].upper_bound(l);
y = *x;
// cout << y << ' ';
if(x != mt[v][1].end() && y <= r) return {y - 1, 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:82:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
82 | 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 |
7 ms |
25180 KB |
n=100 |
4 |
Correct |
7 ms |
25176 KB |
n=100 |
5 |
Correct |
9 ms |
25436 KB |
n=100 |
6 |
Correct |
7 ms |
25180 KB |
n=100 |
7 |
Correct |
8 ms |
25180 KB |
n=100 |
8 |
Correct |
8 ms |
25288 KB |
n=100 |
9 |
Correct |
8 ms |
25188 KB |
n=100 |
10 |
Correct |
8 ms |
25180 KB |
n=100 |
11 |
Correct |
8 ms |
25180 KB |
n=100 |
12 |
Correct |
8 ms |
25296 KB |
n=100 |
13 |
Correct |
8 ms |
25180 KB |
n=100 |
14 |
Correct |
7 ms |
25040 KB |
n=100 |
15 |
Correct |
8 ms |
25180 KB |
n=100 |
16 |
Correct |
8 ms |
25180 KB |
n=100 |
17 |
Correct |
7 ms |
25180 KB |
n=100 |
18 |
Correct |
7 ms |
25180 KB |
n=100 |
19 |
Correct |
8 ms |
25176 KB |
n=100 |
20 |
Correct |
7 ms |
25180 KB |
n=100 |
21 |
Correct |
8 ms |
25436 KB |
n=100 |
22 |
Correct |
7 ms |
25176 KB |
n=100 |
23 |
Correct |
8 ms |
25176 KB |
n=100 |
24 |
Correct |
8 ms |
25180 KB |
n=100 |
25 |
Correct |
8 ms |
25180 KB |
n=100 |
26 |
Correct |
8 ms |
25176 KB |
n=12 |
27 |
Correct |
7 ms |
25180 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 |
7 ms |
25180 KB |
n=100 |
4 |
Correct |
7 ms |
25176 KB |
n=100 |
5 |
Correct |
9 ms |
25436 KB |
n=100 |
6 |
Correct |
7 ms |
25180 KB |
n=100 |
7 |
Correct |
8 ms |
25180 KB |
n=100 |
8 |
Correct |
8 ms |
25288 KB |
n=100 |
9 |
Correct |
8 ms |
25188 KB |
n=100 |
10 |
Correct |
8 ms |
25180 KB |
n=100 |
11 |
Correct |
8 ms |
25180 KB |
n=100 |
12 |
Correct |
8 ms |
25296 KB |
n=100 |
13 |
Correct |
8 ms |
25180 KB |
n=100 |
14 |
Correct |
7 ms |
25040 KB |
n=100 |
15 |
Correct |
8 ms |
25180 KB |
n=100 |
16 |
Correct |
8 ms |
25180 KB |
n=100 |
17 |
Correct |
7 ms |
25180 KB |
n=100 |
18 |
Correct |
7 ms |
25180 KB |
n=100 |
19 |
Correct |
8 ms |
25176 KB |
n=100 |
20 |
Correct |
7 ms |
25180 KB |
n=100 |
21 |
Correct |
8 ms |
25436 KB |
n=100 |
22 |
Correct |
7 ms |
25176 KB |
n=100 |
23 |
Correct |
8 ms |
25176 KB |
n=100 |
24 |
Correct |
8 ms |
25180 KB |
n=100 |
25 |
Correct |
8 ms |
25180 KB |
n=100 |
26 |
Correct |
8 ms |
25176 KB |
n=12 |
27 |
Correct |
7 ms |
25180 KB |
n=100 |
28 |
Correct |
8 ms |
25180 KB |
n=500 |
29 |
Correct |
8 ms |
25180 KB |
n=500 |
30 |
Correct |
8 ms |
25272 KB |
n=500 |
31 |
Correct |
7 ms |
25180 KB |
n=500 |
32 |
Correct |
8 ms |
25180 KB |
n=500 |
33 |
Correct |
9 ms |
25176 KB |
n=500 |
34 |
Correct |
9 ms |
25176 KB |
n=500 |
35 |
Correct |
9 ms |
25180 KB |
n=500 |
36 |
Correct |
7 ms |
25176 KB |
n=500 |
37 |
Correct |
7 ms |
25180 KB |
n=500 |
38 |
Correct |
8 ms |
25176 KB |
n=500 |
39 |
Correct |
8 ms |
25180 KB |
n=500 |
40 |
Correct |
8 ms |
25280 KB |
n=500 |
41 |
Correct |
8 ms |
25176 KB |
n=500 |
42 |
Correct |
8 ms |
25180 KB |
n=500 |
43 |
Correct |
8 ms |
25356 KB |
n=500 |
44 |
Correct |
8 ms |
25176 KB |
n=500 |
45 |
Correct |
8 ms |
25180 KB |
n=500 |
46 |
Correct |
9 ms |
25176 KB |
n=500 |
47 |
Correct |
8 ms |
25180 KB |
n=500 |
48 |
Correct |
8 ms |
25180 KB |
n=500 |
49 |
Correct |
7 ms |
25180 KB |
n=500 |
50 |
Correct |
8 ms |
25176 KB |
n=500 |
51 |
Correct |
8 ms |
25432 KB |
n=500 |
52 |
Correct |
9 ms |
25180 KB |
n=500 |
53 |
Correct |
9 ms |
25528 KB |
n=500 |
54 |
Correct |
10 ms |
25180 KB |
n=500 |
55 |
Correct |
8 ms |
25180 KB |
n=278 |
56 |
Correct |
8 ms |
25176 KB |
n=500 |
57 |
Correct |
8 ms |
25380 KB |
n=500 |
58 |
Correct |
7 ms |
25180 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 |
7 ms |
25180 KB |
n=100 |
4 |
Correct |
7 ms |
25176 KB |
n=100 |
5 |
Correct |
9 ms |
25436 KB |
n=100 |
6 |
Correct |
7 ms |
25180 KB |
n=100 |
7 |
Correct |
8 ms |
25180 KB |
n=100 |
8 |
Correct |
8 ms |
25288 KB |
n=100 |
9 |
Correct |
8 ms |
25188 KB |
n=100 |
10 |
Correct |
8 ms |
25180 KB |
n=100 |
11 |
Correct |
8 ms |
25180 KB |
n=100 |
12 |
Correct |
8 ms |
25296 KB |
n=100 |
13 |
Correct |
8 ms |
25180 KB |
n=100 |
14 |
Correct |
7 ms |
25040 KB |
n=100 |
15 |
Correct |
8 ms |
25180 KB |
n=100 |
16 |
Correct |
8 ms |
25180 KB |
n=100 |
17 |
Correct |
7 ms |
25180 KB |
n=100 |
18 |
Correct |
7 ms |
25180 KB |
n=100 |
19 |
Correct |
8 ms |
25176 KB |
n=100 |
20 |
Correct |
7 ms |
25180 KB |
n=100 |
21 |
Correct |
8 ms |
25436 KB |
n=100 |
22 |
Correct |
7 ms |
25176 KB |
n=100 |
23 |
Correct |
8 ms |
25176 KB |
n=100 |
24 |
Correct |
8 ms |
25180 KB |
n=100 |
25 |
Correct |
8 ms |
25180 KB |
n=100 |
26 |
Correct |
8 ms |
25176 KB |
n=12 |
27 |
Correct |
7 ms |
25180 KB |
n=100 |
28 |
Correct |
8 ms |
25180 KB |
n=500 |
29 |
Correct |
8 ms |
25180 KB |
n=500 |
30 |
Correct |
8 ms |
25272 KB |
n=500 |
31 |
Correct |
7 ms |
25180 KB |
n=500 |
32 |
Correct |
8 ms |
25180 KB |
n=500 |
33 |
Correct |
9 ms |
25176 KB |
n=500 |
34 |
Correct |
9 ms |
25176 KB |
n=500 |
35 |
Correct |
9 ms |
25180 KB |
n=500 |
36 |
Correct |
7 ms |
25176 KB |
n=500 |
37 |
Correct |
7 ms |
25180 KB |
n=500 |
38 |
Correct |
8 ms |
25176 KB |
n=500 |
39 |
Correct |
8 ms |
25180 KB |
n=500 |
40 |
Correct |
8 ms |
25280 KB |
n=500 |
41 |
Correct |
8 ms |
25176 KB |
n=500 |
42 |
Correct |
8 ms |
25180 KB |
n=500 |
43 |
Correct |
8 ms |
25356 KB |
n=500 |
44 |
Correct |
8 ms |
25176 KB |
n=500 |
45 |
Correct |
8 ms |
25180 KB |
n=500 |
46 |
Correct |
9 ms |
25176 KB |
n=500 |
47 |
Correct |
8 ms |
25180 KB |
n=500 |
48 |
Correct |
8 ms |
25180 KB |
n=500 |
49 |
Correct |
7 ms |
25180 KB |
n=500 |
50 |
Correct |
8 ms |
25176 KB |
n=500 |
51 |
Correct |
8 ms |
25432 KB |
n=500 |
52 |
Correct |
9 ms |
25180 KB |
n=500 |
53 |
Correct |
9 ms |
25528 KB |
n=500 |
54 |
Correct |
10 ms |
25180 KB |
n=500 |
55 |
Correct |
8 ms |
25180 KB |
n=278 |
56 |
Correct |
8 ms |
25176 KB |
n=500 |
57 |
Correct |
8 ms |
25380 KB |
n=500 |
58 |
Correct |
7 ms |
25180 KB |
n=500 |
59 |
Correct |
10 ms |
25436 KB |
n=2000 |
60 |
Correct |
10 ms |
25688 KB |
n=2000 |
61 |
Correct |
10 ms |
25692 KB |
n=2000 |
62 |
Correct |
9 ms |
25436 KB |
n=2000 |
63 |
Correct |
9 ms |
25436 KB |
n=2000 |
64 |
Correct |
11 ms |
25432 KB |
n=2000 |
65 |
Correct |
9 ms |
25432 KB |
n=2000 |
66 |
Correct |
11 ms |
25688 KB |
n=2000 |
67 |
Correct |
12 ms |
25436 KB |
n=2000 |
68 |
Correct |
10 ms |
25436 KB |
n=2000 |
69 |
Correct |
9 ms |
25436 KB |
n=2000 |
70 |
Correct |
10 ms |
25436 KB |
n=2000 |
71 |
Correct |
10 ms |
25436 KB |
n=2000 |
72 |
Correct |
10 ms |
25788 KB |
n=2000 |
73 |
Correct |
9 ms |
25436 KB |
n=2000 |
74 |
Correct |
11 ms |
25692 KB |
n=1844 |
75 |
Correct |
9 ms |
25436 KB |
n=2000 |
76 |
Correct |
10 ms |
25436 KB |
n=2000 |
77 |
Correct |
11 ms |
25432 KB |
n=2000 |
78 |
Correct |
10 ms |
25596 KB |
n=2000 |
79 |
Correct |
9 ms |
25432 KB |
n=2000 |
80 |
Correct |
10 ms |
25692 KB |
n=2000 |
81 |
Correct |
10 ms |
25436 KB |
n=2000 |
82 |
Correct |
9 ms |
25436 KB |
n=2000 |
83 |
Correct |
10 ms |
25692 KB |
n=2000 |
84 |
Correct |
10 ms |
25436 KB |
n=2000 |
85 |
Correct |
10 ms |
25432 KB |
n=2000 |
86 |
Correct |
9 ms |
25436 KB |
n=2000 |
87 |
Correct |
10 ms |
25436 KB |
n=2000 |
88 |
Correct |
9 ms |
25692 KB |
n=2000 |
89 |
Correct |
10 ms |
25688 KB |
n=2000 |
90 |
Correct |
10 ms |
25692 KB |
n=2000 |
91 |
Correct |
9 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 |
7 ms |
25180 KB |
n=100 |
4 |
Correct |
7 ms |
25176 KB |
n=100 |
5 |
Correct |
9 ms |
25436 KB |
n=100 |
6 |
Correct |
7 ms |
25180 KB |
n=100 |
7 |
Correct |
8 ms |
25180 KB |
n=100 |
8 |
Correct |
8 ms |
25288 KB |
n=100 |
9 |
Correct |
8 ms |
25188 KB |
n=100 |
10 |
Correct |
8 ms |
25180 KB |
n=100 |
11 |
Correct |
8 ms |
25180 KB |
n=100 |
12 |
Correct |
8 ms |
25296 KB |
n=100 |
13 |
Correct |
8 ms |
25180 KB |
n=100 |
14 |
Correct |
7 ms |
25040 KB |
n=100 |
15 |
Correct |
8 ms |
25180 KB |
n=100 |
16 |
Correct |
8 ms |
25180 KB |
n=100 |
17 |
Correct |
7 ms |
25180 KB |
n=100 |
18 |
Correct |
7 ms |
25180 KB |
n=100 |
19 |
Correct |
8 ms |
25176 KB |
n=100 |
20 |
Correct |
7 ms |
25180 KB |
n=100 |
21 |
Correct |
8 ms |
25436 KB |
n=100 |
22 |
Correct |
7 ms |
25176 KB |
n=100 |
23 |
Correct |
8 ms |
25176 KB |
n=100 |
24 |
Correct |
8 ms |
25180 KB |
n=100 |
25 |
Correct |
8 ms |
25180 KB |
n=100 |
26 |
Correct |
8 ms |
25176 KB |
n=12 |
27 |
Correct |
7 ms |
25180 KB |
n=100 |
28 |
Correct |
8 ms |
25180 KB |
n=500 |
29 |
Correct |
8 ms |
25180 KB |
n=500 |
30 |
Correct |
8 ms |
25272 KB |
n=500 |
31 |
Correct |
7 ms |
25180 KB |
n=500 |
32 |
Correct |
8 ms |
25180 KB |
n=500 |
33 |
Correct |
9 ms |
25176 KB |
n=500 |
34 |
Correct |
9 ms |
25176 KB |
n=500 |
35 |
Correct |
9 ms |
25180 KB |
n=500 |
36 |
Correct |
7 ms |
25176 KB |
n=500 |
37 |
Correct |
7 ms |
25180 KB |
n=500 |
38 |
Correct |
8 ms |
25176 KB |
n=500 |
39 |
Correct |
8 ms |
25180 KB |
n=500 |
40 |
Correct |
8 ms |
25280 KB |
n=500 |
41 |
Correct |
8 ms |
25176 KB |
n=500 |
42 |
Correct |
8 ms |
25180 KB |
n=500 |
43 |
Correct |
8 ms |
25356 KB |
n=500 |
44 |
Correct |
8 ms |
25176 KB |
n=500 |
45 |
Correct |
8 ms |
25180 KB |
n=500 |
46 |
Correct |
9 ms |
25176 KB |
n=500 |
47 |
Correct |
8 ms |
25180 KB |
n=500 |
48 |
Correct |
8 ms |
25180 KB |
n=500 |
49 |
Correct |
7 ms |
25180 KB |
n=500 |
50 |
Correct |
8 ms |
25176 KB |
n=500 |
51 |
Correct |
8 ms |
25432 KB |
n=500 |
52 |
Correct |
9 ms |
25180 KB |
n=500 |
53 |
Correct |
9 ms |
25528 KB |
n=500 |
54 |
Correct |
10 ms |
25180 KB |
n=500 |
55 |
Correct |
8 ms |
25180 KB |
n=278 |
56 |
Correct |
8 ms |
25176 KB |
n=500 |
57 |
Correct |
8 ms |
25380 KB |
n=500 |
58 |
Correct |
7 ms |
25180 KB |
n=500 |
59 |
Correct |
10 ms |
25436 KB |
n=2000 |
60 |
Correct |
10 ms |
25688 KB |
n=2000 |
61 |
Correct |
10 ms |
25692 KB |
n=2000 |
62 |
Correct |
9 ms |
25436 KB |
n=2000 |
63 |
Correct |
9 ms |
25436 KB |
n=2000 |
64 |
Correct |
11 ms |
25432 KB |
n=2000 |
65 |
Correct |
9 ms |
25432 KB |
n=2000 |
66 |
Correct |
11 ms |
25688 KB |
n=2000 |
67 |
Correct |
12 ms |
25436 KB |
n=2000 |
68 |
Correct |
10 ms |
25436 KB |
n=2000 |
69 |
Correct |
9 ms |
25436 KB |
n=2000 |
70 |
Correct |
10 ms |
25436 KB |
n=2000 |
71 |
Correct |
10 ms |
25436 KB |
n=2000 |
72 |
Correct |
10 ms |
25788 KB |
n=2000 |
73 |
Correct |
9 ms |
25436 KB |
n=2000 |
74 |
Correct |
11 ms |
25692 KB |
n=1844 |
75 |
Correct |
9 ms |
25436 KB |
n=2000 |
76 |
Correct |
10 ms |
25436 KB |
n=2000 |
77 |
Correct |
11 ms |
25432 KB |
n=2000 |
78 |
Correct |
10 ms |
25596 KB |
n=2000 |
79 |
Correct |
9 ms |
25432 KB |
n=2000 |
80 |
Correct |
10 ms |
25692 KB |
n=2000 |
81 |
Correct |
10 ms |
25436 KB |
n=2000 |
82 |
Correct |
9 ms |
25436 KB |
n=2000 |
83 |
Correct |
10 ms |
25692 KB |
n=2000 |
84 |
Correct |
10 ms |
25436 KB |
n=2000 |
85 |
Correct |
10 ms |
25432 KB |
n=2000 |
86 |
Correct |
9 ms |
25436 KB |
n=2000 |
87 |
Correct |
10 ms |
25436 KB |
n=2000 |
88 |
Correct |
9 ms |
25692 KB |
n=2000 |
89 |
Correct |
10 ms |
25688 KB |
n=2000 |
90 |
Correct |
10 ms |
25692 KB |
n=2000 |
91 |
Correct |
9 ms |
25436 KB |
n=2000 |
92 |
Correct |
571 ms |
74660 KB |
n=200000 |
93 |
Correct |
848 ms |
82816 KB |
n=200000 |
94 |
Correct |
871 ms |
88356 KB |
n=200000 |
95 |
Correct |
569 ms |
74364 KB |
n=200000 |
96 |
Correct |
559 ms |
74512 KB |
n=200000 |
97 |
Correct |
863 ms |
81312 KB |
n=200000 |
98 |
Correct |
532 ms |
74552 KB |
n=200000 |
99 |
Correct |
723 ms |
75000 KB |
n=200000 |
100 |
Correct |
553 ms |
74400 KB |
n=200000 |
101 |
Correct |
975 ms |
90188 KB |
n=200000 |
102 |
Correct |
368 ms |
75656 KB |
n=200000 |
103 |
Correct |
360 ms |
75476 KB |
n=200000 |
104 |
Correct |
408 ms |
75604 KB |
n=200000 |
105 |
Correct |
380 ms |
76116 KB |
n=200000 |
106 |
Correct |
411 ms |
76060 KB |
n=200000 |
107 |
Correct |
369 ms |
75960 KB |
n=200000 |
108 |
Correct |
624 ms |
74532 KB |
n=200000 |
109 |
Correct |
613 ms |
74576 KB |
n=200000 |
110 |
Correct |
638 ms |
74492 KB |
n=200000 |
111 |
Correct |
518 ms |
74128 KB |
n=200000 |
112 |
Correct |
859 ms |
88524 KB |
n=200000 |
113 |
Correct |
845 ms |
81160 KB |
n=200000 |
114 |
Correct |
532 ms |
73940 KB |
n=200000 |
115 |
Correct |
873 ms |
77600 KB |
n=200000 |
116 |
Correct |
503 ms |
74564 KB |
n=200000 |
117 |
Correct |
740 ms |
89484 KB |
n=200000 |
118 |
Correct |
1039 ms |
79408 KB |
n=200000 |
119 |
Correct |
548 ms |
74660 KB |
n=200000 |
120 |
Correct |
671 ms |
89412 KB |
n=200000 |
121 |
Correct |
907 ms |
89388 KB |
n=200000 |
122 |
Correct |
923 ms |
89692 KB |
n=200000 |
123 |
Correct |
421 ms |
75852 KB |
n=200000 |
124 |
Incorrect |
108 ms |
40960 KB |
Wrong range. |
125 |
Halted |
0 ms |
0 KB |
- |