//-------------dilanyan------------\\
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
//------------------KarginDefines--------------------\\
#define ll long long
#define pb push_back
#define all(u) (u).begin(), (u).end()
#define pqueue priority_queue
#define upper upper_bound
#define lower lower_bound
#define umap unordered_map
#define uset unordered_set
#define Kargin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Usaco freopen(".in", "r", stdin); freopen(".out", "w", stdout);
//-------------------KarginConstants------------------\\
const ll mod = 1000000007;
const ll inf = 1e9 + 15;
//-------------------KarginCode------------------------\\
const int N = 100005;
int a[N];
vector<int> g[N];
int tin[N], tout[N], tim = 0;
int up[N][20];
void dfs(int u, int p) {
tin[u] = tim++;
up[u][0] = p;
for (int v : g[u]) {
if (v != p) dfs(v, u);
}
tout[u] = tim;
}
bool anc(int u, int v) {
return tin[u] <= tin[v] && tout[u] >= tout[v];
}
int lca(int x, int y) {
if (anc(x, y)) return x;
if (anc(y, x)) return y;
for (int i = 19;i >= 0;i--) {
if (!anc(up[x][i], y)) x = up[x][i];
}
return up[x][0];
}
void KarginSolve() {
int n, m, q;
cin >> n >> m >> q;
for (int i = 0;i < n - 1;i++) {
int u, v;
cin >> u >> v;
g[u].pb(v), g[v].pb(u);
}
for (int i = 1;i <= m;i++) cin >> a[i];
dfs(1, 1);
for (int j = 1;j < 20;j++) {
for (int i = 1;i <= n;i++) {
up[i][j] = up[up[i][j - 1]][j - 1];
}
}
while (q--) {
int t; cin >> t;
if (t == 1) {
int pos, v;
cin >> pos >> v;
a[pos] = v;
}
else {
int l, r, v;
cin >> l >> r >> v;
int x = -1, y = -1;
for (int i = l;i <= r;i++) {
if (a[i] == v) {
x = y = i;
break;
}
int h = a[i];
for (int j = i + 1;j <= r;j++) {
h = lca(h, a[j]);
if (h == v) {
x = i, y = j;
break;
}
}
if (x != -1) break;
}
cout << x << ' ' << y << '\n';
}
}
}
int main() {
Kargin;
int test = 1;
//cin >> test;
while (test--) {
KarginSolve();
}
return 0;
}
Compilation message
treearray.cpp:1:1: warning: multi-line comment [-Wcomment]
1 | //-------------dilanyan------------\\
| ^
treearray.cpp:8:1: warning: multi-line comment [-Wcomment]
8 | //------------------KarginDefines--------------------\\
| ^
treearray.cpp:22:1: warning: multi-line comment [-Wcomment]
22 | //-------------------KarginConstants------------------\\
| ^
treearray.cpp:27:1: warning: multi-line comment [-Wcomment]
27 | //-------------------KarginCode------------------------\\
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2908 KB |
n=5 |
2 |
Correct |
1 ms |
2908 KB |
n=100 |
3 |
Correct |
1 ms |
2908 KB |
n=100 |
4 |
Correct |
1 ms |
2908 KB |
n=100 |
5 |
Correct |
1 ms |
2904 KB |
n=100 |
6 |
Correct |
2 ms |
2904 KB |
n=100 |
7 |
Correct |
2 ms |
2908 KB |
n=100 |
8 |
Correct |
1 ms |
2908 KB |
n=100 |
9 |
Correct |
1 ms |
3032 KB |
n=100 |
10 |
Correct |
2 ms |
2908 KB |
n=100 |
11 |
Correct |
2 ms |
2908 KB |
n=100 |
12 |
Correct |
1 ms |
3172 KB |
n=100 |
13 |
Correct |
1 ms |
2904 KB |
n=100 |
14 |
Correct |
1 ms |
2908 KB |
n=100 |
15 |
Correct |
1 ms |
2904 KB |
n=100 |
16 |
Correct |
2 ms |
2908 KB |
n=100 |
17 |
Correct |
1 ms |
2908 KB |
n=100 |
18 |
Correct |
1 ms |
2908 KB |
n=100 |
19 |
Correct |
1 ms |
2904 KB |
n=100 |
20 |
Correct |
1 ms |
2908 KB |
n=100 |
21 |
Correct |
2 ms |
3164 KB |
n=100 |
22 |
Correct |
1 ms |
2908 KB |
n=100 |
23 |
Correct |
1 ms |
2908 KB |
n=100 |
24 |
Correct |
1 ms |
2908 KB |
n=100 |
25 |
Correct |
1 ms |
2908 KB |
n=100 |
26 |
Correct |
1 ms |
2908 KB |
n=12 |
27 |
Correct |
2 ms |
3032 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2908 KB |
n=5 |
2 |
Correct |
1 ms |
2908 KB |
n=100 |
3 |
Correct |
1 ms |
2908 KB |
n=100 |
4 |
Correct |
1 ms |
2908 KB |
n=100 |
5 |
Correct |
1 ms |
2904 KB |
n=100 |
6 |
Correct |
2 ms |
2904 KB |
n=100 |
7 |
Correct |
2 ms |
2908 KB |
n=100 |
8 |
Correct |
1 ms |
2908 KB |
n=100 |
9 |
Correct |
1 ms |
3032 KB |
n=100 |
10 |
Correct |
2 ms |
2908 KB |
n=100 |
11 |
Correct |
2 ms |
2908 KB |
n=100 |
12 |
Correct |
1 ms |
3172 KB |
n=100 |
13 |
Correct |
1 ms |
2904 KB |
n=100 |
14 |
Correct |
1 ms |
2908 KB |
n=100 |
15 |
Correct |
1 ms |
2904 KB |
n=100 |
16 |
Correct |
2 ms |
2908 KB |
n=100 |
17 |
Correct |
1 ms |
2908 KB |
n=100 |
18 |
Correct |
1 ms |
2908 KB |
n=100 |
19 |
Correct |
1 ms |
2904 KB |
n=100 |
20 |
Correct |
1 ms |
2908 KB |
n=100 |
21 |
Correct |
2 ms |
3164 KB |
n=100 |
22 |
Correct |
1 ms |
2908 KB |
n=100 |
23 |
Correct |
1 ms |
2908 KB |
n=100 |
24 |
Correct |
1 ms |
2908 KB |
n=100 |
25 |
Correct |
1 ms |
2908 KB |
n=100 |
26 |
Correct |
1 ms |
2908 KB |
n=12 |
27 |
Correct |
2 ms |
3032 KB |
n=100 |
28 |
Correct |
2 ms |
2904 KB |
n=500 |
29 |
Correct |
12 ms |
2908 KB |
n=500 |
30 |
Correct |
10 ms |
2908 KB |
n=500 |
31 |
Correct |
12 ms |
2904 KB |
n=500 |
32 |
Correct |
2 ms |
2904 KB |
n=500 |
33 |
Correct |
10 ms |
2908 KB |
n=500 |
34 |
Correct |
1 ms |
2908 KB |
n=500 |
35 |
Correct |
10 ms |
2908 KB |
n=500 |
36 |
Correct |
117 ms |
3100 KB |
n=500 |
37 |
Correct |
116 ms |
3352 KB |
n=500 |
38 |
Correct |
116 ms |
2908 KB |
n=500 |
39 |
Correct |
20 ms |
2904 KB |
n=500 |
40 |
Correct |
19 ms |
2908 KB |
n=500 |
41 |
Correct |
19 ms |
2904 KB |
n=500 |
42 |
Correct |
59 ms |
2908 KB |
n=500 |
43 |
Correct |
66 ms |
3156 KB |
n=500 |
44 |
Correct |
57 ms |
2908 KB |
n=500 |
45 |
Correct |
1 ms |
2904 KB |
n=500 |
46 |
Correct |
11 ms |
2904 KB |
n=500 |
47 |
Correct |
9 ms |
2908 KB |
n=500 |
48 |
Correct |
1 ms |
2908 KB |
n=500 |
49 |
Correct |
9 ms |
2908 KB |
n=500 |
50 |
Correct |
16 ms |
2908 KB |
n=500 |
51 |
Correct |
17 ms |
2908 KB |
n=500 |
52 |
Correct |
18 ms |
3136 KB |
n=500 |
53 |
Correct |
18 ms |
2908 KB |
n=500 |
54 |
Correct |
8 ms |
2908 KB |
n=500 |
55 |
Correct |
3 ms |
2908 KB |
n=278 |
56 |
Correct |
59 ms |
3040 KB |
n=500 |
57 |
Correct |
61 ms |
2904 KB |
n=500 |
58 |
Correct |
55 ms |
2908 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2908 KB |
n=5 |
2 |
Correct |
1 ms |
2908 KB |
n=100 |
3 |
Correct |
1 ms |
2908 KB |
n=100 |
4 |
Correct |
1 ms |
2908 KB |
n=100 |
5 |
Correct |
1 ms |
2904 KB |
n=100 |
6 |
Correct |
2 ms |
2904 KB |
n=100 |
7 |
Correct |
2 ms |
2908 KB |
n=100 |
8 |
Correct |
1 ms |
2908 KB |
n=100 |
9 |
Correct |
1 ms |
3032 KB |
n=100 |
10 |
Correct |
2 ms |
2908 KB |
n=100 |
11 |
Correct |
2 ms |
2908 KB |
n=100 |
12 |
Correct |
1 ms |
3172 KB |
n=100 |
13 |
Correct |
1 ms |
2904 KB |
n=100 |
14 |
Correct |
1 ms |
2908 KB |
n=100 |
15 |
Correct |
1 ms |
2904 KB |
n=100 |
16 |
Correct |
2 ms |
2908 KB |
n=100 |
17 |
Correct |
1 ms |
2908 KB |
n=100 |
18 |
Correct |
1 ms |
2908 KB |
n=100 |
19 |
Correct |
1 ms |
2904 KB |
n=100 |
20 |
Correct |
1 ms |
2908 KB |
n=100 |
21 |
Correct |
2 ms |
3164 KB |
n=100 |
22 |
Correct |
1 ms |
2908 KB |
n=100 |
23 |
Correct |
1 ms |
2908 KB |
n=100 |
24 |
Correct |
1 ms |
2908 KB |
n=100 |
25 |
Correct |
1 ms |
2908 KB |
n=100 |
26 |
Correct |
1 ms |
2908 KB |
n=12 |
27 |
Correct |
2 ms |
3032 KB |
n=100 |
28 |
Correct |
2 ms |
2904 KB |
n=500 |
29 |
Correct |
12 ms |
2908 KB |
n=500 |
30 |
Correct |
10 ms |
2908 KB |
n=500 |
31 |
Correct |
12 ms |
2904 KB |
n=500 |
32 |
Correct |
2 ms |
2904 KB |
n=500 |
33 |
Correct |
10 ms |
2908 KB |
n=500 |
34 |
Correct |
1 ms |
2908 KB |
n=500 |
35 |
Correct |
10 ms |
2908 KB |
n=500 |
36 |
Correct |
117 ms |
3100 KB |
n=500 |
37 |
Correct |
116 ms |
3352 KB |
n=500 |
38 |
Correct |
116 ms |
2908 KB |
n=500 |
39 |
Correct |
20 ms |
2904 KB |
n=500 |
40 |
Correct |
19 ms |
2908 KB |
n=500 |
41 |
Correct |
19 ms |
2904 KB |
n=500 |
42 |
Correct |
59 ms |
2908 KB |
n=500 |
43 |
Correct |
66 ms |
3156 KB |
n=500 |
44 |
Correct |
57 ms |
2908 KB |
n=500 |
45 |
Correct |
1 ms |
2904 KB |
n=500 |
46 |
Correct |
11 ms |
2904 KB |
n=500 |
47 |
Correct |
9 ms |
2908 KB |
n=500 |
48 |
Correct |
1 ms |
2908 KB |
n=500 |
49 |
Correct |
9 ms |
2908 KB |
n=500 |
50 |
Correct |
16 ms |
2908 KB |
n=500 |
51 |
Correct |
17 ms |
2908 KB |
n=500 |
52 |
Correct |
18 ms |
3136 KB |
n=500 |
53 |
Correct |
18 ms |
2908 KB |
n=500 |
54 |
Correct |
8 ms |
2908 KB |
n=500 |
55 |
Correct |
3 ms |
2908 KB |
n=278 |
56 |
Correct |
59 ms |
3040 KB |
n=500 |
57 |
Correct |
61 ms |
2904 KB |
n=500 |
58 |
Correct |
55 ms |
2908 KB |
n=500 |
59 |
Correct |
9 ms |
3164 KB |
n=2000 |
60 |
Correct |
570 ms |
3420 KB |
n=2000 |
61 |
Correct |
548 ms |
3372 KB |
n=2000 |
62 |
Correct |
394 ms |
3356 KB |
n=2000 |
63 |
Correct |
13 ms |
3164 KB |
n=2000 |
64 |
Correct |
500 ms |
3360 KB |
n=2000 |
65 |
Correct |
3 ms |
3160 KB |
n=2000 |
66 |
Correct |
634 ms |
3396 KB |
n=2000 |
67 |
Correct |
30 ms |
3164 KB |
n=2000 |
68 |
Correct |
523 ms |
3364 KB |
n=2000 |
69 |
Execution timed out |
4034 ms |
3320 KB |
Time limit exceeded |
70 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2908 KB |
n=5 |
2 |
Correct |
1 ms |
2908 KB |
n=100 |
3 |
Correct |
1 ms |
2908 KB |
n=100 |
4 |
Correct |
1 ms |
2908 KB |
n=100 |
5 |
Correct |
1 ms |
2904 KB |
n=100 |
6 |
Correct |
2 ms |
2904 KB |
n=100 |
7 |
Correct |
2 ms |
2908 KB |
n=100 |
8 |
Correct |
1 ms |
2908 KB |
n=100 |
9 |
Correct |
1 ms |
3032 KB |
n=100 |
10 |
Correct |
2 ms |
2908 KB |
n=100 |
11 |
Correct |
2 ms |
2908 KB |
n=100 |
12 |
Correct |
1 ms |
3172 KB |
n=100 |
13 |
Correct |
1 ms |
2904 KB |
n=100 |
14 |
Correct |
1 ms |
2908 KB |
n=100 |
15 |
Correct |
1 ms |
2904 KB |
n=100 |
16 |
Correct |
2 ms |
2908 KB |
n=100 |
17 |
Correct |
1 ms |
2908 KB |
n=100 |
18 |
Correct |
1 ms |
2908 KB |
n=100 |
19 |
Correct |
1 ms |
2904 KB |
n=100 |
20 |
Correct |
1 ms |
2908 KB |
n=100 |
21 |
Correct |
2 ms |
3164 KB |
n=100 |
22 |
Correct |
1 ms |
2908 KB |
n=100 |
23 |
Correct |
1 ms |
2908 KB |
n=100 |
24 |
Correct |
1 ms |
2908 KB |
n=100 |
25 |
Correct |
1 ms |
2908 KB |
n=100 |
26 |
Correct |
1 ms |
2908 KB |
n=12 |
27 |
Correct |
2 ms |
3032 KB |
n=100 |
28 |
Correct |
2 ms |
2904 KB |
n=500 |
29 |
Correct |
12 ms |
2908 KB |
n=500 |
30 |
Correct |
10 ms |
2908 KB |
n=500 |
31 |
Correct |
12 ms |
2904 KB |
n=500 |
32 |
Correct |
2 ms |
2904 KB |
n=500 |
33 |
Correct |
10 ms |
2908 KB |
n=500 |
34 |
Correct |
1 ms |
2908 KB |
n=500 |
35 |
Correct |
10 ms |
2908 KB |
n=500 |
36 |
Correct |
117 ms |
3100 KB |
n=500 |
37 |
Correct |
116 ms |
3352 KB |
n=500 |
38 |
Correct |
116 ms |
2908 KB |
n=500 |
39 |
Correct |
20 ms |
2904 KB |
n=500 |
40 |
Correct |
19 ms |
2908 KB |
n=500 |
41 |
Correct |
19 ms |
2904 KB |
n=500 |
42 |
Correct |
59 ms |
2908 KB |
n=500 |
43 |
Correct |
66 ms |
3156 KB |
n=500 |
44 |
Correct |
57 ms |
2908 KB |
n=500 |
45 |
Correct |
1 ms |
2904 KB |
n=500 |
46 |
Correct |
11 ms |
2904 KB |
n=500 |
47 |
Correct |
9 ms |
2908 KB |
n=500 |
48 |
Correct |
1 ms |
2908 KB |
n=500 |
49 |
Correct |
9 ms |
2908 KB |
n=500 |
50 |
Correct |
16 ms |
2908 KB |
n=500 |
51 |
Correct |
17 ms |
2908 KB |
n=500 |
52 |
Correct |
18 ms |
3136 KB |
n=500 |
53 |
Correct |
18 ms |
2908 KB |
n=500 |
54 |
Correct |
8 ms |
2908 KB |
n=500 |
55 |
Correct |
3 ms |
2908 KB |
n=278 |
56 |
Correct |
59 ms |
3040 KB |
n=500 |
57 |
Correct |
61 ms |
2904 KB |
n=500 |
58 |
Correct |
55 ms |
2908 KB |
n=500 |
59 |
Correct |
9 ms |
3164 KB |
n=2000 |
60 |
Correct |
570 ms |
3420 KB |
n=2000 |
61 |
Correct |
548 ms |
3372 KB |
n=2000 |
62 |
Correct |
394 ms |
3356 KB |
n=2000 |
63 |
Correct |
13 ms |
3164 KB |
n=2000 |
64 |
Correct |
500 ms |
3360 KB |
n=2000 |
65 |
Correct |
3 ms |
3160 KB |
n=2000 |
66 |
Correct |
634 ms |
3396 KB |
n=2000 |
67 |
Correct |
30 ms |
3164 KB |
n=2000 |
68 |
Correct |
523 ms |
3364 KB |
n=2000 |
69 |
Execution timed out |
4034 ms |
3320 KB |
Time limit exceeded |
70 |
Halted |
0 ms |
0 KB |
- |