/* Speech to the young */
//#include <bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>
#include <unordered_map>
/*
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse,-fgcse-lm")
#pragma GCC optimize("-ftree-pre,-ftree-vrp")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
*/
using namespace std;
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define YOSIK() ios_base::sync_with_stdio(0),cin.tie(0)
#define int long long
#define cube (x) ((x) * (x) * (x))
int gcd (int a, int b) {if (b == 0){return a;}else {return gcd (b, a % b);}}
void pre(int a) { cout<<fixed<<setprecision(a); }
int bitcount (int x) {return __builtin_popcount (x);}
const int N = 2e6 + 10;
const int INF = 1e18 + 1;
const int MOD = 1e9 + 7;
const int P = 31;
const double eps = 1e-19;
long double pi = 3.1415926535897323;
int n, m, q, depth[2005], up[2005][20], a[2005];
vector <int> g[2005];
void dfs (int v, int p) {
up[v][0] = p;
for (int i = 1; i <= 15; ++ i) up[v][i] = up[up[v][i - 1]][i - 1];
for (auto to: g[v]) {
if (to != p) {
depth[to] = depth[v] + 1;
dfs (to, v);
}
}
return;
}
int lca (int a, int b) {
if (depth[a] < depth[b]) swap (a, b);
int k = depth[a] - depth[b];
for (int i = 15; i >= 0; -- i) if (((k >> i) & 1)) a = up[a][i];
if (a == b) return a;
for (int i = 15; i >= 0; -- i) {
if (up[a][i] != up[b][i]) {
a = up[a][i], b = up[b][i];
}
}
return up[a][0];
}
void Solution () {
cin >> n >> m >> q;
int x, y;
for (int i = 1; i < n; ++ i) {
cin >> x >> y;
g[x].pb (y), g[y].pb (x);
}
dfs (1, 0);
for (int i = 1; i <= m; ++ i) cin >> a[i];
while (q --) {
int tp, l, r, v, pos;
cin >> tp;
if (tp == 1) {
cin >> pos >> v;
a[pos] = v;
} else {
cin >> l >> r >> v;
pair <int, int> ans;
for (int i = l; i <= r; ++ i) {
int x = a[i];
if (x == v) {
ans = {i, i};
break;
}
for (int j = i; j <= r; ++ j) {
x = lca (x, a[j]);
if (x == v) {
ans = {i, j};
}
}
}
if (ans.F == 0 && ans.S == 0) {
cout << "-1 -1\n";
} else cout << ans.F << ' ' << ans.S << '\n';
}
}
}
signed main () {
YOSIK();
// precalc();
int T = 1;
// cin >> T;
while (T --) Solution ();
exit (0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
n=5 |
2 |
Correct |
2 ms |
340 KB |
n=100 |
3 |
Correct |
5 ms |
380 KB |
n=100 |
4 |
Correct |
2 ms |
376 KB |
n=100 |
5 |
Correct |
2 ms |
372 KB |
n=100 |
6 |
Correct |
13 ms |
380 KB |
n=100 |
7 |
Correct |
14 ms |
400 KB |
n=100 |
8 |
Correct |
2 ms |
340 KB |
n=100 |
9 |
Correct |
2 ms |
340 KB |
n=100 |
10 |
Correct |
8 ms |
400 KB |
n=100 |
11 |
Correct |
8 ms |
340 KB |
n=100 |
12 |
Correct |
1 ms |
340 KB |
n=100 |
13 |
Correct |
2 ms |
372 KB |
n=100 |
14 |
Correct |
1 ms |
340 KB |
n=100 |
15 |
Correct |
1 ms |
340 KB |
n=100 |
16 |
Correct |
4 ms |
376 KB |
n=100 |
17 |
Correct |
2 ms |
340 KB |
n=100 |
18 |
Correct |
2 ms |
340 KB |
n=100 |
19 |
Correct |
2 ms |
340 KB |
n=100 |
20 |
Correct |
2 ms |
340 KB |
n=100 |
21 |
Correct |
2 ms |
340 KB |
n=100 |
22 |
Correct |
2 ms |
376 KB |
n=100 |
23 |
Correct |
3 ms |
372 KB |
n=100 |
24 |
Correct |
4 ms |
340 KB |
n=100 |
25 |
Correct |
6 ms |
380 KB |
n=100 |
26 |
Correct |
1 ms |
368 KB |
n=12 |
27 |
Correct |
5 ms |
376 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
n=5 |
2 |
Correct |
2 ms |
340 KB |
n=100 |
3 |
Correct |
5 ms |
380 KB |
n=100 |
4 |
Correct |
2 ms |
376 KB |
n=100 |
5 |
Correct |
2 ms |
372 KB |
n=100 |
6 |
Correct |
13 ms |
380 KB |
n=100 |
7 |
Correct |
14 ms |
400 KB |
n=100 |
8 |
Correct |
2 ms |
340 KB |
n=100 |
9 |
Correct |
2 ms |
340 KB |
n=100 |
10 |
Correct |
8 ms |
400 KB |
n=100 |
11 |
Correct |
8 ms |
340 KB |
n=100 |
12 |
Correct |
1 ms |
340 KB |
n=100 |
13 |
Correct |
2 ms |
372 KB |
n=100 |
14 |
Correct |
1 ms |
340 KB |
n=100 |
15 |
Correct |
1 ms |
340 KB |
n=100 |
16 |
Correct |
4 ms |
376 KB |
n=100 |
17 |
Correct |
2 ms |
340 KB |
n=100 |
18 |
Correct |
2 ms |
340 KB |
n=100 |
19 |
Correct |
2 ms |
340 KB |
n=100 |
20 |
Correct |
2 ms |
340 KB |
n=100 |
21 |
Correct |
2 ms |
340 KB |
n=100 |
22 |
Correct |
2 ms |
376 KB |
n=100 |
23 |
Correct |
3 ms |
372 KB |
n=100 |
24 |
Correct |
4 ms |
340 KB |
n=100 |
25 |
Correct |
6 ms |
380 KB |
n=100 |
26 |
Correct |
1 ms |
368 KB |
n=12 |
27 |
Correct |
5 ms |
376 KB |
n=100 |
28 |
Correct |
104 ms |
480 KB |
n=500 |
29 |
Correct |
176 ms |
500 KB |
n=500 |
30 |
Correct |
156 ms |
468 KB |
n=500 |
31 |
Correct |
173 ms |
496 KB |
n=500 |
32 |
Correct |
152 ms |
476 KB |
n=500 |
33 |
Correct |
178 ms |
488 KB |
n=500 |
34 |
Correct |
134 ms |
476 KB |
n=500 |
35 |
Correct |
153 ms |
500 KB |
n=500 |
36 |
Correct |
1687 ms |
484 KB |
n=500 |
37 |
Correct |
1684 ms |
480 KB |
n=500 |
38 |
Correct |
1781 ms |
608 KB |
n=500 |
39 |
Correct |
149 ms |
732 KB |
n=500 |
40 |
Correct |
135 ms |
392 KB |
n=500 |
41 |
Correct |
136 ms |
484 KB |
n=500 |
42 |
Correct |
825 ms |
480 KB |
n=500 |
43 |
Correct |
883 ms |
476 KB |
n=500 |
44 |
Correct |
885 ms |
476 KB |
n=500 |
45 |
Correct |
40 ms |
468 KB |
n=500 |
46 |
Correct |
161 ms |
512 KB |
n=500 |
47 |
Correct |
129 ms |
492 KB |
n=500 |
48 |
Correct |
11 ms |
384 KB |
n=500 |
49 |
Correct |
124 ms |
512 KB |
n=500 |
50 |
Correct |
96 ms |
468 KB |
n=500 |
51 |
Correct |
217 ms |
488 KB |
n=500 |
52 |
Correct |
268 ms |
500 KB |
n=500 |
53 |
Correct |
213 ms |
492 KB |
n=500 |
54 |
Correct |
917 ms |
496 KB |
n=500 |
55 |
Correct |
48 ms |
340 KB |
n=278 |
56 |
Correct |
1000 ms |
496 KB |
n=500 |
57 |
Correct |
1026 ms |
496 KB |
n=500 |
58 |
Correct |
560 ms |
616 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
n=5 |
2 |
Correct |
2 ms |
340 KB |
n=100 |
3 |
Correct |
5 ms |
380 KB |
n=100 |
4 |
Correct |
2 ms |
376 KB |
n=100 |
5 |
Correct |
2 ms |
372 KB |
n=100 |
6 |
Correct |
13 ms |
380 KB |
n=100 |
7 |
Correct |
14 ms |
400 KB |
n=100 |
8 |
Correct |
2 ms |
340 KB |
n=100 |
9 |
Correct |
2 ms |
340 KB |
n=100 |
10 |
Correct |
8 ms |
400 KB |
n=100 |
11 |
Correct |
8 ms |
340 KB |
n=100 |
12 |
Correct |
1 ms |
340 KB |
n=100 |
13 |
Correct |
2 ms |
372 KB |
n=100 |
14 |
Correct |
1 ms |
340 KB |
n=100 |
15 |
Correct |
1 ms |
340 KB |
n=100 |
16 |
Correct |
4 ms |
376 KB |
n=100 |
17 |
Correct |
2 ms |
340 KB |
n=100 |
18 |
Correct |
2 ms |
340 KB |
n=100 |
19 |
Correct |
2 ms |
340 KB |
n=100 |
20 |
Correct |
2 ms |
340 KB |
n=100 |
21 |
Correct |
2 ms |
340 KB |
n=100 |
22 |
Correct |
2 ms |
376 KB |
n=100 |
23 |
Correct |
3 ms |
372 KB |
n=100 |
24 |
Correct |
4 ms |
340 KB |
n=100 |
25 |
Correct |
6 ms |
380 KB |
n=100 |
26 |
Correct |
1 ms |
368 KB |
n=12 |
27 |
Correct |
5 ms |
376 KB |
n=100 |
28 |
Correct |
104 ms |
480 KB |
n=500 |
29 |
Correct |
176 ms |
500 KB |
n=500 |
30 |
Correct |
156 ms |
468 KB |
n=500 |
31 |
Correct |
173 ms |
496 KB |
n=500 |
32 |
Correct |
152 ms |
476 KB |
n=500 |
33 |
Correct |
178 ms |
488 KB |
n=500 |
34 |
Correct |
134 ms |
476 KB |
n=500 |
35 |
Correct |
153 ms |
500 KB |
n=500 |
36 |
Correct |
1687 ms |
484 KB |
n=500 |
37 |
Correct |
1684 ms |
480 KB |
n=500 |
38 |
Correct |
1781 ms |
608 KB |
n=500 |
39 |
Correct |
149 ms |
732 KB |
n=500 |
40 |
Correct |
135 ms |
392 KB |
n=500 |
41 |
Correct |
136 ms |
484 KB |
n=500 |
42 |
Correct |
825 ms |
480 KB |
n=500 |
43 |
Correct |
883 ms |
476 KB |
n=500 |
44 |
Correct |
885 ms |
476 KB |
n=500 |
45 |
Correct |
40 ms |
468 KB |
n=500 |
46 |
Correct |
161 ms |
512 KB |
n=500 |
47 |
Correct |
129 ms |
492 KB |
n=500 |
48 |
Correct |
11 ms |
384 KB |
n=500 |
49 |
Correct |
124 ms |
512 KB |
n=500 |
50 |
Correct |
96 ms |
468 KB |
n=500 |
51 |
Correct |
217 ms |
488 KB |
n=500 |
52 |
Correct |
268 ms |
500 KB |
n=500 |
53 |
Correct |
213 ms |
492 KB |
n=500 |
54 |
Correct |
917 ms |
496 KB |
n=500 |
55 |
Correct |
48 ms |
340 KB |
n=278 |
56 |
Correct |
1000 ms |
496 KB |
n=500 |
57 |
Correct |
1026 ms |
496 KB |
n=500 |
58 |
Correct |
560 ms |
616 KB |
n=500 |
59 |
Correct |
3985 ms |
836 KB |
n=2000 |
60 |
Execution timed out |
4050 ms |
904 KB |
Time limit exceeded |
61 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
n=5 |
2 |
Correct |
2 ms |
340 KB |
n=100 |
3 |
Correct |
5 ms |
380 KB |
n=100 |
4 |
Correct |
2 ms |
376 KB |
n=100 |
5 |
Correct |
2 ms |
372 KB |
n=100 |
6 |
Correct |
13 ms |
380 KB |
n=100 |
7 |
Correct |
14 ms |
400 KB |
n=100 |
8 |
Correct |
2 ms |
340 KB |
n=100 |
9 |
Correct |
2 ms |
340 KB |
n=100 |
10 |
Correct |
8 ms |
400 KB |
n=100 |
11 |
Correct |
8 ms |
340 KB |
n=100 |
12 |
Correct |
1 ms |
340 KB |
n=100 |
13 |
Correct |
2 ms |
372 KB |
n=100 |
14 |
Correct |
1 ms |
340 KB |
n=100 |
15 |
Correct |
1 ms |
340 KB |
n=100 |
16 |
Correct |
4 ms |
376 KB |
n=100 |
17 |
Correct |
2 ms |
340 KB |
n=100 |
18 |
Correct |
2 ms |
340 KB |
n=100 |
19 |
Correct |
2 ms |
340 KB |
n=100 |
20 |
Correct |
2 ms |
340 KB |
n=100 |
21 |
Correct |
2 ms |
340 KB |
n=100 |
22 |
Correct |
2 ms |
376 KB |
n=100 |
23 |
Correct |
3 ms |
372 KB |
n=100 |
24 |
Correct |
4 ms |
340 KB |
n=100 |
25 |
Correct |
6 ms |
380 KB |
n=100 |
26 |
Correct |
1 ms |
368 KB |
n=12 |
27 |
Correct |
5 ms |
376 KB |
n=100 |
28 |
Correct |
104 ms |
480 KB |
n=500 |
29 |
Correct |
176 ms |
500 KB |
n=500 |
30 |
Correct |
156 ms |
468 KB |
n=500 |
31 |
Correct |
173 ms |
496 KB |
n=500 |
32 |
Correct |
152 ms |
476 KB |
n=500 |
33 |
Correct |
178 ms |
488 KB |
n=500 |
34 |
Correct |
134 ms |
476 KB |
n=500 |
35 |
Correct |
153 ms |
500 KB |
n=500 |
36 |
Correct |
1687 ms |
484 KB |
n=500 |
37 |
Correct |
1684 ms |
480 KB |
n=500 |
38 |
Correct |
1781 ms |
608 KB |
n=500 |
39 |
Correct |
149 ms |
732 KB |
n=500 |
40 |
Correct |
135 ms |
392 KB |
n=500 |
41 |
Correct |
136 ms |
484 KB |
n=500 |
42 |
Correct |
825 ms |
480 KB |
n=500 |
43 |
Correct |
883 ms |
476 KB |
n=500 |
44 |
Correct |
885 ms |
476 KB |
n=500 |
45 |
Correct |
40 ms |
468 KB |
n=500 |
46 |
Correct |
161 ms |
512 KB |
n=500 |
47 |
Correct |
129 ms |
492 KB |
n=500 |
48 |
Correct |
11 ms |
384 KB |
n=500 |
49 |
Correct |
124 ms |
512 KB |
n=500 |
50 |
Correct |
96 ms |
468 KB |
n=500 |
51 |
Correct |
217 ms |
488 KB |
n=500 |
52 |
Correct |
268 ms |
500 KB |
n=500 |
53 |
Correct |
213 ms |
492 KB |
n=500 |
54 |
Correct |
917 ms |
496 KB |
n=500 |
55 |
Correct |
48 ms |
340 KB |
n=278 |
56 |
Correct |
1000 ms |
496 KB |
n=500 |
57 |
Correct |
1026 ms |
496 KB |
n=500 |
58 |
Correct |
560 ms |
616 KB |
n=500 |
59 |
Correct |
3985 ms |
836 KB |
n=2000 |
60 |
Execution timed out |
4050 ms |
904 KB |
Time limit exceeded |
61 |
Halted |
0 ms |
0 KB |
- |