Submission #495936

# Submission time Handle Problem Language Result Execution time Memory
495936 2021-12-20T08:15:35 Z Mukhitali Birthday gift (IZhO18_treearray) C++17
30 / 100
4000 ms 5452 KB
//bit chass 1
#include <bits/stdc++.h>

#define x first
#define y second
#define el "\n"
#define ll long long
#define pb push_back
#define pll pair <ll, ll>
#define pii pair <int, int>
#define all(x) x.begin(), x.end()
#define lcm(x,y) x * y / __gcd(x, y)
#define ibase ios_base::sync_with_stdio(0), cin.tie(0)

using namespace std;

const int N = 2e5 + 5, inf = 1e9 + 7, M = 2e6, MM = 2e6 + 5, K = 300;
const ll MI = 2e18;
const double P = 3.14;

int a[N], tim, tin[N], tout[N], u[N][25];
vector <int> g[N];

void dfs(int v, int pr) {
	tin[v] = tim++;
	u[v][0] = pr;
	for (int i = 1; i <= 24; i++)
		u[v][i] = u[u[v][i - 1]][i - 1];
	for (int to : g[v]) {
		if (to != pr)
			dfs(to, v);
	}
	tout[v] = tim++;
}

bool up(int x, int y) {
	if (tin[x] <= tin[y] && tin[y] <= tout[x])
		return 1;
	return 0;
}

int lca(int x, int y) {
	if (up(x, y))
		return x;
	if (up(y, x))
		return y;
	for (int i = 24; i >= 0; i--) {
		if (u[x][i] != 0 && !up(u[x][i], y))
			x = u[x][i];
	}
	return u[x][0];
}

void solve() {
	int n, m, q;
	cin >> n >> m >> q;
	for (int i = 1, x, y; i < n; i++) {
		cin >> x >> y;
		g[x].pb(y);
		g[y].pb(x);
	}
	tim = 1;
	dfs(1, 0);
	tout[0] = N;
	for (int i = 1; i <= m; i++)
		cin >> a[i];
//	cout << lca(2, 4) << el;
	while (q--) {
		int tp;
		cin >> tp;
		if (tp == 1) {
			int pos, v;
			cin >> pos >> v;
			a[pos] = v;
		}
		else {
			int l, r, v;
			bool ok = 0;
			cin >> l >> r >> v;
			for (int i = l; i <= r; i++) {
				int lc = a[i];
				for (int j = i; j <= r; j++) {
					if (!up(v, a[j]))
						break;
					lc = lca(a[j], lc);
					if (lc == v) {
						cout << i << ' ' << j << el;
						ok = 1;
						break;
					}
				}
				if (ok)
					break;
			}
			if (!ok)
				cout << "-1 -1" << el;
		}
	}
}

int main() {
	ibase;
	int T = 1;
//	cin >> T;
	for (int i = 1; i <= T; i++) {
//		cout << "Case " << i << ": ";
		solve();
		cout << el;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB n=5
2 Correct 3 ms 4940 KB n=100
3 Correct 3 ms 4940 KB n=100
4 Correct 3 ms 4940 KB n=100
5 Correct 3 ms 4940 KB n=100
6 Correct 2 ms 4940 KB n=100
7 Correct 3 ms 4940 KB n=100
8 Correct 4 ms 4940 KB n=100
9 Correct 3 ms 4940 KB n=100
10 Correct 3 ms 4940 KB n=100
11 Correct 4 ms 4940 KB n=100
12 Correct 3 ms 4940 KB n=100
13 Correct 3 ms 4940 KB n=100
14 Correct 3 ms 4940 KB n=100
15 Correct 2 ms 4940 KB n=100
16 Correct 4 ms 4940 KB n=100
17 Correct 3 ms 4940 KB n=100
18 Correct 3 ms 4940 KB n=100
19 Correct 3 ms 5032 KB n=100
20 Correct 3 ms 4940 KB n=100
21 Correct 3 ms 4940 KB n=100
22 Correct 3 ms 4940 KB n=100
23 Correct 3 ms 4940 KB n=100
24 Correct 3 ms 4940 KB n=100
25 Correct 3 ms 4940 KB n=100
26 Correct 3 ms 4940 KB n=12
27 Correct 3 ms 4940 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB n=5
2 Correct 3 ms 4940 KB n=100
3 Correct 3 ms 4940 KB n=100
4 Correct 3 ms 4940 KB n=100
5 Correct 3 ms 4940 KB n=100
6 Correct 2 ms 4940 KB n=100
7 Correct 3 ms 4940 KB n=100
8 Correct 4 ms 4940 KB n=100
9 Correct 3 ms 4940 KB n=100
10 Correct 3 ms 4940 KB n=100
11 Correct 4 ms 4940 KB n=100
12 Correct 3 ms 4940 KB n=100
13 Correct 3 ms 4940 KB n=100
14 Correct 3 ms 4940 KB n=100
15 Correct 2 ms 4940 KB n=100
16 Correct 4 ms 4940 KB n=100
17 Correct 3 ms 4940 KB n=100
18 Correct 3 ms 4940 KB n=100
19 Correct 3 ms 5032 KB n=100
20 Correct 3 ms 4940 KB n=100
21 Correct 3 ms 4940 KB n=100
22 Correct 3 ms 4940 KB n=100
23 Correct 3 ms 4940 KB n=100
24 Correct 3 ms 4940 KB n=100
25 Correct 3 ms 4940 KB n=100
26 Correct 3 ms 4940 KB n=12
27 Correct 3 ms 4940 KB n=100
28 Correct 4 ms 5068 KB n=500
29 Correct 4 ms 5068 KB n=500
30 Correct 5 ms 5068 KB n=500
31 Correct 4 ms 5068 KB n=500
32 Correct 3 ms 5068 KB n=500
33 Correct 5 ms 5068 KB n=500
34 Correct 3 ms 5068 KB n=500
35 Correct 4 ms 5068 KB n=500
36 Correct 4 ms 5068 KB n=500
37 Correct 4 ms 5068 KB n=500
38 Correct 4 ms 5068 KB n=500
39 Correct 3 ms 5068 KB n=500
40 Correct 3 ms 5068 KB n=500
41 Correct 4 ms 5068 KB n=500
42 Correct 4 ms 5068 KB n=500
43 Correct 4 ms 5068 KB n=500
44 Correct 3 ms 5068 KB n=500
45 Correct 3 ms 5068 KB n=500
46 Correct 4 ms 5068 KB n=500
47 Correct 4 ms 5068 KB n=500
48 Correct 3 ms 5068 KB n=500
49 Correct 3 ms 5068 KB n=500
50 Correct 3 ms 5068 KB n=500
51 Correct 4 ms 5068 KB n=500
52 Correct 4 ms 5068 KB n=500
53 Correct 4 ms 5068 KB n=500
54 Correct 15 ms 5068 KB n=500
55 Correct 3 ms 5068 KB n=278
56 Correct 84 ms 5104 KB n=500
57 Correct 105 ms 5108 KB n=500
58 Correct 4 ms 5068 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB n=5
2 Correct 3 ms 4940 KB n=100
3 Correct 3 ms 4940 KB n=100
4 Correct 3 ms 4940 KB n=100
5 Correct 3 ms 4940 KB n=100
6 Correct 2 ms 4940 KB n=100
7 Correct 3 ms 4940 KB n=100
8 Correct 4 ms 4940 KB n=100
9 Correct 3 ms 4940 KB n=100
10 Correct 3 ms 4940 KB n=100
11 Correct 4 ms 4940 KB n=100
12 Correct 3 ms 4940 KB n=100
13 Correct 3 ms 4940 KB n=100
14 Correct 3 ms 4940 KB n=100
15 Correct 2 ms 4940 KB n=100
16 Correct 4 ms 4940 KB n=100
17 Correct 3 ms 4940 KB n=100
18 Correct 3 ms 4940 KB n=100
19 Correct 3 ms 5032 KB n=100
20 Correct 3 ms 4940 KB n=100
21 Correct 3 ms 4940 KB n=100
22 Correct 3 ms 4940 KB n=100
23 Correct 3 ms 4940 KB n=100
24 Correct 3 ms 4940 KB n=100
25 Correct 3 ms 4940 KB n=100
26 Correct 3 ms 4940 KB n=12
27 Correct 3 ms 4940 KB n=100
28 Correct 4 ms 5068 KB n=500
29 Correct 4 ms 5068 KB n=500
30 Correct 5 ms 5068 KB n=500
31 Correct 4 ms 5068 KB n=500
32 Correct 3 ms 5068 KB n=500
33 Correct 5 ms 5068 KB n=500
34 Correct 3 ms 5068 KB n=500
35 Correct 4 ms 5068 KB n=500
36 Correct 4 ms 5068 KB n=500
37 Correct 4 ms 5068 KB n=500
38 Correct 4 ms 5068 KB n=500
39 Correct 3 ms 5068 KB n=500
40 Correct 3 ms 5068 KB n=500
41 Correct 4 ms 5068 KB n=500
42 Correct 4 ms 5068 KB n=500
43 Correct 4 ms 5068 KB n=500
44 Correct 3 ms 5068 KB n=500
45 Correct 3 ms 5068 KB n=500
46 Correct 4 ms 5068 KB n=500
47 Correct 4 ms 5068 KB n=500
48 Correct 3 ms 5068 KB n=500
49 Correct 3 ms 5068 KB n=500
50 Correct 3 ms 5068 KB n=500
51 Correct 4 ms 5068 KB n=500
52 Correct 4 ms 5068 KB n=500
53 Correct 4 ms 5068 KB n=500
54 Correct 15 ms 5068 KB n=500
55 Correct 3 ms 5068 KB n=278
56 Correct 84 ms 5104 KB n=500
57 Correct 105 ms 5108 KB n=500
58 Correct 4 ms 5068 KB n=500
59 Correct 4 ms 5324 KB n=2000
60 Correct 21 ms 5324 KB n=2000
61 Correct 28 ms 5372 KB n=2000
62 Correct 32 ms 5324 KB n=2000
63 Correct 4 ms 5324 KB n=2000
64 Correct 31 ms 5324 KB n=2000
65 Correct 4 ms 5324 KB n=2000
66 Correct 27 ms 5324 KB n=2000
67 Correct 5 ms 5324 KB n=2000
68 Correct 29 ms 5324 KB n=2000
69 Correct 10 ms 5324 KB n=2000
70 Correct 9 ms 5324 KB n=2000
71 Correct 10 ms 5324 KB n=2000
72 Correct 8 ms 5376 KB n=2000
73 Correct 7 ms 5324 KB n=2000
74 Correct 6 ms 5316 KB n=1844
75 Correct 7 ms 5268 KB n=2000
76 Correct 17 ms 5316 KB n=2000
77 Correct 20 ms 5280 KB n=2000
78 Correct 18 ms 5364 KB n=2000
79 Correct 4 ms 5288 KB n=2000
80 Correct 20 ms 5328 KB n=2000
81 Correct 30 ms 5324 KB n=2000
82 Correct 5 ms 5324 KB n=2000
83 Correct 22 ms 5328 KB n=2000
84 Correct 7 ms 5324 KB n=2000
85 Correct 36 ms 5284 KB n=2000
86 Correct 25 ms 5396 KB n=2000
87 Correct 7 ms 5288 KB n=2000
88 Execution timed out 4067 ms 5452 KB Time limit exceeded
89 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB n=5
2 Correct 3 ms 4940 KB n=100
3 Correct 3 ms 4940 KB n=100
4 Correct 3 ms 4940 KB n=100
5 Correct 3 ms 4940 KB n=100
6 Correct 2 ms 4940 KB n=100
7 Correct 3 ms 4940 KB n=100
8 Correct 4 ms 4940 KB n=100
9 Correct 3 ms 4940 KB n=100
10 Correct 3 ms 4940 KB n=100
11 Correct 4 ms 4940 KB n=100
12 Correct 3 ms 4940 KB n=100
13 Correct 3 ms 4940 KB n=100
14 Correct 3 ms 4940 KB n=100
15 Correct 2 ms 4940 KB n=100
16 Correct 4 ms 4940 KB n=100
17 Correct 3 ms 4940 KB n=100
18 Correct 3 ms 4940 KB n=100
19 Correct 3 ms 5032 KB n=100
20 Correct 3 ms 4940 KB n=100
21 Correct 3 ms 4940 KB n=100
22 Correct 3 ms 4940 KB n=100
23 Correct 3 ms 4940 KB n=100
24 Correct 3 ms 4940 KB n=100
25 Correct 3 ms 4940 KB n=100
26 Correct 3 ms 4940 KB n=12
27 Correct 3 ms 4940 KB n=100
28 Correct 4 ms 5068 KB n=500
29 Correct 4 ms 5068 KB n=500
30 Correct 5 ms 5068 KB n=500
31 Correct 4 ms 5068 KB n=500
32 Correct 3 ms 5068 KB n=500
33 Correct 5 ms 5068 KB n=500
34 Correct 3 ms 5068 KB n=500
35 Correct 4 ms 5068 KB n=500
36 Correct 4 ms 5068 KB n=500
37 Correct 4 ms 5068 KB n=500
38 Correct 4 ms 5068 KB n=500
39 Correct 3 ms 5068 KB n=500
40 Correct 3 ms 5068 KB n=500
41 Correct 4 ms 5068 KB n=500
42 Correct 4 ms 5068 KB n=500
43 Correct 4 ms 5068 KB n=500
44 Correct 3 ms 5068 KB n=500
45 Correct 3 ms 5068 KB n=500
46 Correct 4 ms 5068 KB n=500
47 Correct 4 ms 5068 KB n=500
48 Correct 3 ms 5068 KB n=500
49 Correct 3 ms 5068 KB n=500
50 Correct 3 ms 5068 KB n=500
51 Correct 4 ms 5068 KB n=500
52 Correct 4 ms 5068 KB n=500
53 Correct 4 ms 5068 KB n=500
54 Correct 15 ms 5068 KB n=500
55 Correct 3 ms 5068 KB n=278
56 Correct 84 ms 5104 KB n=500
57 Correct 105 ms 5108 KB n=500
58 Correct 4 ms 5068 KB n=500
59 Correct 4 ms 5324 KB n=2000
60 Correct 21 ms 5324 KB n=2000
61 Correct 28 ms 5372 KB n=2000
62 Correct 32 ms 5324 KB n=2000
63 Correct 4 ms 5324 KB n=2000
64 Correct 31 ms 5324 KB n=2000
65 Correct 4 ms 5324 KB n=2000
66 Correct 27 ms 5324 KB n=2000
67 Correct 5 ms 5324 KB n=2000
68 Correct 29 ms 5324 KB n=2000
69 Correct 10 ms 5324 KB n=2000
70 Correct 9 ms 5324 KB n=2000
71 Correct 10 ms 5324 KB n=2000
72 Correct 8 ms 5376 KB n=2000
73 Correct 7 ms 5324 KB n=2000
74 Correct 6 ms 5316 KB n=1844
75 Correct 7 ms 5268 KB n=2000
76 Correct 17 ms 5316 KB n=2000
77 Correct 20 ms 5280 KB n=2000
78 Correct 18 ms 5364 KB n=2000
79 Correct 4 ms 5288 KB n=2000
80 Correct 20 ms 5328 KB n=2000
81 Correct 30 ms 5324 KB n=2000
82 Correct 5 ms 5324 KB n=2000
83 Correct 22 ms 5328 KB n=2000
84 Correct 7 ms 5324 KB n=2000
85 Correct 36 ms 5284 KB n=2000
86 Correct 25 ms 5396 KB n=2000
87 Correct 7 ms 5288 KB n=2000
88 Execution timed out 4067 ms 5452 KB Time limit exceeded
89 Halted 0 ms 0 KB -