Submission #538073

# Submission time Handle Problem Language Result Execution time Memory
538073 2022-03-16T04:55:43 Z fhvirus Long Mansion (JOI17_long_mansion) C++17
100 / 100
279 ms 43384 KB
// jiaqiyang orz
// solution adapted from his/her submission
#include<bits/stdc++.h>
using namespace std;

const int kN = 500005;
int N, Q, C[kN], B[kN];
vector<int> A[kN];

int prv[kN], nxt[kN], occ[kN];
int lb[kN], rb[kN];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	cin >> N;
	for (int i = 1; i < N; ++i)
		cin >> C[i];
	for (int i = 1; i <= N; ++i) {
		cin >> B[i];
		A[i].resize(B[i]);
		for (int& a: A[i])
			cin >> a;
	}

	for (int i = 1; i < N; ++i) {
		for (const int& a: A[i])
			occ[a] = i;
		prv[i] = occ[C[i]];
	}
	for (int i = 1; i <= N; ++i)
		occ[i] = N + 1;
	for (int i = N - 1; i >= 1; --i) {
		for (const int& a: A[i + 1])
			occ[a] = i + 1;
		nxt[i] = occ[C[i]];
	}

	for (int i = 1; i <= N; ++i) {
		int l = i, r = i;
		while (true) {
			if (l > 1 and l <= nxt[l - 1] and nxt[l - 1] <= r) {
				r = max(r, rb[l - 1]);
				l = min(l, lb[l - 1]);
			} else if (r < N and l <= prv[r] and prv[r] <= r) {
				++r;
			} else break;
		}
		lb[i] = l; rb[i] = r;
	}

	cin >> Q;
	for (int X, Y, i = 0; i < Q; ++i) {
		cin >> X >> Y;
		cout << (lb[X] <= Y and Y <= rb[X] ? "YES\n" : "NO\n");
	}
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12244 KB Output is correct
2 Correct 8 ms 12296 KB Output is correct
3 Correct 9 ms 12476 KB Output is correct
4 Correct 9 ms 12224 KB Output is correct
5 Correct 9 ms 12304 KB Output is correct
6 Correct 10 ms 12216 KB Output is correct
7 Correct 11 ms 12220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12244 KB Output is correct
2 Correct 8 ms 12296 KB Output is correct
3 Correct 9 ms 12476 KB Output is correct
4 Correct 9 ms 12224 KB Output is correct
5 Correct 9 ms 12304 KB Output is correct
6 Correct 10 ms 12216 KB Output is correct
7 Correct 11 ms 12220 KB Output is correct
8 Correct 95 ms 14012 KB Output is correct
9 Correct 90 ms 14152 KB Output is correct
10 Correct 110 ms 14156 KB Output is correct
11 Correct 97 ms 14372 KB Output is correct
12 Correct 87 ms 14156 KB Output is correct
13 Correct 91 ms 14180 KB Output is correct
14 Correct 92 ms 14168 KB Output is correct
15 Correct 102 ms 14292 KB Output is correct
16 Correct 91 ms 14516 KB Output is correct
17 Correct 92 ms 14244 KB Output is correct
18 Correct 93 ms 14224 KB Output is correct
19 Correct 98 ms 14260 KB Output is correct
20 Correct 120 ms 14412 KB Output is correct
21 Correct 131 ms 14504 KB Output is correct
22 Correct 96 ms 14276 KB Output is correct
23 Correct 118 ms 14084 KB Output is correct
24 Correct 93 ms 14032 KB Output is correct
25 Correct 93 ms 14084 KB Output is correct
26 Correct 103 ms 13992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 148 ms 20080 KB Output is correct
2 Correct 180 ms 19944 KB Output is correct
3 Correct 163 ms 19988 KB Output is correct
4 Correct 186 ms 19912 KB Output is correct
5 Correct 166 ms 19960 KB Output is correct
6 Correct 140 ms 20024 KB Output is correct
7 Correct 171 ms 20196 KB Output is correct
8 Correct 128 ms 20168 KB Output is correct
9 Correct 175 ms 20272 KB Output is correct
10 Correct 163 ms 20172 KB Output is correct
11 Correct 129 ms 20200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12244 KB Output is correct
2 Correct 8 ms 12296 KB Output is correct
3 Correct 9 ms 12476 KB Output is correct
4 Correct 9 ms 12224 KB Output is correct
5 Correct 9 ms 12304 KB Output is correct
6 Correct 10 ms 12216 KB Output is correct
7 Correct 11 ms 12220 KB Output is correct
8 Correct 95 ms 14012 KB Output is correct
9 Correct 90 ms 14152 KB Output is correct
10 Correct 110 ms 14156 KB Output is correct
11 Correct 97 ms 14372 KB Output is correct
12 Correct 87 ms 14156 KB Output is correct
13 Correct 91 ms 14180 KB Output is correct
14 Correct 92 ms 14168 KB Output is correct
15 Correct 102 ms 14292 KB Output is correct
16 Correct 91 ms 14516 KB Output is correct
17 Correct 92 ms 14244 KB Output is correct
18 Correct 93 ms 14224 KB Output is correct
19 Correct 98 ms 14260 KB Output is correct
20 Correct 120 ms 14412 KB Output is correct
21 Correct 131 ms 14504 KB Output is correct
22 Correct 96 ms 14276 KB Output is correct
23 Correct 118 ms 14084 KB Output is correct
24 Correct 93 ms 14032 KB Output is correct
25 Correct 93 ms 14084 KB Output is correct
26 Correct 103 ms 13992 KB Output is correct
27 Correct 148 ms 20080 KB Output is correct
28 Correct 180 ms 19944 KB Output is correct
29 Correct 163 ms 19988 KB Output is correct
30 Correct 186 ms 19912 KB Output is correct
31 Correct 166 ms 19960 KB Output is correct
32 Correct 140 ms 20024 KB Output is correct
33 Correct 171 ms 20196 KB Output is correct
34 Correct 128 ms 20168 KB Output is correct
35 Correct 175 ms 20272 KB Output is correct
36 Correct 163 ms 20172 KB Output is correct
37 Correct 129 ms 20200 KB Output is correct
38 Correct 238 ms 37252 KB Output is correct
39 Correct 252 ms 43152 KB Output is correct
40 Correct 205 ms 31520 KB Output is correct
41 Correct 245 ms 43384 KB Output is correct
42 Correct 127 ms 19900 KB Output is correct
43 Correct 137 ms 19932 KB Output is correct
44 Correct 197 ms 25804 KB Output is correct
45 Correct 190 ms 25776 KB Output is correct
46 Correct 181 ms 25768 KB Output is correct
47 Correct 135 ms 19996 KB Output is correct
48 Correct 139 ms 20072 KB Output is correct
49 Correct 174 ms 25812 KB Output is correct
50 Correct 196 ms 25896 KB Output is correct
51 Correct 175 ms 25796 KB Output is correct
52 Correct 187 ms 25560 KB Output is correct
53 Correct 192 ms 31468 KB Output is correct
54 Correct 279 ms 37316 KB Output is correct
55 Correct 189 ms 31376 KB Output is correct