Submission #168263

# Submission time Handle Problem Language Result Execution time Memory
168263 2019-12-12T07:08:42 Z iefnah06 Long Mansion (JOI17_long_mansion) C++11
100 / 100
364 ms 43992 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 5.1e5;
int N;
int C[MAXN];
vector<int> A[MAXN];

int last[MAXN];
int prv[MAXN]; // previous position with corresponding key
int nxt[MAXN]; // next

int lo[MAXN];
int hi[MAXN];

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> N;
	for (int i = 1; i <= N-1; i++) {
		cin >> C[i];
	}
	for (int i = 1; i <= N; i++) {
		int B; cin >> B;
		A[i].reserve(B);
		for (int j = 0; j < B; j++) {
			int v; cin >> v;
			A[i].push_back(v);
		}
	}

	for (int i = 1; i <= N-1; i++) {
		for (int v : A[i]) {
			last[v] = i;
		}
		prv[i] = last[C[i]];
	}

	fill(last + 1, last + N + 1, N+1);
	for (int i = N; i >= 2; i--) {
		for (int v : A[i]) {
			last[v] = i;
		}
		nxt[i-1] = last[C[i-1]];
	}

	for (int i = 1; i <= N; i++) {
		int l = i;
		int r = i;
		while (true) {
			if (l > 1 && nxt[l-1] <= r) {
				r = max(r, hi[l-1]);
				l = lo[l-1];
				continue;
			}
			if (r+1 <= N && prv[r] >= l) {
				r++;
				continue;
			}
			break;
		}
		lo[i] = l;
		hi[i] = r;
	}

	int Q; cin >> Q;
	while (Q--) {
		int x, y; cin >> x >> y;
		if (lo[x] <= y && y <= hi[x]) {
			cout << "YES" << '\n';
		} else {
			cout << "NO" << '\n';
		}
	}

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 15 ms 12540 KB Output is correct
2 Correct 14 ms 12536 KB Output is correct
3 Correct 16 ms 12708 KB Output is correct
4 Correct 15 ms 12540 KB Output is correct
5 Correct 15 ms 12536 KB Output is correct
6 Correct 15 ms 12536 KB Output is correct
7 Correct 14 ms 12536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 12540 KB Output is correct
2 Correct 14 ms 12536 KB Output is correct
3 Correct 16 ms 12708 KB Output is correct
4 Correct 15 ms 12540 KB Output is correct
5 Correct 15 ms 12536 KB Output is correct
6 Correct 15 ms 12536 KB Output is correct
7 Correct 14 ms 12536 KB Output is correct
8 Correct 143 ms 18480 KB Output is correct
9 Correct 144 ms 18296 KB Output is correct
10 Correct 148 ms 18848 KB Output is correct
11 Correct 144 ms 19064 KB Output is correct
12 Correct 131 ms 17912 KB Output is correct
13 Correct 144 ms 18552 KB Output is correct
14 Correct 142 ms 18552 KB Output is correct
15 Correct 144 ms 18588 KB Output is correct
16 Correct 139 ms 18424 KB Output is correct
17 Correct 142 ms 18680 KB Output is correct
18 Correct 139 ms 18680 KB Output is correct
19 Correct 140 ms 18552 KB Output is correct
20 Correct 149 ms 18652 KB Output is correct
21 Correct 141 ms 18424 KB Output is correct
22 Correct 144 ms 18424 KB Output is correct
23 Correct 142 ms 18424 KB Output is correct
24 Correct 143 ms 18424 KB Output is correct
25 Correct 139 ms 18296 KB Output is correct
26 Correct 138 ms 18296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 221 ms 25052 KB Output is correct
2 Correct 224 ms 25008 KB Output is correct
3 Correct 213 ms 25084 KB Output is correct
4 Correct 220 ms 24736 KB Output is correct
5 Correct 223 ms 24952 KB Output is correct
6 Correct 198 ms 25556 KB Output is correct
7 Correct 191 ms 25976 KB Output is correct
8 Correct 199 ms 25848 KB Output is correct
9 Correct 193 ms 25872 KB Output is correct
10 Correct 188 ms 25848 KB Output is correct
11 Correct 187 ms 25872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 12540 KB Output is correct
2 Correct 14 ms 12536 KB Output is correct
3 Correct 16 ms 12708 KB Output is correct
4 Correct 15 ms 12540 KB Output is correct
5 Correct 15 ms 12536 KB Output is correct
6 Correct 15 ms 12536 KB Output is correct
7 Correct 14 ms 12536 KB Output is correct
8 Correct 143 ms 18480 KB Output is correct
9 Correct 144 ms 18296 KB Output is correct
10 Correct 148 ms 18848 KB Output is correct
11 Correct 144 ms 19064 KB Output is correct
12 Correct 131 ms 17912 KB Output is correct
13 Correct 144 ms 18552 KB Output is correct
14 Correct 142 ms 18552 KB Output is correct
15 Correct 144 ms 18588 KB Output is correct
16 Correct 139 ms 18424 KB Output is correct
17 Correct 142 ms 18680 KB Output is correct
18 Correct 139 ms 18680 KB Output is correct
19 Correct 140 ms 18552 KB Output is correct
20 Correct 149 ms 18652 KB Output is correct
21 Correct 141 ms 18424 KB Output is correct
22 Correct 144 ms 18424 KB Output is correct
23 Correct 142 ms 18424 KB Output is correct
24 Correct 143 ms 18424 KB Output is correct
25 Correct 139 ms 18296 KB Output is correct
26 Correct 138 ms 18296 KB Output is correct
27 Correct 221 ms 25052 KB Output is correct
28 Correct 224 ms 25008 KB Output is correct
29 Correct 213 ms 25084 KB Output is correct
30 Correct 220 ms 24736 KB Output is correct
31 Correct 223 ms 24952 KB Output is correct
32 Correct 198 ms 25556 KB Output is correct
33 Correct 191 ms 25976 KB Output is correct
34 Correct 199 ms 25848 KB Output is correct
35 Correct 193 ms 25872 KB Output is correct
36 Correct 188 ms 25848 KB Output is correct
37 Correct 187 ms 25872 KB Output is correct
38 Correct 333 ms 38876 KB Output is correct
39 Correct 364 ms 43992 KB Output is correct
40 Correct 320 ms 32744 KB Output is correct
41 Correct 345 ms 43960 KB Output is correct
42 Correct 201 ms 22836 KB Output is correct
43 Correct 211 ms 22776 KB Output is correct
44 Correct 267 ms 27364 KB Output is correct
45 Correct 303 ms 27276 KB Output is correct
46 Correct 279 ms 27196 KB Output is correct
47 Correct 202 ms 22904 KB Output is correct
48 Correct 202 ms 22904 KB Output is correct
49 Correct 271 ms 27384 KB Output is correct
50 Correct 272 ms 27560 KB Output is correct
51 Correct 281 ms 27476 KB Output is correct
52 Correct 255 ms 27640 KB Output is correct
53 Correct 325 ms 32708 KB Output is correct
54 Correct 356 ms 37984 KB Output is correct
55 Correct 307 ms 32432 KB Output is correct