# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
62985 | 2018-07-31T05:51:13 Z | kingpig9 | Long Mansion (JOI17_long_mansion) | C++11 | 2113 ms | 158232 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 1e5 + 10; //#define debug(...) fprintf(stderr, __VA_ARGS__) #define debug(...) #define fi first #define se second #define all(v) (v).begin(), (v).end() #define fillchar(a, s) memset((a), (s), sizeof(a)) int N, Q; int C[MAXN]; int L[MAXN], R[MAXN]; vector<int> A[MAXN]; bool has[MAXN]; void small() { for (int i = 1; i <= N; i++) { L[i] = R[i] = i; for (int j = 1; j <= N; j++) { has[j] = false; } for (int x : A[i]) { has[x] = true; } //ok let's go! while (true) { //extend left if (L[i] > 1) { int c = C[L[i] - 1]; if (has[c]) { L[i]--; for (int x : A[L[i]]) { has[x] = true; } continue; } } //extend right if (R[i] < N) { int c = C[R[i]]; if (has[c]) { R[i]++; for (int x : A[R[i]]) { has[x] = true; } continue; } } break; } } } vector<int> indk[21], indc[21]; void large() { for (int i = 1; i <= N; i++) { for (int x : A[i]) { indk[x].push_back(i); } } for (int i = 1; i < N; i++) { indc[C[i]].push_back(i); } for (int i = 1; i <= N; i++) { debug("----------------------------------i = %d----------------------------------\n", i); L[i] = R[i] = i; for (int j = 1; j <= 20; j++) { has[j] = false; } for (int x : A[i]) { has[x] = true; } while (true) { debug("----------L[%d] = %d, R[%d] = %d--------\n", i, L[i], i, R[i]); //extend left, update colors which it has vector<int> vhas, vnohas; for (int j = 1; j <= 20; j++) { if (has[j]) { debug("has %d\n", j); vhas.push_back(j); } else { vnohas.push_back(j); } } int lbarrier = 0, rbarrier = N; for (int c : vnohas) { //whatever is < i auto it = lower_bound(all(indc[c]), i); if (it != indc[c].end()) { debug("c = %d. index = %d.\n", c, *it); rbarrier = min(rbarrier, *it); } if (it != indc[c].begin()) { it--; lbarrier = max(lbarrier, *it); } } //lbarrier + 1 bool ok = false; debug("-ok. lbarrier = %d. rbarrier = %d.-\n", lbarrier, rbarrier); int nl = lbarrier + 1, nr = rbarrier; debug("nl = %d, nr = %d\n", nl, nr); if (nl != L[i]) { L[i] = nl; //if there is something [nl, i] for (int c : vnohas) { auto it = lower_bound(all(indk[c]), nl); if (it != indk[c].end() && *it <= i) { has[c] = true; } } ok = true; } if (nr != R[i]) { R[i] = nr; //if there is something in [i, nr] for (int c : vnohas) { auto it = lower_bound(all(indk[c]), i); if (it != indk[c].end() && *it <= nr) { has[c] = true; } } ok = true; } //extend right, update colors which it has if (!ok) { break; } } } } int main() { scanf("%d", &N); for (int i = 1; i < N; i++) { scanf("%d", &C[i]); } for (int i = 1; i <= N; i++) { int b; scanf("%d", &b); A[i].resize(b); for (int &x : A[i]) { scanf("%d", &x); } } if (N <= 5000) { small(); } else { large(); } scanf("%d", &Q); //then let's do this stuff for (int i = 1; i <= Q; i++) { int x, y; scanf("%d %d", &x, &y); puts(L[x] <= y && y <= R[x] ? "YES" : "NO"); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 2808 KB | Output is correct |
2 | Correct | 34 ms | 3132 KB | Output is correct |
3 | Correct | 72 ms | 3364 KB | Output is correct |
4 | Correct | 10 ms | 3392 KB | Output is correct |
5 | Correct | 27 ms | 3392 KB | Output is correct |
6 | Correct | 20 ms | 3392 KB | Output is correct |
7 | Correct | 16 ms | 3580 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 2808 KB | Output is correct |
2 | Correct | 34 ms | 3132 KB | Output is correct |
3 | Correct | 72 ms | 3364 KB | Output is correct |
4 | Correct | 10 ms | 3392 KB | Output is correct |
5 | Correct | 27 ms | 3392 KB | Output is correct |
6 | Correct | 20 ms | 3392 KB | Output is correct |
7 | Correct | 16 ms | 3580 KB | Output is correct |
8 | Correct | 215 ms | 9396 KB | Output is correct |
9 | Correct | 148 ms | 13828 KB | Output is correct |
10 | Correct | 192 ms | 18496 KB | Output is correct |
11 | Correct | 230 ms | 23440 KB | Output is correct |
12 | Correct | 148 ms | 27192 KB | Output is correct |
13 | Correct | 189 ms | 31500 KB | Output is correct |
14 | Correct | 147 ms | 35844 KB | Output is correct |
15 | Correct | 151 ms | 40228 KB | Output is correct |
16 | Correct | 167 ms | 44384 KB | Output is correct |
17 | Correct | 142 ms | 48492 KB | Output is correct |
18 | Correct | 179 ms | 52828 KB | Output is correct |
19 | Correct | 185 ms | 57304 KB | Output is correct |
20 | Correct | 227 ms | 61656 KB | Output is correct |
21 | Correct | 146 ms | 65536 KB | Output is correct |
22 | Correct | 159 ms | 69712 KB | Output is correct |
23 | Correct | 169 ms | 73736 KB | Output is correct |
24 | Correct | 233 ms | 78056 KB | Output is correct |
25 | Correct | 160 ms | 82324 KB | Output is correct |
26 | Correct | 181 ms | 86536 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 670 ms | 101048 KB | Output is correct |
2 | Correct | 549 ms | 107784 KB | Output is correct |
3 | Correct | 510 ms | 114256 KB | Output is correct |
4 | Correct | 601 ms | 121048 KB | Output is correct |
5 | Correct | 568 ms | 127380 KB | Output is correct |
6 | Correct | 1431 ms | 132332 KB | Output is correct |
7 | Correct | 1928 ms | 137640 KB | Output is correct |
8 | Correct | 1895 ms | 143000 KB | Output is correct |
9 | Correct | 2113 ms | 148104 KB | Output is correct |
10 | Correct | 2098 ms | 153260 KB | Output is correct |
11 | Correct | 1795 ms | 158232 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 2808 KB | Output is correct |
2 | Correct | 34 ms | 3132 KB | Output is correct |
3 | Correct | 72 ms | 3364 KB | Output is correct |
4 | Correct | 10 ms | 3392 KB | Output is correct |
5 | Correct | 27 ms | 3392 KB | Output is correct |
6 | Correct | 20 ms | 3392 KB | Output is correct |
7 | Correct | 16 ms | 3580 KB | Output is correct |
8 | Correct | 215 ms | 9396 KB | Output is correct |
9 | Correct | 148 ms | 13828 KB | Output is correct |
10 | Correct | 192 ms | 18496 KB | Output is correct |
11 | Correct | 230 ms | 23440 KB | Output is correct |
12 | Correct | 148 ms | 27192 KB | Output is correct |
13 | Correct | 189 ms | 31500 KB | Output is correct |
14 | Correct | 147 ms | 35844 KB | Output is correct |
15 | Correct | 151 ms | 40228 KB | Output is correct |
16 | Correct | 167 ms | 44384 KB | Output is correct |
17 | Correct | 142 ms | 48492 KB | Output is correct |
18 | Correct | 179 ms | 52828 KB | Output is correct |
19 | Correct | 185 ms | 57304 KB | Output is correct |
20 | Correct | 227 ms | 61656 KB | Output is correct |
21 | Correct | 146 ms | 65536 KB | Output is correct |
22 | Correct | 159 ms | 69712 KB | Output is correct |
23 | Correct | 169 ms | 73736 KB | Output is correct |
24 | Correct | 233 ms | 78056 KB | Output is correct |
25 | Correct | 160 ms | 82324 KB | Output is correct |
26 | Correct | 181 ms | 86536 KB | Output is correct |
27 | Correct | 670 ms | 101048 KB | Output is correct |
28 | Correct | 549 ms | 107784 KB | Output is correct |
29 | Correct | 510 ms | 114256 KB | Output is correct |
30 | Correct | 601 ms | 121048 KB | Output is correct |
31 | Correct | 568 ms | 127380 KB | Output is correct |
32 | Correct | 1431 ms | 132332 KB | Output is correct |
33 | Correct | 1928 ms | 137640 KB | Output is correct |
34 | Correct | 1895 ms | 143000 KB | Output is correct |
35 | Correct | 2113 ms | 148104 KB | Output is correct |
36 | Correct | 2098 ms | 153260 KB | Output is correct |
37 | Correct | 1795 ms | 158232 KB | Output is correct |
38 | Runtime error | 98 ms | 158232 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
39 | Halted | 0 ms | 0 KB | - |