Submission #497990

# Submission time Handle Problem Language Result Execution time Memory
497990 2021-12-24T08:14:52 Z Mukhitali Birthday gift (IZhO18_treearray) C++17
100 / 100
1425 ms 76888 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, mm = 1e15;
const double P = 3.14;

vector <int> g[N];
int tim, tin[N], tout[N], u[N][22], a[N];
multiset <int> s[N];

void dfs(int v, int pr) {
	tin[v] = ++tim;
	u[v][0] = pr;
	for (int i = 1; i < 22; 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 upper(int x, int y) {
	return (tin[x] <= tin[y] && tin[y] <= tout[x]);
}

int lca(int x, int y) {
	if (upper(x, y))
		return x;
	if (upper(y, x))
		return y;
	for (int i = 21; i >= 0; i--) 
		if (u[x][i] != 0 && !upper(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);
	}
	dfs(1, 0);
	for (int i = 1; i <= m; i++) {
		cin >> a[i];
		s[a[i]].insert(i);
		if (i > 1)
			s[lca(a[i], a[i - 1])].insert(i - 1);
	}
	for (int i = 1; i <= q; i++) {
		int tp;
		cin >> tp;
		if (tp == 1) {
			int pos, v;
			cin >> pos >> v;
			if (s[lca(a[pos], a[pos - 1])].lower_bound(pos - 1) != s[lca(a[pos], a[pos - 1])].end())
				s[lca(a[pos], a[pos - 1])].erase(s[lca(a[pos], a[pos - 1])].lower_bound(pos - 1));
			if (s[lca(a[pos], a[pos + 1])].lower_bound(pos) != s[lca(a[pos], a[pos + 1])].end())
				s[lca(a[pos], a[pos + 1])].erase(s[lca(a[pos], a[pos + 1])].lower_bound(pos));
			s[a[pos]].erase(s[a[pos]].lower_bound(pos));
			if (pos != 1)
				s[lca(a[pos - 1], v)].insert(pos - 1);
			if (pos != m)
				s[lca(a[pos + 1], v)].insert(pos);
			s[v].insert(pos);
			a[pos] = v;
		}
		else {
			int l, r, v;
			cin >> l >> r >> v;
			auto tl = s[v].lower_bound(l);
			if (tl != s[v].end() && *tl < r)
				cout << *tl << ' ' << *tl + 1 << el;
			else if (tl != s[v].end() && *tl == r && a[r] == v)
				cout << *tl << ' ' << *tl << el;
			else 
				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 7 ms 14284 KB n=5
2 Correct 7 ms 14316 KB n=100
3 Correct 8 ms 14396 KB n=100
4 Correct 8 ms 14412 KB n=100
5 Correct 7 ms 14388 KB n=100
6 Correct 8 ms 14356 KB n=100
7 Correct 7 ms 14388 KB n=100
8 Correct 10 ms 14392 KB n=100
9 Correct 7 ms 14380 KB n=100
10 Correct 7 ms 14396 KB n=100
11 Correct 7 ms 14412 KB n=100
12 Correct 7 ms 14384 KB n=100
13 Correct 9 ms 14396 KB n=100
14 Correct 9 ms 14412 KB n=100
15 Correct 8 ms 14380 KB n=100
16 Correct 8 ms 14428 KB n=100
17 Correct 7 ms 14412 KB n=100
18 Correct 7 ms 14384 KB n=100
19 Correct 8 ms 14412 KB n=100
20 Correct 7 ms 14392 KB n=100
21 Correct 8 ms 14412 KB n=100
22 Correct 8 ms 14412 KB n=100
23 Correct 7 ms 14412 KB n=100
24 Correct 9 ms 14412 KB n=100
25 Correct 9 ms 14412 KB n=100
26 Correct 7 ms 14412 KB n=12
27 Correct 10 ms 14416 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14284 KB n=5
2 Correct 7 ms 14316 KB n=100
3 Correct 8 ms 14396 KB n=100
4 Correct 8 ms 14412 KB n=100
5 Correct 7 ms 14388 KB n=100
6 Correct 8 ms 14356 KB n=100
7 Correct 7 ms 14388 KB n=100
8 Correct 10 ms 14392 KB n=100
9 Correct 7 ms 14380 KB n=100
10 Correct 7 ms 14396 KB n=100
11 Correct 7 ms 14412 KB n=100
12 Correct 7 ms 14384 KB n=100
13 Correct 9 ms 14396 KB n=100
14 Correct 9 ms 14412 KB n=100
15 Correct 8 ms 14380 KB n=100
16 Correct 8 ms 14428 KB n=100
17 Correct 7 ms 14412 KB n=100
18 Correct 7 ms 14384 KB n=100
19 Correct 8 ms 14412 KB n=100
20 Correct 7 ms 14392 KB n=100
21 Correct 8 ms 14412 KB n=100
22 Correct 8 ms 14412 KB n=100
23 Correct 7 ms 14412 KB n=100
24 Correct 9 ms 14412 KB n=100
25 Correct 9 ms 14412 KB n=100
26 Correct 7 ms 14412 KB n=12
27 Correct 10 ms 14416 KB n=100
28 Correct 8 ms 14528 KB n=500
29 Correct 8 ms 14540 KB n=500
30 Correct 9 ms 14448 KB n=500
31 Correct 9 ms 14524 KB n=500
32 Correct 10 ms 14532 KB n=500
33 Correct 8 ms 14540 KB n=500
34 Correct 10 ms 14412 KB n=500
35 Correct 8 ms 14540 KB n=500
36 Correct 8 ms 14528 KB n=500
37 Correct 9 ms 14524 KB n=500
38 Correct 12 ms 14412 KB n=500
39 Correct 10 ms 14412 KB n=500
40 Correct 10 ms 14412 KB n=500
41 Correct 9 ms 14540 KB n=500
42 Correct 9 ms 14524 KB n=500
43 Correct 9 ms 14412 KB n=500
44 Correct 9 ms 14524 KB n=500
45 Correct 8 ms 14524 KB n=500
46 Correct 8 ms 14540 KB n=500
47 Correct 9 ms 14540 KB n=500
48 Correct 8 ms 14412 KB n=500
49 Correct 8 ms 14540 KB n=500
50 Correct 9 ms 14412 KB n=500
51 Correct 9 ms 14540 KB n=500
52 Correct 9 ms 14540 KB n=500
53 Correct 10 ms 14448 KB n=500
54 Correct 11 ms 14540 KB n=500
55 Correct 9 ms 14540 KB n=278
56 Correct 9 ms 14540 KB n=500
57 Correct 10 ms 14540 KB n=500
58 Correct 9 ms 14532 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14284 KB n=5
2 Correct 7 ms 14316 KB n=100
3 Correct 8 ms 14396 KB n=100
4 Correct 8 ms 14412 KB n=100
5 Correct 7 ms 14388 KB n=100
6 Correct 8 ms 14356 KB n=100
7 Correct 7 ms 14388 KB n=100
8 Correct 10 ms 14392 KB n=100
9 Correct 7 ms 14380 KB n=100
10 Correct 7 ms 14396 KB n=100
11 Correct 7 ms 14412 KB n=100
12 Correct 7 ms 14384 KB n=100
13 Correct 9 ms 14396 KB n=100
14 Correct 9 ms 14412 KB n=100
15 Correct 8 ms 14380 KB n=100
16 Correct 8 ms 14428 KB n=100
17 Correct 7 ms 14412 KB n=100
18 Correct 7 ms 14384 KB n=100
19 Correct 8 ms 14412 KB n=100
20 Correct 7 ms 14392 KB n=100
21 Correct 8 ms 14412 KB n=100
22 Correct 8 ms 14412 KB n=100
23 Correct 7 ms 14412 KB n=100
24 Correct 9 ms 14412 KB n=100
25 Correct 9 ms 14412 KB n=100
26 Correct 7 ms 14412 KB n=12
27 Correct 10 ms 14416 KB n=100
28 Correct 8 ms 14528 KB n=500
29 Correct 8 ms 14540 KB n=500
30 Correct 9 ms 14448 KB n=500
31 Correct 9 ms 14524 KB n=500
32 Correct 10 ms 14532 KB n=500
33 Correct 8 ms 14540 KB n=500
34 Correct 10 ms 14412 KB n=500
35 Correct 8 ms 14540 KB n=500
36 Correct 8 ms 14528 KB n=500
37 Correct 9 ms 14524 KB n=500
38 Correct 12 ms 14412 KB n=500
39 Correct 10 ms 14412 KB n=500
40 Correct 10 ms 14412 KB n=500
41 Correct 9 ms 14540 KB n=500
42 Correct 9 ms 14524 KB n=500
43 Correct 9 ms 14412 KB n=500
44 Correct 9 ms 14524 KB n=500
45 Correct 8 ms 14524 KB n=500
46 Correct 8 ms 14540 KB n=500
47 Correct 9 ms 14540 KB n=500
48 Correct 8 ms 14412 KB n=500
49 Correct 8 ms 14540 KB n=500
50 Correct 9 ms 14412 KB n=500
51 Correct 9 ms 14540 KB n=500
52 Correct 9 ms 14540 KB n=500
53 Correct 10 ms 14448 KB n=500
54 Correct 11 ms 14540 KB n=500
55 Correct 9 ms 14540 KB n=278
56 Correct 9 ms 14540 KB n=500
57 Correct 10 ms 14540 KB n=500
58 Correct 9 ms 14532 KB n=500
59 Correct 13 ms 14788 KB n=2000
60 Correct 13 ms 14924 KB n=2000
61 Correct 13 ms 14920 KB n=2000
62 Correct 16 ms 14924 KB n=2000
63 Correct 16 ms 14916 KB n=2000
64 Correct 13 ms 14924 KB n=2000
65 Correct 13 ms 14924 KB n=2000
66 Correct 13 ms 14924 KB n=2000
67 Correct 15 ms 14796 KB n=2000
68 Correct 13 ms 14924 KB n=2000
69 Correct 14 ms 14924 KB n=2000
70 Correct 15 ms 14924 KB n=2000
71 Correct 20 ms 14936 KB n=2000
72 Correct 18 ms 14796 KB n=2000
73 Correct 15 ms 14924 KB n=2000
74 Correct 12 ms 14784 KB n=1844
75 Correct 14 ms 14928 KB n=2000
76 Correct 13 ms 14796 KB n=2000
77 Correct 13 ms 14796 KB n=2000
78 Correct 14 ms 14796 KB n=2000
79 Correct 16 ms 14868 KB n=2000
80 Correct 15 ms 14916 KB n=2000
81 Correct 17 ms 14924 KB n=2000
82 Correct 13 ms 14796 KB n=2000
83 Correct 14 ms 14924 KB n=2000
84 Correct 14 ms 14836 KB n=2000
85 Correct 14 ms 14924 KB n=2000
86 Correct 14 ms 14828 KB n=2000
87 Correct 15 ms 14928 KB n=2000
88 Correct 15 ms 14916 KB n=2000
89 Correct 13 ms 14916 KB n=2000
90 Correct 13 ms 14876 KB n=2000
91 Correct 14 ms 14912 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14284 KB n=5
2 Correct 7 ms 14316 KB n=100
3 Correct 8 ms 14396 KB n=100
4 Correct 8 ms 14412 KB n=100
5 Correct 7 ms 14388 KB n=100
6 Correct 8 ms 14356 KB n=100
7 Correct 7 ms 14388 KB n=100
8 Correct 10 ms 14392 KB n=100
9 Correct 7 ms 14380 KB n=100
10 Correct 7 ms 14396 KB n=100
11 Correct 7 ms 14412 KB n=100
12 Correct 7 ms 14384 KB n=100
13 Correct 9 ms 14396 KB n=100
14 Correct 9 ms 14412 KB n=100
15 Correct 8 ms 14380 KB n=100
16 Correct 8 ms 14428 KB n=100
17 Correct 7 ms 14412 KB n=100
18 Correct 7 ms 14384 KB n=100
19 Correct 8 ms 14412 KB n=100
20 Correct 7 ms 14392 KB n=100
21 Correct 8 ms 14412 KB n=100
22 Correct 8 ms 14412 KB n=100
23 Correct 7 ms 14412 KB n=100
24 Correct 9 ms 14412 KB n=100
25 Correct 9 ms 14412 KB n=100
26 Correct 7 ms 14412 KB n=12
27 Correct 10 ms 14416 KB n=100
28 Correct 8 ms 14528 KB n=500
29 Correct 8 ms 14540 KB n=500
30 Correct 9 ms 14448 KB n=500
31 Correct 9 ms 14524 KB n=500
32 Correct 10 ms 14532 KB n=500
33 Correct 8 ms 14540 KB n=500
34 Correct 10 ms 14412 KB n=500
35 Correct 8 ms 14540 KB n=500
36 Correct 8 ms 14528 KB n=500
37 Correct 9 ms 14524 KB n=500
38 Correct 12 ms 14412 KB n=500
39 Correct 10 ms 14412 KB n=500
40 Correct 10 ms 14412 KB n=500
41 Correct 9 ms 14540 KB n=500
42 Correct 9 ms 14524 KB n=500
43 Correct 9 ms 14412 KB n=500
44 Correct 9 ms 14524 KB n=500
45 Correct 8 ms 14524 KB n=500
46 Correct 8 ms 14540 KB n=500
47 Correct 9 ms 14540 KB n=500
48 Correct 8 ms 14412 KB n=500
49 Correct 8 ms 14540 KB n=500
50 Correct 9 ms 14412 KB n=500
51 Correct 9 ms 14540 KB n=500
52 Correct 9 ms 14540 KB n=500
53 Correct 10 ms 14448 KB n=500
54 Correct 11 ms 14540 KB n=500
55 Correct 9 ms 14540 KB n=278
56 Correct 9 ms 14540 KB n=500
57 Correct 10 ms 14540 KB n=500
58 Correct 9 ms 14532 KB n=500
59 Correct 13 ms 14788 KB n=2000
60 Correct 13 ms 14924 KB n=2000
61 Correct 13 ms 14920 KB n=2000
62 Correct 16 ms 14924 KB n=2000
63 Correct 16 ms 14916 KB n=2000
64 Correct 13 ms 14924 KB n=2000
65 Correct 13 ms 14924 KB n=2000
66 Correct 13 ms 14924 KB n=2000
67 Correct 15 ms 14796 KB n=2000
68 Correct 13 ms 14924 KB n=2000
69 Correct 14 ms 14924 KB n=2000
70 Correct 15 ms 14924 KB n=2000
71 Correct 20 ms 14936 KB n=2000
72 Correct 18 ms 14796 KB n=2000
73 Correct 15 ms 14924 KB n=2000
74 Correct 12 ms 14784 KB n=1844
75 Correct 14 ms 14928 KB n=2000
76 Correct 13 ms 14796 KB n=2000
77 Correct 13 ms 14796 KB n=2000
78 Correct 14 ms 14796 KB n=2000
79 Correct 16 ms 14868 KB n=2000
80 Correct 15 ms 14916 KB n=2000
81 Correct 17 ms 14924 KB n=2000
82 Correct 13 ms 14796 KB n=2000
83 Correct 14 ms 14924 KB n=2000
84 Correct 14 ms 14836 KB n=2000
85 Correct 14 ms 14924 KB n=2000
86 Correct 14 ms 14828 KB n=2000
87 Correct 15 ms 14928 KB n=2000
88 Correct 15 ms 14916 KB n=2000
89 Correct 13 ms 14916 KB n=2000
90 Correct 13 ms 14876 KB n=2000
91 Correct 14 ms 14912 KB n=2000
92 Correct 1071 ms 67368 KB n=200000
93 Correct 1186 ms 72344 KB n=200000
94 Correct 937 ms 75684 KB n=200000
95 Correct 1025 ms 67376 KB n=200000
96 Correct 1065 ms 67256 KB n=200000
97 Correct 1194 ms 71380 KB n=200000
98 Correct 1056 ms 67256 KB n=200000
99 Correct 1161 ms 67508 KB n=200000
100 Correct 1137 ms 67288 KB n=200000
101 Correct 806 ms 76888 KB n=200000
102 Correct 849 ms 68420 KB n=200000
103 Correct 902 ms 68400 KB n=200000
104 Correct 858 ms 68472 KB n=200000
105 Correct 872 ms 68892 KB n=200000
106 Correct 924 ms 68860 KB n=200000
107 Correct 886 ms 68768 KB n=200000
108 Correct 1062 ms 67328 KB n=200000
109 Correct 1122 ms 67276 KB n=200000
110 Correct 1109 ms 67316 KB n=200000
111 Correct 1004 ms 66740 KB n=200000
112 Correct 867 ms 75984 KB n=200000
113 Correct 1170 ms 71188 KB n=200000
114 Correct 1070 ms 66848 KB n=200000
115 Correct 1425 ms 69240 KB n=200000
116 Correct 991 ms 67436 KB n=200000
117 Correct 867 ms 76088 KB n=200000
118 Correct 1233 ms 70228 KB n=200000
119 Correct 1135 ms 67668 KB n=200000
120 Correct 776 ms 76096 KB n=200000
121 Correct 764 ms 75884 KB n=200000
122 Correct 762 ms 76172 KB n=200000
123 Correct 875 ms 68644 KB n=200000
124 Correct 243 ms 29504 KB n=25264