Submission #495935

# Submission time Handle Problem Language Result Execution time Memory
495935 2021-12-20T08:13:32 Z Mukhitali Birthday gift (IZhO18_treearray) C++17
30 / 100
4000 ms 5536 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++) {
					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 4 ms 4940 KB n=100
3 Correct 3 ms 5068 KB n=100
4 Correct 3 ms 4940 KB n=100
5 Correct 3 ms 5016 KB n=100
6 Correct 5 ms 4940 KB n=100
7 Correct 5 ms 4940 KB n=100
8 Correct 3 ms 4940 KB n=100
9 Correct 3 ms 4940 KB n=100
10 Correct 3 ms 5016 KB n=100
11 Correct 4 ms 4940 KB n=100
12 Correct 3 ms 5020 KB n=100
13 Correct 3 ms 5008 KB n=100
14 Correct 3 ms 4940 KB n=100
15 Correct 3 ms 5016 KB n=100
16 Correct 3 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 4940 KB n=100
20 Correct 3 ms 5020 KB n=100
21 Correct 3 ms 5020 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 2 ms 4940 KB n=12
27 Correct 3 ms 5020 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB n=5
2 Correct 4 ms 4940 KB n=100
3 Correct 3 ms 5068 KB n=100
4 Correct 3 ms 4940 KB n=100
5 Correct 3 ms 5016 KB n=100
6 Correct 5 ms 4940 KB n=100
7 Correct 5 ms 4940 KB n=100
8 Correct 3 ms 4940 KB n=100
9 Correct 3 ms 4940 KB n=100
10 Correct 3 ms 5016 KB n=100
11 Correct 4 ms 4940 KB n=100
12 Correct 3 ms 5020 KB n=100
13 Correct 3 ms 5008 KB n=100
14 Correct 3 ms 4940 KB n=100
15 Correct 3 ms 5016 KB n=100
16 Correct 3 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 4940 KB n=100
20 Correct 3 ms 5020 KB n=100
21 Correct 3 ms 5020 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 2 ms 4940 KB n=12
27 Correct 3 ms 5020 KB n=100
28 Correct 4 ms 5196 KB n=500
29 Correct 16 ms 5020 KB n=500
30 Correct 14 ms 5132 KB n=500
31 Correct 16 ms 5028 KB n=500
32 Correct 3 ms 5068 KB n=500
33 Correct 14 ms 5132 KB n=500
34 Correct 3 ms 5068 KB n=500
35 Correct 15 ms 5068 KB n=500
36 Correct 138 ms 5028 KB n=500
37 Correct 140 ms 5100 KB n=500
38 Correct 142 ms 5232 KB n=500
39 Correct 27 ms 5120 KB n=500
40 Correct 22 ms 5124 KB n=500
41 Correct 21 ms 5068 KB n=500
42 Correct 79 ms 5104 KB n=500
43 Correct 72 ms 5104 KB n=500
44 Correct 71 ms 5116 KB n=500
45 Correct 3 ms 5028 KB n=500
46 Correct 16 ms 5068 KB n=500
47 Correct 14 ms 5196 KB n=500
48 Correct 3 ms 5108 KB n=500
49 Correct 13 ms 5068 KB n=500
50 Correct 24 ms 5028 KB n=500
51 Correct 22 ms 5068 KB n=500
52 Correct 25 ms 5068 KB n=500
53 Correct 27 ms 5068 KB n=500
54 Correct 13 ms 5032 KB n=500
55 Correct 6 ms 5024 KB n=278
56 Correct 77 ms 5068 KB n=500
57 Correct 86 ms 5120 KB n=500
58 Correct 62 ms 5112 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB n=5
2 Correct 4 ms 4940 KB n=100
3 Correct 3 ms 5068 KB n=100
4 Correct 3 ms 4940 KB n=100
5 Correct 3 ms 5016 KB n=100
6 Correct 5 ms 4940 KB n=100
7 Correct 5 ms 4940 KB n=100
8 Correct 3 ms 4940 KB n=100
9 Correct 3 ms 4940 KB n=100
10 Correct 3 ms 5016 KB n=100
11 Correct 4 ms 4940 KB n=100
12 Correct 3 ms 5020 KB n=100
13 Correct 3 ms 5008 KB n=100
14 Correct 3 ms 4940 KB n=100
15 Correct 3 ms 5016 KB n=100
16 Correct 3 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 4940 KB n=100
20 Correct 3 ms 5020 KB n=100
21 Correct 3 ms 5020 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 2 ms 4940 KB n=12
27 Correct 3 ms 5020 KB n=100
28 Correct 4 ms 5196 KB n=500
29 Correct 16 ms 5020 KB n=500
30 Correct 14 ms 5132 KB n=500
31 Correct 16 ms 5028 KB n=500
32 Correct 3 ms 5068 KB n=500
33 Correct 14 ms 5132 KB n=500
34 Correct 3 ms 5068 KB n=500
35 Correct 15 ms 5068 KB n=500
36 Correct 138 ms 5028 KB n=500
37 Correct 140 ms 5100 KB n=500
38 Correct 142 ms 5232 KB n=500
39 Correct 27 ms 5120 KB n=500
40 Correct 22 ms 5124 KB n=500
41 Correct 21 ms 5068 KB n=500
42 Correct 79 ms 5104 KB n=500
43 Correct 72 ms 5104 KB n=500
44 Correct 71 ms 5116 KB n=500
45 Correct 3 ms 5028 KB n=500
46 Correct 16 ms 5068 KB n=500
47 Correct 14 ms 5196 KB n=500
48 Correct 3 ms 5108 KB n=500
49 Correct 13 ms 5068 KB n=500
50 Correct 24 ms 5028 KB n=500
51 Correct 22 ms 5068 KB n=500
52 Correct 25 ms 5068 KB n=500
53 Correct 27 ms 5068 KB n=500
54 Correct 13 ms 5032 KB n=500
55 Correct 6 ms 5024 KB n=278
56 Correct 77 ms 5068 KB n=500
57 Correct 86 ms 5120 KB n=500
58 Correct 62 ms 5112 KB n=500
59 Correct 13 ms 5288 KB n=2000
60 Correct 743 ms 5460 KB n=2000
61 Correct 683 ms 5536 KB n=2000
62 Correct 472 ms 5388 KB n=2000
63 Correct 19 ms 5324 KB n=2000
64 Correct 617 ms 5400 KB n=2000
65 Correct 6 ms 5324 KB n=2000
66 Correct 796 ms 5424 KB n=2000
67 Correct 38 ms 5368 KB n=2000
68 Correct 656 ms 5400 KB n=2000
69 Execution timed out 4072 ms 5352 KB Time limit exceeded
70 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB n=5
2 Correct 4 ms 4940 KB n=100
3 Correct 3 ms 5068 KB n=100
4 Correct 3 ms 4940 KB n=100
5 Correct 3 ms 5016 KB n=100
6 Correct 5 ms 4940 KB n=100
7 Correct 5 ms 4940 KB n=100
8 Correct 3 ms 4940 KB n=100
9 Correct 3 ms 4940 KB n=100
10 Correct 3 ms 5016 KB n=100
11 Correct 4 ms 4940 KB n=100
12 Correct 3 ms 5020 KB n=100
13 Correct 3 ms 5008 KB n=100
14 Correct 3 ms 4940 KB n=100
15 Correct 3 ms 5016 KB n=100
16 Correct 3 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 4940 KB n=100
20 Correct 3 ms 5020 KB n=100
21 Correct 3 ms 5020 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 2 ms 4940 KB n=12
27 Correct 3 ms 5020 KB n=100
28 Correct 4 ms 5196 KB n=500
29 Correct 16 ms 5020 KB n=500
30 Correct 14 ms 5132 KB n=500
31 Correct 16 ms 5028 KB n=500
32 Correct 3 ms 5068 KB n=500
33 Correct 14 ms 5132 KB n=500
34 Correct 3 ms 5068 KB n=500
35 Correct 15 ms 5068 KB n=500
36 Correct 138 ms 5028 KB n=500
37 Correct 140 ms 5100 KB n=500
38 Correct 142 ms 5232 KB n=500
39 Correct 27 ms 5120 KB n=500
40 Correct 22 ms 5124 KB n=500
41 Correct 21 ms 5068 KB n=500
42 Correct 79 ms 5104 KB n=500
43 Correct 72 ms 5104 KB n=500
44 Correct 71 ms 5116 KB n=500
45 Correct 3 ms 5028 KB n=500
46 Correct 16 ms 5068 KB n=500
47 Correct 14 ms 5196 KB n=500
48 Correct 3 ms 5108 KB n=500
49 Correct 13 ms 5068 KB n=500
50 Correct 24 ms 5028 KB n=500
51 Correct 22 ms 5068 KB n=500
52 Correct 25 ms 5068 KB n=500
53 Correct 27 ms 5068 KB n=500
54 Correct 13 ms 5032 KB n=500
55 Correct 6 ms 5024 KB n=278
56 Correct 77 ms 5068 KB n=500
57 Correct 86 ms 5120 KB n=500
58 Correct 62 ms 5112 KB n=500
59 Correct 13 ms 5288 KB n=2000
60 Correct 743 ms 5460 KB n=2000
61 Correct 683 ms 5536 KB n=2000
62 Correct 472 ms 5388 KB n=2000
63 Correct 19 ms 5324 KB n=2000
64 Correct 617 ms 5400 KB n=2000
65 Correct 6 ms 5324 KB n=2000
66 Correct 796 ms 5424 KB n=2000
67 Correct 38 ms 5368 KB n=2000
68 Correct 656 ms 5400 KB n=2000
69 Execution timed out 4072 ms 5352 KB Time limit exceeded
70 Halted 0 ms 0 KB -