#include <bits/stdc++.h>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
//#define int long long
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,bmi,bmi2,lzcnt,popcnt")
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
const double eps = 1e-9;
int n, m, q, depth[maxn], up[maxn][LOG];
vector<int> graph[maxn], val(maxn);
void dfs(int u, int p) {
for(int i=1; i<LOG; i++) up[u][i] = up[up[u][i-1]][i-1];
for(int &v : graph[u]) {
if(v == p) continue;
up[v][0] = u;
depth[v] = depth[u] + 1;
dfs(v, u);
}
}
int jmp(int x, int d) {
for(int j=LOG-1; j>=0; j--)
if(d & (1 << j)) x = up[x][j];
return x;
}
int get_lca(int a, int b) {
if(a == 1e9) return b;
if(b == 1e9) return a;
if(depth[a] < depth[b]) swap(a, b);
a = jmp(a, depth[a] - depth[b]);
if(a == b) return a;
for(int j=LOG-1; j>=0; j--)
if(up[a][j] != up[b][j])
a = up[a][j], b = up[b][j];
return up[a][0];
}
struct SegTree {
int n;
vector<int> v;
vector<int> tree;
SegTree(int _n) {
n = _n;
tree.resize(4*n+5, 1e9);
}
void build(int u, int tl, int tr) {
if(tl == tr) {
tree[u] = v[tl];
} else {
int tm = (tl + tr) / 2;
build(2*u, tl, tm);
build(2*u+1, tm+1, tr);
tree[u] = get_lca(tree[2*u], tree[2*u+1]);
}
}
void update(int u, int tl, int tr, int p, int v) {
if(tl == tr) {
tree[u] = v;
} else {
int tm = (tl + tr) / 2;
if(p <= tm) update(2*u, tl, tm, p, v);
else update(2*u+1, tm+1, tr, p, v);
tree[u] = get_lca(tree[2*u], tree[2*u+1]);
}
}
int query(int u, int tl, int tr, int l, int r) {
if(tl > tr || l > tr || tl > r) return 1e9;
if(l <= tl && tr <= r) return tree[u];
int tm = (tl + tr) / 2;
return get_lca(
query(2*u, tl, tm, l, r),
query(2*u+1, tm+1, tr, l, r)
);
}
void update(int p, int v) { update(1, 0, n-1, p, v); }
int query(int l, int r) { return query(1, 0, n-1, l, r); }
};
int32_t main() {
ios_base::sync_with_stdio(false);
cout.tie(0); cin.tie(0);
cin >> n >> m >> q;
for(int i=0; i<n-1; i++) {
int a, b;
cin >> a >> b;
graph[a].push_back(b);
graph[b].push_back(a);
}
dfs(1, 0);
for(int i=1; i<=m; i++) {
cin >> val[i];
}
SegTree tree(m+1);
for(int i=1; i<=m; i++) tree.update(i, val[i]);
while(q--) {
int t;
cin >> t;
if(t == 1) {
int p, v;
cin >> p >> v;
val[p] = v;
tree.update(p, v);
} else {
int l, r, v;
cin >> l >> r >> v;
bool ok = 0;
for(int i=l; i<=r; i++) {
int d = depth[v];
int tl=i, tr=r, pos=i;
while(tl <= tr) {
int mid = (tl + tr) / 2;
if(depth[tree.query(i, mid)] >= d) pos = mid, tl = mid + 1;
else tr = mid - 1;
}
//cout << i << ": " << pos << ", " << d << '\n';
//cout << tree.query(i, pos) << '\n';
if(tree.query(i, pos) == v && !ok) {
ok = 1;
cout << i << " " << pos << '\n';
break;
}
}
if(!ok) cout << "-1 -1" << '\n';
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4952 KB |
n=5 |
2 |
Correct |
2 ms |
4956 KB |
n=100 |
3 |
Correct |
1 ms |
4956 KB |
n=100 |
4 |
Correct |
1 ms |
4952 KB |
n=100 |
5 |
Correct |
1 ms |
4956 KB |
n=100 |
6 |
Correct |
3 ms |
4956 KB |
n=100 |
7 |
Correct |
3 ms |
4956 KB |
n=100 |
8 |
Correct |
2 ms |
4952 KB |
n=100 |
9 |
Correct |
2 ms |
4956 KB |
n=100 |
10 |
Correct |
2 ms |
4956 KB |
n=100 |
11 |
Correct |
2 ms |
4956 KB |
n=100 |
12 |
Correct |
1 ms |
4956 KB |
n=100 |
13 |
Correct |
1 ms |
4956 KB |
n=100 |
14 |
Correct |
1 ms |
4952 KB |
n=100 |
15 |
Correct |
1 ms |
4956 KB |
n=100 |
16 |
Correct |
1 ms |
4956 KB |
n=100 |
17 |
Correct |
2 ms |
4952 KB |
n=100 |
18 |
Correct |
2 ms |
4956 KB |
n=100 |
19 |
Correct |
1 ms |
4956 KB |
n=100 |
20 |
Correct |
2 ms |
4956 KB |
n=100 |
21 |
Correct |
1 ms |
4956 KB |
n=100 |
22 |
Correct |
1 ms |
4952 KB |
n=100 |
23 |
Correct |
3 ms |
4956 KB |
n=100 |
24 |
Correct |
3 ms |
4956 KB |
n=100 |
25 |
Correct |
1 ms |
4956 KB |
n=100 |
26 |
Correct |
2 ms |
4952 KB |
n=12 |
27 |
Correct |
2 ms |
4956 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4952 KB |
n=5 |
2 |
Correct |
2 ms |
4956 KB |
n=100 |
3 |
Correct |
1 ms |
4956 KB |
n=100 |
4 |
Correct |
1 ms |
4952 KB |
n=100 |
5 |
Correct |
1 ms |
4956 KB |
n=100 |
6 |
Correct |
3 ms |
4956 KB |
n=100 |
7 |
Correct |
3 ms |
4956 KB |
n=100 |
8 |
Correct |
2 ms |
4952 KB |
n=100 |
9 |
Correct |
2 ms |
4956 KB |
n=100 |
10 |
Correct |
2 ms |
4956 KB |
n=100 |
11 |
Correct |
2 ms |
4956 KB |
n=100 |
12 |
Correct |
1 ms |
4956 KB |
n=100 |
13 |
Correct |
1 ms |
4956 KB |
n=100 |
14 |
Correct |
1 ms |
4952 KB |
n=100 |
15 |
Correct |
1 ms |
4956 KB |
n=100 |
16 |
Correct |
1 ms |
4956 KB |
n=100 |
17 |
Correct |
2 ms |
4952 KB |
n=100 |
18 |
Correct |
2 ms |
4956 KB |
n=100 |
19 |
Correct |
1 ms |
4956 KB |
n=100 |
20 |
Correct |
2 ms |
4956 KB |
n=100 |
21 |
Correct |
1 ms |
4956 KB |
n=100 |
22 |
Correct |
1 ms |
4952 KB |
n=100 |
23 |
Correct |
3 ms |
4956 KB |
n=100 |
24 |
Correct |
3 ms |
4956 KB |
n=100 |
25 |
Correct |
1 ms |
4956 KB |
n=100 |
26 |
Correct |
2 ms |
4952 KB |
n=12 |
27 |
Correct |
2 ms |
4956 KB |
n=100 |
28 |
Correct |
2 ms |
4952 KB |
n=500 |
29 |
Correct |
22 ms |
4952 KB |
n=500 |
30 |
Correct |
17 ms |
4956 KB |
n=500 |
31 |
Correct |
19 ms |
4956 KB |
n=500 |
32 |
Correct |
2 ms |
4952 KB |
n=500 |
33 |
Correct |
16 ms |
4956 KB |
n=500 |
34 |
Correct |
2 ms |
4956 KB |
n=500 |
35 |
Correct |
19 ms |
4952 KB |
n=500 |
36 |
Correct |
110 ms |
4956 KB |
n=500 |
37 |
Correct |
118 ms |
4956 KB |
n=500 |
38 |
Correct |
109 ms |
4956 KB |
n=500 |
39 |
Correct |
37 ms |
4956 KB |
n=500 |
40 |
Correct |
39 ms |
4956 KB |
n=500 |
41 |
Correct |
37 ms |
4952 KB |
n=500 |
42 |
Correct |
65 ms |
4952 KB |
n=500 |
43 |
Correct |
56 ms |
4956 KB |
n=500 |
44 |
Correct |
57 ms |
4952 KB |
n=500 |
45 |
Correct |
2 ms |
4956 KB |
n=500 |
46 |
Correct |
21 ms |
4952 KB |
n=500 |
47 |
Correct |
17 ms |
4952 KB |
n=500 |
48 |
Correct |
1 ms |
4956 KB |
n=500 |
49 |
Correct |
17 ms |
4956 KB |
n=500 |
50 |
Correct |
23 ms |
4956 KB |
n=500 |
51 |
Correct |
29 ms |
4956 KB |
n=500 |
52 |
Correct |
37 ms |
4952 KB |
n=500 |
53 |
Correct |
30 ms |
4956 KB |
n=500 |
54 |
Correct |
25 ms |
4956 KB |
n=500 |
55 |
Correct |
4 ms |
4956 KB |
n=278 |
56 |
Correct |
132 ms |
4956 KB |
n=500 |
57 |
Correct |
137 ms |
4952 KB |
n=500 |
58 |
Correct |
67 ms |
4952 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4952 KB |
n=5 |
2 |
Correct |
2 ms |
4956 KB |
n=100 |
3 |
Correct |
1 ms |
4956 KB |
n=100 |
4 |
Correct |
1 ms |
4952 KB |
n=100 |
5 |
Correct |
1 ms |
4956 KB |
n=100 |
6 |
Correct |
3 ms |
4956 KB |
n=100 |
7 |
Correct |
3 ms |
4956 KB |
n=100 |
8 |
Correct |
2 ms |
4952 KB |
n=100 |
9 |
Correct |
2 ms |
4956 KB |
n=100 |
10 |
Correct |
2 ms |
4956 KB |
n=100 |
11 |
Correct |
2 ms |
4956 KB |
n=100 |
12 |
Correct |
1 ms |
4956 KB |
n=100 |
13 |
Correct |
1 ms |
4956 KB |
n=100 |
14 |
Correct |
1 ms |
4952 KB |
n=100 |
15 |
Correct |
1 ms |
4956 KB |
n=100 |
16 |
Correct |
1 ms |
4956 KB |
n=100 |
17 |
Correct |
2 ms |
4952 KB |
n=100 |
18 |
Correct |
2 ms |
4956 KB |
n=100 |
19 |
Correct |
1 ms |
4956 KB |
n=100 |
20 |
Correct |
2 ms |
4956 KB |
n=100 |
21 |
Correct |
1 ms |
4956 KB |
n=100 |
22 |
Correct |
1 ms |
4952 KB |
n=100 |
23 |
Correct |
3 ms |
4956 KB |
n=100 |
24 |
Correct |
3 ms |
4956 KB |
n=100 |
25 |
Correct |
1 ms |
4956 KB |
n=100 |
26 |
Correct |
2 ms |
4952 KB |
n=12 |
27 |
Correct |
2 ms |
4956 KB |
n=100 |
28 |
Correct |
2 ms |
4952 KB |
n=500 |
29 |
Correct |
22 ms |
4952 KB |
n=500 |
30 |
Correct |
17 ms |
4956 KB |
n=500 |
31 |
Correct |
19 ms |
4956 KB |
n=500 |
32 |
Correct |
2 ms |
4952 KB |
n=500 |
33 |
Correct |
16 ms |
4956 KB |
n=500 |
34 |
Correct |
2 ms |
4956 KB |
n=500 |
35 |
Correct |
19 ms |
4952 KB |
n=500 |
36 |
Correct |
110 ms |
4956 KB |
n=500 |
37 |
Correct |
118 ms |
4956 KB |
n=500 |
38 |
Correct |
109 ms |
4956 KB |
n=500 |
39 |
Correct |
37 ms |
4956 KB |
n=500 |
40 |
Correct |
39 ms |
4956 KB |
n=500 |
41 |
Correct |
37 ms |
4952 KB |
n=500 |
42 |
Correct |
65 ms |
4952 KB |
n=500 |
43 |
Correct |
56 ms |
4956 KB |
n=500 |
44 |
Correct |
57 ms |
4952 KB |
n=500 |
45 |
Correct |
2 ms |
4956 KB |
n=500 |
46 |
Correct |
21 ms |
4952 KB |
n=500 |
47 |
Correct |
17 ms |
4952 KB |
n=500 |
48 |
Correct |
1 ms |
4956 KB |
n=500 |
49 |
Correct |
17 ms |
4956 KB |
n=500 |
50 |
Correct |
23 ms |
4956 KB |
n=500 |
51 |
Correct |
29 ms |
4956 KB |
n=500 |
52 |
Correct |
37 ms |
4952 KB |
n=500 |
53 |
Correct |
30 ms |
4956 KB |
n=500 |
54 |
Correct |
25 ms |
4956 KB |
n=500 |
55 |
Correct |
4 ms |
4956 KB |
n=278 |
56 |
Correct |
132 ms |
4956 KB |
n=500 |
57 |
Correct |
137 ms |
4952 KB |
n=500 |
58 |
Correct |
67 ms |
4952 KB |
n=500 |
59 |
Correct |
7 ms |
5208 KB |
n=2000 |
60 |
Correct |
523 ms |
5356 KB |
n=2000 |
61 |
Correct |
449 ms |
5212 KB |
n=2000 |
62 |
Correct |
295 ms |
5208 KB |
n=2000 |
63 |
Correct |
10 ms |
5208 KB |
n=2000 |
64 |
Correct |
398 ms |
5272 KB |
n=2000 |
65 |
Correct |
5 ms |
5208 KB |
n=2000 |
66 |
Correct |
514 ms |
5212 KB |
n=2000 |
67 |
Correct |
22 ms |
5208 KB |
n=2000 |
68 |
Correct |
414 ms |
5292 KB |
n=2000 |
69 |
Correct |
2693 ms |
5212 KB |
n=2000 |
70 |
Correct |
2717 ms |
5228 KB |
n=2000 |
71 |
Correct |
2674 ms |
5208 KB |
n=2000 |
72 |
Correct |
921 ms |
5208 KB |
n=2000 |
73 |
Correct |
930 ms |
5212 KB |
n=2000 |
74 |
Correct |
7 ms |
5208 KB |
n=1844 |
75 |
Correct |
929 ms |
5232 KB |
n=2000 |
76 |
Correct |
1480 ms |
5212 KB |
n=2000 |
77 |
Correct |
1388 ms |
5208 KB |
n=2000 |
78 |
Correct |
1465 ms |
5208 KB |
n=2000 |
79 |
Correct |
5 ms |
5212 KB |
n=2000 |
80 |
Correct |
416 ms |
5212 KB |
n=2000 |
81 |
Correct |
364 ms |
5208 KB |
n=2000 |
82 |
Correct |
5 ms |
5212 KB |
n=2000 |
83 |
Correct |
407 ms |
5312 KB |
n=2000 |
84 |
Correct |
600 ms |
5212 KB |
n=2000 |
85 |
Correct |
703 ms |
5212 KB |
n=2000 |
86 |
Correct |
762 ms |
5208 KB |
n=2000 |
87 |
Correct |
614 ms |
5208 KB |
n=2000 |
88 |
Correct |
3818 ms |
5360 KB |
n=2000 |
89 |
Correct |
3822 ms |
5416 KB |
n=2000 |
90 |
Correct |
568 ms |
5208 KB |
n=2000 |
91 |
Correct |
1736 ms |
5212 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4952 KB |
n=5 |
2 |
Correct |
2 ms |
4956 KB |
n=100 |
3 |
Correct |
1 ms |
4956 KB |
n=100 |
4 |
Correct |
1 ms |
4952 KB |
n=100 |
5 |
Correct |
1 ms |
4956 KB |
n=100 |
6 |
Correct |
3 ms |
4956 KB |
n=100 |
7 |
Correct |
3 ms |
4956 KB |
n=100 |
8 |
Correct |
2 ms |
4952 KB |
n=100 |
9 |
Correct |
2 ms |
4956 KB |
n=100 |
10 |
Correct |
2 ms |
4956 KB |
n=100 |
11 |
Correct |
2 ms |
4956 KB |
n=100 |
12 |
Correct |
1 ms |
4956 KB |
n=100 |
13 |
Correct |
1 ms |
4956 KB |
n=100 |
14 |
Correct |
1 ms |
4952 KB |
n=100 |
15 |
Correct |
1 ms |
4956 KB |
n=100 |
16 |
Correct |
1 ms |
4956 KB |
n=100 |
17 |
Correct |
2 ms |
4952 KB |
n=100 |
18 |
Correct |
2 ms |
4956 KB |
n=100 |
19 |
Correct |
1 ms |
4956 KB |
n=100 |
20 |
Correct |
2 ms |
4956 KB |
n=100 |
21 |
Correct |
1 ms |
4956 KB |
n=100 |
22 |
Correct |
1 ms |
4952 KB |
n=100 |
23 |
Correct |
3 ms |
4956 KB |
n=100 |
24 |
Correct |
3 ms |
4956 KB |
n=100 |
25 |
Correct |
1 ms |
4956 KB |
n=100 |
26 |
Correct |
2 ms |
4952 KB |
n=12 |
27 |
Correct |
2 ms |
4956 KB |
n=100 |
28 |
Correct |
2 ms |
4952 KB |
n=500 |
29 |
Correct |
22 ms |
4952 KB |
n=500 |
30 |
Correct |
17 ms |
4956 KB |
n=500 |
31 |
Correct |
19 ms |
4956 KB |
n=500 |
32 |
Correct |
2 ms |
4952 KB |
n=500 |
33 |
Correct |
16 ms |
4956 KB |
n=500 |
34 |
Correct |
2 ms |
4956 KB |
n=500 |
35 |
Correct |
19 ms |
4952 KB |
n=500 |
36 |
Correct |
110 ms |
4956 KB |
n=500 |
37 |
Correct |
118 ms |
4956 KB |
n=500 |
38 |
Correct |
109 ms |
4956 KB |
n=500 |
39 |
Correct |
37 ms |
4956 KB |
n=500 |
40 |
Correct |
39 ms |
4956 KB |
n=500 |
41 |
Correct |
37 ms |
4952 KB |
n=500 |
42 |
Correct |
65 ms |
4952 KB |
n=500 |
43 |
Correct |
56 ms |
4956 KB |
n=500 |
44 |
Correct |
57 ms |
4952 KB |
n=500 |
45 |
Correct |
2 ms |
4956 KB |
n=500 |
46 |
Correct |
21 ms |
4952 KB |
n=500 |
47 |
Correct |
17 ms |
4952 KB |
n=500 |
48 |
Correct |
1 ms |
4956 KB |
n=500 |
49 |
Correct |
17 ms |
4956 KB |
n=500 |
50 |
Correct |
23 ms |
4956 KB |
n=500 |
51 |
Correct |
29 ms |
4956 KB |
n=500 |
52 |
Correct |
37 ms |
4952 KB |
n=500 |
53 |
Correct |
30 ms |
4956 KB |
n=500 |
54 |
Correct |
25 ms |
4956 KB |
n=500 |
55 |
Correct |
4 ms |
4956 KB |
n=278 |
56 |
Correct |
132 ms |
4956 KB |
n=500 |
57 |
Correct |
137 ms |
4952 KB |
n=500 |
58 |
Correct |
67 ms |
4952 KB |
n=500 |
59 |
Correct |
7 ms |
5208 KB |
n=2000 |
60 |
Correct |
523 ms |
5356 KB |
n=2000 |
61 |
Correct |
449 ms |
5212 KB |
n=2000 |
62 |
Correct |
295 ms |
5208 KB |
n=2000 |
63 |
Correct |
10 ms |
5208 KB |
n=2000 |
64 |
Correct |
398 ms |
5272 KB |
n=2000 |
65 |
Correct |
5 ms |
5208 KB |
n=2000 |
66 |
Correct |
514 ms |
5212 KB |
n=2000 |
67 |
Correct |
22 ms |
5208 KB |
n=2000 |
68 |
Correct |
414 ms |
5292 KB |
n=2000 |
69 |
Correct |
2693 ms |
5212 KB |
n=2000 |
70 |
Correct |
2717 ms |
5228 KB |
n=2000 |
71 |
Correct |
2674 ms |
5208 KB |
n=2000 |
72 |
Correct |
921 ms |
5208 KB |
n=2000 |
73 |
Correct |
930 ms |
5212 KB |
n=2000 |
74 |
Correct |
7 ms |
5208 KB |
n=1844 |
75 |
Correct |
929 ms |
5232 KB |
n=2000 |
76 |
Correct |
1480 ms |
5212 KB |
n=2000 |
77 |
Correct |
1388 ms |
5208 KB |
n=2000 |
78 |
Correct |
1465 ms |
5208 KB |
n=2000 |
79 |
Correct |
5 ms |
5212 KB |
n=2000 |
80 |
Correct |
416 ms |
5212 KB |
n=2000 |
81 |
Correct |
364 ms |
5208 KB |
n=2000 |
82 |
Correct |
5 ms |
5212 KB |
n=2000 |
83 |
Correct |
407 ms |
5312 KB |
n=2000 |
84 |
Correct |
600 ms |
5212 KB |
n=2000 |
85 |
Correct |
703 ms |
5212 KB |
n=2000 |
86 |
Correct |
762 ms |
5208 KB |
n=2000 |
87 |
Correct |
614 ms |
5208 KB |
n=2000 |
88 |
Correct |
3818 ms |
5360 KB |
n=2000 |
89 |
Correct |
3822 ms |
5416 KB |
n=2000 |
90 |
Correct |
568 ms |
5208 KB |
n=2000 |
91 |
Correct |
1736 ms |
5212 KB |
n=2000 |
92 |
Runtime error |
42 ms |
27476 KB |
Execution killed with signal 11 |
93 |
Halted |
0 ms |
0 KB |
- |