Submission #909489

# Submission time Handle Problem Language Result Execution time Memory
909489 2024-01-17T08:26:24 Z IBory Long Mansion (JOI17_long_mansion) C++17
100 / 100
431 ms 75992 KB
#include <bits/stdc++.h>
#define pii pair<int, int>
using namespace std;

const int MAX = 500005;
int C[MAX], L[MAX], R[MAX];
pii E[MAX];
vector<int> K[MAX];

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int N, Q;
	cin >> N;
	for (int i = 1; i < N; ++i) cin >> C[i];
	for (int i = 1; i <= N; ++i) {
		int M;
		cin >> M;
		K[i].resize(M);
		for (int& n : K[i]) cin >> n;
	}

	vector<int> in(N + 1);
	for (int i = 1; i < N; ++i) {
		for (int k : K[i]) in[k] = i;
		L[i] = in[C[i]];
	}
	fill(in.begin(), in.end(), N + 1);
	for (int i = N - 1; i > 0; --i) {
		for (int k : K[i + 1]) in[k] = i + 1;
		R[i] = in[C[i]];
	}
	R[0] = R[N] = N + 1, L[0] = L[N] = 0;

	set<int, greater<int>> UD;
	set<pii> CR;
	for (int i = 1; i <= N; ++i) UD.insert(i);
	CR.emplace(0, R[0]);

	for (int i = 1; i <= N; ++i) {
		auto it = UD.lower_bound(i);
		while (it != UD.end()) {
			int cur = *it;
			if (cur <= L[i]) break;

			auto it2 = CR.lower_bound(pii{cur, 0}); it2--;
			while ((*it2).second <= i) it2 = CR.erase(it2), it2--;
			if ((*it2).first < L[i]) break;

			E[cur] = {(*it2).first + 1, i};
			it = UD.erase(it);
		}

		CR.emplace(i, R[i]);
	}

	cin >> Q;
	while (Q--) {
		int x, y;
		cin >> x >> y;
		bool can = E[x].first <= y && y <= E[x].second;
		cout << (can ? "YES" : "NO") << '\n';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 19288 KB Output is correct
2 Correct 7 ms 19292 KB Output is correct
3 Correct 11 ms 19548 KB Output is correct
4 Correct 7 ms 19292 KB Output is correct
5 Correct 7 ms 19292 KB Output is correct
6 Correct 7 ms 19364 KB Output is correct
7 Correct 7 ms 19292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 19288 KB Output is correct
2 Correct 7 ms 19292 KB Output is correct
3 Correct 11 ms 19548 KB Output is correct
4 Correct 7 ms 19292 KB Output is correct
5 Correct 7 ms 19292 KB Output is correct
6 Correct 7 ms 19364 KB Output is correct
7 Correct 7 ms 19292 KB Output is correct
8 Correct 82 ms 25160 KB Output is correct
9 Correct 79 ms 24916 KB Output is correct
10 Correct 81 ms 25428 KB Output is correct
11 Correct 87 ms 25744 KB Output is correct
12 Correct 72 ms 24656 KB Output is correct
13 Correct 78 ms 25168 KB Output is correct
14 Correct 75 ms 25176 KB Output is correct
15 Correct 76 ms 25364 KB Output is correct
16 Correct 75 ms 25196 KB Output is correct
17 Correct 95 ms 25172 KB Output is correct
18 Correct 75 ms 25248 KB Output is correct
19 Correct 78 ms 25168 KB Output is correct
20 Correct 76 ms 25172 KB Output is correct
21 Correct 95 ms 25060 KB Output is correct
22 Correct 79 ms 25284 KB Output is correct
23 Correct 77 ms 25060 KB Output is correct
24 Correct 85 ms 25128 KB Output is correct
25 Correct 78 ms 25076 KB Output is correct
26 Correct 76 ms 24912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 151 ms 38176 KB Output is correct
2 Correct 150 ms 38224 KB Output is correct
3 Correct 144 ms 38124 KB Output is correct
4 Correct 148 ms 38156 KB Output is correct
5 Correct 151 ms 38348 KB Output is correct
6 Correct 136 ms 37520 KB Output is correct
7 Correct 142 ms 37200 KB Output is correct
8 Correct 142 ms 37204 KB Output is correct
9 Correct 134 ms 37188 KB Output is correct
10 Correct 134 ms 37204 KB Output is correct
11 Correct 133 ms 37376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 19288 KB Output is correct
2 Correct 7 ms 19292 KB Output is correct
3 Correct 11 ms 19548 KB Output is correct
4 Correct 7 ms 19292 KB Output is correct
5 Correct 7 ms 19292 KB Output is correct
6 Correct 7 ms 19364 KB Output is correct
7 Correct 7 ms 19292 KB Output is correct
8 Correct 82 ms 25160 KB Output is correct
9 Correct 79 ms 24916 KB Output is correct
10 Correct 81 ms 25428 KB Output is correct
11 Correct 87 ms 25744 KB Output is correct
12 Correct 72 ms 24656 KB Output is correct
13 Correct 78 ms 25168 KB Output is correct
14 Correct 75 ms 25176 KB Output is correct
15 Correct 76 ms 25364 KB Output is correct
16 Correct 75 ms 25196 KB Output is correct
17 Correct 95 ms 25172 KB Output is correct
18 Correct 75 ms 25248 KB Output is correct
19 Correct 78 ms 25168 KB Output is correct
20 Correct 76 ms 25172 KB Output is correct
21 Correct 95 ms 25060 KB Output is correct
22 Correct 79 ms 25284 KB Output is correct
23 Correct 77 ms 25060 KB Output is correct
24 Correct 85 ms 25128 KB Output is correct
25 Correct 78 ms 25076 KB Output is correct
26 Correct 76 ms 24912 KB Output is correct
27 Correct 151 ms 38176 KB Output is correct
28 Correct 150 ms 38224 KB Output is correct
29 Correct 144 ms 38124 KB Output is correct
30 Correct 148 ms 38156 KB Output is correct
31 Correct 151 ms 38348 KB Output is correct
32 Correct 136 ms 37520 KB Output is correct
33 Correct 142 ms 37200 KB Output is correct
34 Correct 142 ms 37204 KB Output is correct
35 Correct 134 ms 37188 KB Output is correct
36 Correct 134 ms 37204 KB Output is correct
37 Correct 133 ms 37376 KB Output is correct
38 Correct 344 ms 67600 KB Output is correct
39 Correct 431 ms 75992 KB Output is correct
40 Correct 290 ms 57824 KB Output is correct
41 Correct 385 ms 74468 KB Output is correct
42 Correct 158 ms 38484 KB Output is correct
43 Correct 143 ms 38420 KB Output is correct
44 Correct 223 ms 49232 KB Output is correct
45 Correct 241 ms 49488 KB Output is correct
46 Correct 231 ms 49488 KB Output is correct
47 Correct 135 ms 38640 KB Output is correct
48 Correct 140 ms 38224 KB Output is correct
49 Correct 212 ms 49276 KB Output is correct
50 Correct 223 ms 49472 KB Output is correct
51 Correct 234 ms 50016 KB Output is correct
52 Correct 239 ms 48524 KB Output is correct
53 Correct 322 ms 58488 KB Output is correct
54 Correct 429 ms 68408 KB Output is correct
55 Correct 351 ms 58716 KB Output is correct