// 以上帝的名义
// 候选硕士
#include <bits/stdc++.h>
#ifdef local
#include "algo/debug.h"
#else
#define dbg(x...) 0
#endif
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define Node int
#define at(i) find_by_order(i)
#define which(x) order_of_key(x)
#define SET tree<Node, null_type,less<Node>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std ;
using ll = long long ;
using ld = long double ;
const int N = 2e5 + 5 ;
int n , m , q, a[N], p[N] ;
vector<int> g[N] ;
int tin[N], tout[N], timer , up[N][20] ;
void dfs(int v, int p) {
tin[v] = ++timer ;
up[v][0] = p ;
for (int i = 1 ; i < 20 ; i++) {
up[v][i] = up[up[v][i - 1]][i - 1] ;
}
for (auto to : g[v]) {
if (to != p) {
dfs(to, v) ;
}
}
tout[v] = ++timer ;
}
bool is(int u, int v) {
return tin[u] <= tin[v] && tout[u] >= tout[v] ;
}
bool upper(int u, int v) {
return tin[u] < tin[v] && tout[u] > tout[v] ;
}
int lca(int u, int v) {
if (!u) return v ;
if (!v) return u ;
if (is(u, v)) return u ;
if (is(v, u)) return v ;
for (int i = 19 ; ~i ; i--) {
if (!is(up[u][i], v)) {
u = up[u][i] ;
}
}
return up[u][0] ;
}
int t[N * 4] ;
void modify(int i, int x, int v, int tl, int tr) {
if (tl == tr) {
t[v] = x ;
} else {
int tm = (tl + tr) / 2 ;
if (i <= tm) {
modify(i, x, v * 2, tl, tm) ;
} else {
modify(i, x, v * 2 + 1, tm + 1, tr) ;
}
t[v] = lca(t[v * 2], t[v * 2 + 1]) ;
}
}
int get(int l, int r, int v, int tl, int tr) {
if (l > tr || r < tl) return 0 ;
if (l <= tl && tr <= r) return t[v] ;
int tm = (tl + tr) / 2 ;
return lca(get(l, r,v * 2, tl, tm), get(l, r,v * 2 + 1 ,tm + 1, tr)) ;
}
int32_t main() {
ios::sync_with_stdio(false) ;
cin.tie(nullptr) ;
cin >> n >> m >> q ;
for (int i = 1 ; i < n ; i++) {
int u , v ; cin >> u >> v;
g[u].push_back(v) ;
g[v].push_back(u) ;
}
for (int i = 1 ; i <= m ; i++) {
cin >> a[i] ;
p[a[i]] = i ;
}
dfs(1, 1) ;
for (int i = 1 ; i <= m ; i++) {
modify(i, a[i], 1, 1, m) ;
}
// dbg(get(1, 2, 1, 1, m)) ;
for (int i = 0 ; i < q ; i++) {
int cmd ; cin >> cmd ;
if (cmd == 1) {
int pos, v; cin >> pos >> v ;
modify(pos, v, 1, 1, m) ;
} else {
int l, r, v; cin >> l >> r >> v ;
int _l = -1, _r = -1 ;
for (int j = l ; j <= r ; j++) {
int L = j, R = r ;
while (L < R) {
ll mid = (L + R + 1) / 2 ;
ll c = get(j, mid, 1, 1, m) ;
if (upper(c, v)) R = mid - 1 ;
else L = mid ;
}
// dbg(j, L, get(j, L, 1, 1, m)) ;
if (get(j, L, 1, 1, m) == v) {
_l = j , _r = L ;
break ;
}
}
cout << _l << ' ' << _r << "\n" ;
}
}
return 0 ;
}
// 希望白银
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8792 KB |
n=5 |
2 |
Correct |
2 ms |
8796 KB |
n=100 |
3 |
Correct |
2 ms |
9048 KB |
n=100 |
4 |
Correct |
2 ms |
8792 KB |
n=100 |
5 |
Correct |
2 ms |
9048 KB |
n=100 |
6 |
Correct |
8 ms |
8796 KB |
n=100 |
7 |
Correct |
6 ms |
8796 KB |
n=100 |
8 |
Correct |
3 ms |
8792 KB |
n=100 |
9 |
Correct |
5 ms |
8796 KB |
n=100 |
10 |
Correct |
4 ms |
8796 KB |
n=100 |
11 |
Correct |
3 ms |
8796 KB |
n=100 |
12 |
Correct |
2 ms |
8796 KB |
n=100 |
13 |
Correct |
2 ms |
8796 KB |
n=100 |
14 |
Correct |
2 ms |
9048 KB |
n=100 |
15 |
Correct |
2 ms |
8796 KB |
n=100 |
16 |
Correct |
2 ms |
8796 KB |
n=100 |
17 |
Correct |
2 ms |
8796 KB |
n=100 |
18 |
Correct |
2 ms |
8796 KB |
n=100 |
19 |
Correct |
2 ms |
9048 KB |
n=100 |
20 |
Correct |
2 ms |
8796 KB |
n=100 |
21 |
Correct |
2 ms |
8792 KB |
n=100 |
22 |
Correct |
2 ms |
8796 KB |
n=100 |
23 |
Correct |
3 ms |
8796 KB |
n=100 |
24 |
Correct |
3 ms |
8796 KB |
n=100 |
25 |
Correct |
2 ms |
8796 KB |
n=100 |
26 |
Correct |
1 ms |
8796 KB |
n=12 |
27 |
Correct |
5 ms |
8796 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8792 KB |
n=5 |
2 |
Correct |
2 ms |
8796 KB |
n=100 |
3 |
Correct |
2 ms |
9048 KB |
n=100 |
4 |
Correct |
2 ms |
8792 KB |
n=100 |
5 |
Correct |
2 ms |
9048 KB |
n=100 |
6 |
Correct |
8 ms |
8796 KB |
n=100 |
7 |
Correct |
6 ms |
8796 KB |
n=100 |
8 |
Correct |
3 ms |
8792 KB |
n=100 |
9 |
Correct |
5 ms |
8796 KB |
n=100 |
10 |
Correct |
4 ms |
8796 KB |
n=100 |
11 |
Correct |
3 ms |
8796 KB |
n=100 |
12 |
Correct |
2 ms |
8796 KB |
n=100 |
13 |
Correct |
2 ms |
8796 KB |
n=100 |
14 |
Correct |
2 ms |
9048 KB |
n=100 |
15 |
Correct |
2 ms |
8796 KB |
n=100 |
16 |
Correct |
2 ms |
8796 KB |
n=100 |
17 |
Correct |
2 ms |
8796 KB |
n=100 |
18 |
Correct |
2 ms |
8796 KB |
n=100 |
19 |
Correct |
2 ms |
9048 KB |
n=100 |
20 |
Correct |
2 ms |
8796 KB |
n=100 |
21 |
Correct |
2 ms |
8792 KB |
n=100 |
22 |
Correct |
2 ms |
8796 KB |
n=100 |
23 |
Correct |
3 ms |
8796 KB |
n=100 |
24 |
Correct |
3 ms |
8796 KB |
n=100 |
25 |
Correct |
2 ms |
8796 KB |
n=100 |
26 |
Correct |
1 ms |
8796 KB |
n=12 |
27 |
Correct |
5 ms |
8796 KB |
n=100 |
28 |
Correct |
3 ms |
8796 KB |
n=500 |
29 |
Correct |
24 ms |
8796 KB |
n=500 |
30 |
Correct |
19 ms |
8796 KB |
n=500 |
31 |
Correct |
21 ms |
8960 KB |
n=500 |
32 |
Correct |
3 ms |
8792 KB |
n=500 |
33 |
Correct |
18 ms |
8792 KB |
n=500 |
34 |
Correct |
2 ms |
8796 KB |
n=500 |
35 |
Correct |
21 ms |
8968 KB |
n=500 |
36 |
Correct |
145 ms |
8932 KB |
n=500 |
37 |
Correct |
144 ms |
8940 KB |
n=500 |
38 |
Correct |
144 ms |
8796 KB |
n=500 |
39 |
Correct |
52 ms |
8796 KB |
n=500 |
40 |
Correct |
47 ms |
8944 KB |
n=500 |
41 |
Correct |
48 ms |
8796 KB |
n=500 |
42 |
Correct |
76 ms |
8796 KB |
n=500 |
43 |
Correct |
83 ms |
8936 KB |
n=500 |
44 |
Correct |
75 ms |
8944 KB |
n=500 |
45 |
Correct |
2 ms |
8796 KB |
n=500 |
46 |
Correct |
25 ms |
9052 KB |
n=500 |
47 |
Correct |
20 ms |
8792 KB |
n=500 |
48 |
Correct |
2 ms |
8796 KB |
n=500 |
49 |
Correct |
18 ms |
8796 KB |
n=500 |
50 |
Correct |
31 ms |
8796 KB |
n=500 |
51 |
Correct |
33 ms |
8792 KB |
n=500 |
52 |
Correct |
39 ms |
8796 KB |
n=500 |
53 |
Correct |
35 ms |
8796 KB |
n=500 |
54 |
Correct |
23 ms |
8796 KB |
n=500 |
55 |
Correct |
7 ms |
8792 KB |
n=278 |
56 |
Correct |
126 ms |
8960 KB |
n=500 |
57 |
Correct |
133 ms |
8792 KB |
n=500 |
58 |
Correct |
97 ms |
8948 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8792 KB |
n=5 |
2 |
Correct |
2 ms |
8796 KB |
n=100 |
3 |
Correct |
2 ms |
9048 KB |
n=100 |
4 |
Correct |
2 ms |
8792 KB |
n=100 |
5 |
Correct |
2 ms |
9048 KB |
n=100 |
6 |
Correct |
8 ms |
8796 KB |
n=100 |
7 |
Correct |
6 ms |
8796 KB |
n=100 |
8 |
Correct |
3 ms |
8792 KB |
n=100 |
9 |
Correct |
5 ms |
8796 KB |
n=100 |
10 |
Correct |
4 ms |
8796 KB |
n=100 |
11 |
Correct |
3 ms |
8796 KB |
n=100 |
12 |
Correct |
2 ms |
8796 KB |
n=100 |
13 |
Correct |
2 ms |
8796 KB |
n=100 |
14 |
Correct |
2 ms |
9048 KB |
n=100 |
15 |
Correct |
2 ms |
8796 KB |
n=100 |
16 |
Correct |
2 ms |
8796 KB |
n=100 |
17 |
Correct |
2 ms |
8796 KB |
n=100 |
18 |
Correct |
2 ms |
8796 KB |
n=100 |
19 |
Correct |
2 ms |
9048 KB |
n=100 |
20 |
Correct |
2 ms |
8796 KB |
n=100 |
21 |
Correct |
2 ms |
8792 KB |
n=100 |
22 |
Correct |
2 ms |
8796 KB |
n=100 |
23 |
Correct |
3 ms |
8796 KB |
n=100 |
24 |
Correct |
3 ms |
8796 KB |
n=100 |
25 |
Correct |
2 ms |
8796 KB |
n=100 |
26 |
Correct |
1 ms |
8796 KB |
n=12 |
27 |
Correct |
5 ms |
8796 KB |
n=100 |
28 |
Correct |
3 ms |
8796 KB |
n=500 |
29 |
Correct |
24 ms |
8796 KB |
n=500 |
30 |
Correct |
19 ms |
8796 KB |
n=500 |
31 |
Correct |
21 ms |
8960 KB |
n=500 |
32 |
Correct |
3 ms |
8792 KB |
n=500 |
33 |
Correct |
18 ms |
8792 KB |
n=500 |
34 |
Correct |
2 ms |
8796 KB |
n=500 |
35 |
Correct |
21 ms |
8968 KB |
n=500 |
36 |
Correct |
145 ms |
8932 KB |
n=500 |
37 |
Correct |
144 ms |
8940 KB |
n=500 |
38 |
Correct |
144 ms |
8796 KB |
n=500 |
39 |
Correct |
52 ms |
8796 KB |
n=500 |
40 |
Correct |
47 ms |
8944 KB |
n=500 |
41 |
Correct |
48 ms |
8796 KB |
n=500 |
42 |
Correct |
76 ms |
8796 KB |
n=500 |
43 |
Correct |
83 ms |
8936 KB |
n=500 |
44 |
Correct |
75 ms |
8944 KB |
n=500 |
45 |
Correct |
2 ms |
8796 KB |
n=500 |
46 |
Correct |
25 ms |
9052 KB |
n=500 |
47 |
Correct |
20 ms |
8792 KB |
n=500 |
48 |
Correct |
2 ms |
8796 KB |
n=500 |
49 |
Correct |
18 ms |
8796 KB |
n=500 |
50 |
Correct |
31 ms |
8796 KB |
n=500 |
51 |
Correct |
33 ms |
8792 KB |
n=500 |
52 |
Correct |
39 ms |
8796 KB |
n=500 |
53 |
Correct |
35 ms |
8796 KB |
n=500 |
54 |
Correct |
23 ms |
8796 KB |
n=500 |
55 |
Correct |
7 ms |
8792 KB |
n=278 |
56 |
Correct |
126 ms |
8960 KB |
n=500 |
57 |
Correct |
133 ms |
8792 KB |
n=500 |
58 |
Correct |
97 ms |
8948 KB |
n=500 |
59 |
Correct |
9 ms |
9048 KB |
n=2000 |
60 |
Correct |
499 ms |
9296 KB |
n=2000 |
61 |
Correct |
470 ms |
9048 KB |
n=2000 |
62 |
Correct |
326 ms |
9076 KB |
n=2000 |
63 |
Correct |
13 ms |
9048 KB |
n=2000 |
64 |
Correct |
427 ms |
9088 KB |
n=2000 |
65 |
Correct |
6 ms |
9064 KB |
n=2000 |
66 |
Correct |
535 ms |
9116 KB |
n=2000 |
67 |
Correct |
29 ms |
9052 KB |
n=2000 |
68 |
Correct |
437 ms |
9096 KB |
n=2000 |
69 |
Correct |
3331 ms |
9320 KB |
n=2000 |
70 |
Correct |
3298 ms |
9072 KB |
n=2000 |
71 |
Correct |
3320 ms |
9308 KB |
n=2000 |
72 |
Correct |
1206 ms |
9060 KB |
n=2000 |
73 |
Correct |
1185 ms |
9304 KB |
n=2000 |
74 |
Correct |
5 ms |
9052 KB |
n=1844 |
75 |
Correct |
1197 ms |
9056 KB |
n=2000 |
76 |
Correct |
1733 ms |
9300 KB |
n=2000 |
77 |
Correct |
1740 ms |
9304 KB |
n=2000 |
78 |
Correct |
1836 ms |
9064 KB |
n=2000 |
79 |
Correct |
5 ms |
9052 KB |
n=2000 |
80 |
Correct |
430 ms |
9128 KB |
n=2000 |
81 |
Correct |
390 ms |
9088 KB |
n=2000 |
82 |
Correct |
5 ms |
9048 KB |
n=2000 |
83 |
Correct |
426 ms |
9116 KB |
n=2000 |
84 |
Correct |
783 ms |
9060 KB |
n=2000 |
85 |
Correct |
767 ms |
9080 KB |
n=2000 |
86 |
Correct |
834 ms |
9048 KB |
n=2000 |
87 |
Correct |
850 ms |
9300 KB |
n=2000 |
88 |
Correct |
3367 ms |
9148 KB |
n=2000 |
89 |
Correct |
3347 ms |
9148 KB |
n=2000 |
90 |
Correct |
503 ms |
9140 KB |
n=2000 |
91 |
Correct |
2349 ms |
9312 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8792 KB |
n=5 |
2 |
Correct |
2 ms |
8796 KB |
n=100 |
3 |
Correct |
2 ms |
9048 KB |
n=100 |
4 |
Correct |
2 ms |
8792 KB |
n=100 |
5 |
Correct |
2 ms |
9048 KB |
n=100 |
6 |
Correct |
8 ms |
8796 KB |
n=100 |
7 |
Correct |
6 ms |
8796 KB |
n=100 |
8 |
Correct |
3 ms |
8792 KB |
n=100 |
9 |
Correct |
5 ms |
8796 KB |
n=100 |
10 |
Correct |
4 ms |
8796 KB |
n=100 |
11 |
Correct |
3 ms |
8796 KB |
n=100 |
12 |
Correct |
2 ms |
8796 KB |
n=100 |
13 |
Correct |
2 ms |
8796 KB |
n=100 |
14 |
Correct |
2 ms |
9048 KB |
n=100 |
15 |
Correct |
2 ms |
8796 KB |
n=100 |
16 |
Correct |
2 ms |
8796 KB |
n=100 |
17 |
Correct |
2 ms |
8796 KB |
n=100 |
18 |
Correct |
2 ms |
8796 KB |
n=100 |
19 |
Correct |
2 ms |
9048 KB |
n=100 |
20 |
Correct |
2 ms |
8796 KB |
n=100 |
21 |
Correct |
2 ms |
8792 KB |
n=100 |
22 |
Correct |
2 ms |
8796 KB |
n=100 |
23 |
Correct |
3 ms |
8796 KB |
n=100 |
24 |
Correct |
3 ms |
8796 KB |
n=100 |
25 |
Correct |
2 ms |
8796 KB |
n=100 |
26 |
Correct |
1 ms |
8796 KB |
n=12 |
27 |
Correct |
5 ms |
8796 KB |
n=100 |
28 |
Correct |
3 ms |
8796 KB |
n=500 |
29 |
Correct |
24 ms |
8796 KB |
n=500 |
30 |
Correct |
19 ms |
8796 KB |
n=500 |
31 |
Correct |
21 ms |
8960 KB |
n=500 |
32 |
Correct |
3 ms |
8792 KB |
n=500 |
33 |
Correct |
18 ms |
8792 KB |
n=500 |
34 |
Correct |
2 ms |
8796 KB |
n=500 |
35 |
Correct |
21 ms |
8968 KB |
n=500 |
36 |
Correct |
145 ms |
8932 KB |
n=500 |
37 |
Correct |
144 ms |
8940 KB |
n=500 |
38 |
Correct |
144 ms |
8796 KB |
n=500 |
39 |
Correct |
52 ms |
8796 KB |
n=500 |
40 |
Correct |
47 ms |
8944 KB |
n=500 |
41 |
Correct |
48 ms |
8796 KB |
n=500 |
42 |
Correct |
76 ms |
8796 KB |
n=500 |
43 |
Correct |
83 ms |
8936 KB |
n=500 |
44 |
Correct |
75 ms |
8944 KB |
n=500 |
45 |
Correct |
2 ms |
8796 KB |
n=500 |
46 |
Correct |
25 ms |
9052 KB |
n=500 |
47 |
Correct |
20 ms |
8792 KB |
n=500 |
48 |
Correct |
2 ms |
8796 KB |
n=500 |
49 |
Correct |
18 ms |
8796 KB |
n=500 |
50 |
Correct |
31 ms |
8796 KB |
n=500 |
51 |
Correct |
33 ms |
8792 KB |
n=500 |
52 |
Correct |
39 ms |
8796 KB |
n=500 |
53 |
Correct |
35 ms |
8796 KB |
n=500 |
54 |
Correct |
23 ms |
8796 KB |
n=500 |
55 |
Correct |
7 ms |
8792 KB |
n=278 |
56 |
Correct |
126 ms |
8960 KB |
n=500 |
57 |
Correct |
133 ms |
8792 KB |
n=500 |
58 |
Correct |
97 ms |
8948 KB |
n=500 |
59 |
Correct |
9 ms |
9048 KB |
n=2000 |
60 |
Correct |
499 ms |
9296 KB |
n=2000 |
61 |
Correct |
470 ms |
9048 KB |
n=2000 |
62 |
Correct |
326 ms |
9076 KB |
n=2000 |
63 |
Correct |
13 ms |
9048 KB |
n=2000 |
64 |
Correct |
427 ms |
9088 KB |
n=2000 |
65 |
Correct |
6 ms |
9064 KB |
n=2000 |
66 |
Correct |
535 ms |
9116 KB |
n=2000 |
67 |
Correct |
29 ms |
9052 KB |
n=2000 |
68 |
Correct |
437 ms |
9096 KB |
n=2000 |
69 |
Correct |
3331 ms |
9320 KB |
n=2000 |
70 |
Correct |
3298 ms |
9072 KB |
n=2000 |
71 |
Correct |
3320 ms |
9308 KB |
n=2000 |
72 |
Correct |
1206 ms |
9060 KB |
n=2000 |
73 |
Correct |
1185 ms |
9304 KB |
n=2000 |
74 |
Correct |
5 ms |
9052 KB |
n=1844 |
75 |
Correct |
1197 ms |
9056 KB |
n=2000 |
76 |
Correct |
1733 ms |
9300 KB |
n=2000 |
77 |
Correct |
1740 ms |
9304 KB |
n=2000 |
78 |
Correct |
1836 ms |
9064 KB |
n=2000 |
79 |
Correct |
5 ms |
9052 KB |
n=2000 |
80 |
Correct |
430 ms |
9128 KB |
n=2000 |
81 |
Correct |
390 ms |
9088 KB |
n=2000 |
82 |
Correct |
5 ms |
9048 KB |
n=2000 |
83 |
Correct |
426 ms |
9116 KB |
n=2000 |
84 |
Correct |
783 ms |
9060 KB |
n=2000 |
85 |
Correct |
767 ms |
9080 KB |
n=2000 |
86 |
Correct |
834 ms |
9048 KB |
n=2000 |
87 |
Correct |
850 ms |
9300 KB |
n=2000 |
88 |
Correct |
3367 ms |
9148 KB |
n=2000 |
89 |
Correct |
3347 ms |
9148 KB |
n=2000 |
90 |
Correct |
503 ms |
9140 KB |
n=2000 |
91 |
Correct |
2349 ms |
9312 KB |
n=2000 |
92 |
Execution timed out |
4056 ms |
39268 KB |
Time limit exceeded |
93 |
Halted |
0 ms |
0 KB |
- |