답안 #168261

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
168261 2019-12-12T07:08:06 Z iefnah06 Long Mansion (JOI17_long_mansion) C++11
100 / 100
372 ms 52636 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 = N; i >= 1; i--) {
		int cur = i;
		while (cur+1 <= N && prv[cur] >= i) {
			cur = hi[cur+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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 12536 KB Output is correct
2 Correct 18 ms 12636 KB Output is correct
3 Correct 16 ms 12664 KB Output is correct
4 Correct 15 ms 12536 KB Output is correct
5 Correct 23 ms 12536 KB Output is correct
6 Correct 18 ms 12636 KB Output is correct
7 Correct 18 ms 12536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 12536 KB Output is correct
2 Correct 18 ms 12636 KB Output is correct
3 Correct 16 ms 12664 KB Output is correct
4 Correct 15 ms 12536 KB Output is correct
5 Correct 23 ms 12536 KB Output is correct
6 Correct 18 ms 12636 KB Output is correct
7 Correct 18 ms 12536 KB Output is correct
8 Correct 147 ms 18656 KB Output is correct
9 Correct 142 ms 18296 KB Output is correct
10 Correct 146 ms 18808 KB Output is correct
11 Correct 147 ms 19272 KB Output is correct
12 Correct 133 ms 18024 KB Output is correct
13 Correct 138 ms 18612 KB Output is correct
14 Correct 141 ms 18648 KB Output is correct
15 Correct 141 ms 18680 KB Output is correct
16 Correct 136 ms 18416 KB Output is correct
17 Correct 138 ms 18564 KB Output is correct
18 Correct 139 ms 18552 KB Output is correct
19 Correct 140 ms 18552 KB Output is correct
20 Correct 141 ms 18552 KB Output is correct
21 Correct 136 ms 18404 KB Output is correct
22 Correct 146 ms 18424 KB Output is correct
23 Correct 145 ms 18552 KB Output is correct
24 Correct 139 ms 18476 KB Output is correct
25 Correct 139 ms 18296 KB Output is correct
26 Correct 140 ms 18396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 230 ms 26976 KB Output is correct
2 Correct 222 ms 26744 KB Output is correct
3 Correct 219 ms 26580 KB Output is correct
4 Correct 226 ms 26876 KB Output is correct
5 Correct 220 ms 26872 KB Output is correct
6 Correct 200 ms 26180 KB Output is correct
7 Correct 200 ms 26040 KB Output is correct
8 Correct 190 ms 25860 KB Output is correct
9 Correct 192 ms 25860 KB Output is correct
10 Correct 188 ms 25848 KB Output is correct
11 Correct 188 ms 26004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 12536 KB Output is correct
2 Correct 18 ms 12636 KB Output is correct
3 Correct 16 ms 12664 KB Output is correct
4 Correct 15 ms 12536 KB Output is correct
5 Correct 23 ms 12536 KB Output is correct
6 Correct 18 ms 12636 KB Output is correct
7 Correct 18 ms 12536 KB Output is correct
8 Correct 147 ms 18656 KB Output is correct
9 Correct 142 ms 18296 KB Output is correct
10 Correct 146 ms 18808 KB Output is correct
11 Correct 147 ms 19272 KB Output is correct
12 Correct 133 ms 18024 KB Output is correct
13 Correct 138 ms 18612 KB Output is correct
14 Correct 141 ms 18648 KB Output is correct
15 Correct 141 ms 18680 KB Output is correct
16 Correct 136 ms 18416 KB Output is correct
17 Correct 138 ms 18564 KB Output is correct
18 Correct 139 ms 18552 KB Output is correct
19 Correct 140 ms 18552 KB Output is correct
20 Correct 141 ms 18552 KB Output is correct
21 Correct 136 ms 18404 KB Output is correct
22 Correct 146 ms 18424 KB Output is correct
23 Correct 145 ms 18552 KB Output is correct
24 Correct 139 ms 18476 KB Output is correct
25 Correct 139 ms 18296 KB Output is correct
26 Correct 140 ms 18396 KB Output is correct
27 Correct 230 ms 26976 KB Output is correct
28 Correct 222 ms 26744 KB Output is correct
29 Correct 219 ms 26580 KB Output is correct
30 Correct 226 ms 26876 KB Output is correct
31 Correct 220 ms 26872 KB Output is correct
32 Correct 200 ms 26180 KB Output is correct
33 Correct 200 ms 26040 KB Output is correct
34 Correct 190 ms 25860 KB Output is correct
35 Correct 192 ms 25860 KB Output is correct
36 Correct 188 ms 25848 KB Output is correct
37 Correct 188 ms 26004 KB Output is correct
38 Correct 370 ms 47488 KB Output is correct
39 Correct 372 ms 52636 KB Output is correct
40 Correct 314 ms 40876 KB Output is correct
41 Correct 363 ms 51136 KB Output is correct
42 Correct 203 ms 26972 KB Output is correct
43 Correct 204 ms 27040 KB Output is correct
44 Correct 273 ms 35196 KB Output is correct
45 Correct 285 ms 35348 KB Output is correct
46 Correct 283 ms 35428 KB Output is correct
47 Correct 204 ms 27132 KB Output is correct
48 Correct 201 ms 26844 KB Output is correct
49 Correct 272 ms 35164 KB Output is correct
50 Correct 271 ms 35204 KB Output is correct
51 Correct 288 ms 35612 KB Output is correct
52 Correct 272 ms 34076 KB Output is correct
53 Correct 312 ms 41192 KB Output is correct
54 Correct 360 ms 48292 KB Output is correct
55 Correct 309 ms 41412 KB Output is correct