Submission #122182

# Submission time Handle Problem Language Result Execution time Memory
122182 2019-06-27T19:25:55 Z cerberus Long Mansion (JOI17_long_mansion) C++17
10 / 100
3000 ms 22524 KB
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 5e5 + 10, LOG = log2(N) + 5;

int c[N], l[N], r[N], lkey[N], rkey[N];
vector<int> pos[N];

int main() {
	fast_cin();
	int n; cin >> n;
	for (int i = 1; i <= n - 1; ++i) {
		cin >> c[i];
	}
	for (int i = 1; i <= n; ++i) {
		int b; cin >> b;
		for (int j = 0; j < b; ++j) {
			int k; cin >> k;
			pos[k].pb(i);
		}
	}
	for (int i = 1; i <= n; ++i) {
		pos[i].pb(0);
		pos[i].pb(n + 1);
		sort(pos[i].begin(), pos[i].end());
	}
	for (int i = 1; i <= n - 1; ++i) {
		auto it = lower_bound(pos[c[i]].begin(), pos[c[i]].end(), i + 1);
		rkey[i] = *it;
		lkey[i] = *(it - 1);
	}
	for (int i = 1; i <= n; ++i) {
		l[i] = r[i] = i;
		while (true) {
			if (l[i] > 1 and rkey[l[i] - 1] <= r[i]) {
				--l[i];
			} else if (r[i] < n and lkey[r[i]] >= l[i]) {
				++r[i];
			} else {
				break;
			}
		}
	}
	int q; cin >> q;
	while (q--) {
		int x, y;
		cin >> x >> y;
		if (l[x] <= y and y <= r[x]) {
			cout << "YES\n";
		} else {
			cout << "NO\n";
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12288 KB Output is correct
2 Correct 16 ms 12416 KB Output is correct
3 Correct 25 ms 12416 KB Output is correct
4 Correct 14 ms 12288 KB Output is correct
5 Correct 16 ms 12288 KB Output is correct
6 Correct 14 ms 12288 KB Output is correct
7 Correct 15 ms 12288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12288 KB Output is correct
2 Correct 16 ms 12416 KB Output is correct
3 Correct 25 ms 12416 KB Output is correct
4 Correct 14 ms 12288 KB Output is correct
5 Correct 16 ms 12288 KB Output is correct
6 Correct 14 ms 12288 KB Output is correct
7 Correct 15 ms 12288 KB Output is correct
8 Correct 105 ms 15608 KB Output is correct
9 Correct 105 ms 15584 KB Output is correct
10 Correct 114 ms 15840 KB Output is correct
11 Correct 120 ms 16024 KB Output is correct
12 Correct 97 ms 15828 KB Output is correct
13 Correct 108 ms 15876 KB Output is correct
14 Correct 103 ms 15848 KB Output is correct
15 Correct 106 ms 15936 KB Output is correct
16 Correct 108 ms 16120 KB Output is correct
17 Correct 103 ms 15992 KB Output is correct
18 Correct 106 ms 15864 KB Output is correct
19 Correct 102 ms 15868 KB Output is correct
20 Correct 104 ms 15992 KB Output is correct
21 Correct 106 ms 16120 KB Output is correct
22 Correct 106 ms 15864 KB Output is correct
23 Correct 105 ms 15652 KB Output is correct
24 Correct 105 ms 15736 KB Output is correct
25 Correct 104 ms 15636 KB Output is correct
26 Correct 105 ms 15736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 945 ms 20812 KB Output is correct
2 Correct 1817 ms 22524 KB Output is correct
3 Execution timed out 3027 ms 20252 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12288 KB Output is correct
2 Correct 16 ms 12416 KB Output is correct
3 Correct 25 ms 12416 KB Output is correct
4 Correct 14 ms 12288 KB Output is correct
5 Correct 16 ms 12288 KB Output is correct
6 Correct 14 ms 12288 KB Output is correct
7 Correct 15 ms 12288 KB Output is correct
8 Correct 105 ms 15608 KB Output is correct
9 Correct 105 ms 15584 KB Output is correct
10 Correct 114 ms 15840 KB Output is correct
11 Correct 120 ms 16024 KB Output is correct
12 Correct 97 ms 15828 KB Output is correct
13 Correct 108 ms 15876 KB Output is correct
14 Correct 103 ms 15848 KB Output is correct
15 Correct 106 ms 15936 KB Output is correct
16 Correct 108 ms 16120 KB Output is correct
17 Correct 103 ms 15992 KB Output is correct
18 Correct 106 ms 15864 KB Output is correct
19 Correct 102 ms 15868 KB Output is correct
20 Correct 104 ms 15992 KB Output is correct
21 Correct 106 ms 16120 KB Output is correct
22 Correct 106 ms 15864 KB Output is correct
23 Correct 105 ms 15652 KB Output is correct
24 Correct 105 ms 15736 KB Output is correct
25 Correct 104 ms 15636 KB Output is correct
26 Correct 105 ms 15736 KB Output is correct
27 Correct 945 ms 20812 KB Output is correct
28 Correct 1817 ms 22524 KB Output is correct
29 Execution timed out 3027 ms 20252 KB Time limit exceeded
30 Halted 0 ms 0 KB -