# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
60401 | 2018-07-24T05:32:12 Z | 강태규(#1741) | Long Mansion (JOI17_long_mansion) | C++11 | 706 ms | 39640 KB |
#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <deque> #include <set> #include <map> #include <unordered_map> #include <functional> #include <cstring> #include <cmath> #include <ctime> #include <cstdlib> using namespace std; typedef long long llong; typedef long double ld; typedef pair<int, int> pii; typedef pair<llong, llong> pll; int n; int door[500000]; vector<int> key[500001]; struct _ret { int i; int l, r; _ret() : i(0), l(0), r(0) {} _ret(int i, int l, int r) : i(i), l(l), r(r) {} } ans[500001]; int findv(const vector<int> &v, int l, int r) { auto it = lower_bound(v.begin(), v.end(), l); if (it != v.end() && *it <= r) return 1; return 0; } int par[500001]; int find(int x) { if (par[x]) return par[x] = find(par[x]); return x; } int process[500001]; _ret expand(int x) { if (process[x]) return _ret(x, x, x); if (find(x) != x) return expand(find(x)); if (ans[x].l) return ans[x]; process[x] = 1; int l = x, r = x; while (1) { if (l > 1 && findv(key[door[l - 1]], l, r)) { _ret ret = expand(l - 1); l = min(l, ret.l); r = max(r, ret.r); if (ret.i && ret.i != x) { par[x] = find(ret.i); process[x] = 0; ret.l = min(ret.l, l); ret.r = max(ret.r, r); return ret; } } else if (r < n && findv(key[door[r]], l, r)) { _ret ret = expand(r + 1); l = min(l, ret.l); r = max(r, ret.r); if (ret.i && ret.i != x) { par[x] = find(ret.i); process[x] = 0; ret.l = min(ret.l, l); ret.r = max(ret.r, r); return ret; } } else break; } process[x] = 0; return ans[x] = _ret(0, l, r); } int main() { scanf("%d", &n); for (int i = 1; i < n; ++i) { scanf("%d", door + i); } for (int i = 1; i <= n; ++i) { int b; scanf("%d", &b); for (int j = 0; j < b; ++j) { int a; scanf("%d", &a); key[a].push_back(i); } } for (int i = 1; i <= n; ++i) expand(i); int q; scanf("%d", &q); while (q--) { int a, b; scanf("%d%d", &a, &b); _ret ret = ans[find(a)]; printf(ret.l <= b && b <= ret.r ? "YES\n" : "NO\n"); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 18040 KB | Output is correct |
2 | Correct | 25 ms | 18212 KB | Output is correct |
3 | Correct | 30 ms | 18336 KB | Output is correct |
4 | Correct | 31 ms | 18408 KB | Output is correct |
5 | Correct | 27 ms | 18444 KB | Output is correct |
6 | Correct | 27 ms | 18632 KB | Output is correct |
7 | Correct | 35 ms | 18756 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 18040 KB | Output is correct |
2 | Correct | 25 ms | 18212 KB | Output is correct |
3 | Correct | 30 ms | 18336 KB | Output is correct |
4 | Correct | 31 ms | 18408 KB | Output is correct |
5 | Correct | 27 ms | 18444 KB | Output is correct |
6 | Correct | 27 ms | 18632 KB | Output is correct |
7 | Correct | 35 ms | 18756 KB | Output is correct |
8 | Correct | 248 ms | 21012 KB | Output is correct |
9 | Correct | 221 ms | 21148 KB | Output is correct |
10 | Correct | 193 ms | 22548 KB | Output is correct |
11 | Correct | 268 ms | 22836 KB | Output is correct |
12 | Correct | 231 ms | 22836 KB | Output is correct |
13 | Correct | 267 ms | 22836 KB | Output is correct |
14 | Correct | 211 ms | 22836 KB | Output is correct |
15 | Correct | 187 ms | 22836 KB | Output is correct |
16 | Correct | 185 ms | 22940 KB | Output is correct |
17 | Correct | 192 ms | 22940 KB | Output is correct |
18 | Correct | 228 ms | 22940 KB | Output is correct |
19 | Correct | 196 ms | 22940 KB | Output is correct |
20 | Correct | 289 ms | 22992 KB | Output is correct |
21 | Correct | 178 ms | 22992 KB | Output is correct |
22 | Correct | 221 ms | 22992 KB | Output is correct |
23 | Correct | 210 ms | 22992 KB | Output is correct |
24 | Correct | 190 ms | 22992 KB | Output is correct |
25 | Correct | 215 ms | 22992 KB | Output is correct |
26 | Correct | 190 ms | 22992 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 427 ms | 26380 KB | Output is correct |
2 | Correct | 523 ms | 26380 KB | Output is correct |
3 | Correct | 349 ms | 26380 KB | Output is correct |
4 | Correct | 381 ms | 26380 KB | Output is correct |
5 | Correct | 492 ms | 26380 KB | Output is correct |
6 | Correct | 404 ms | 26380 KB | Output is correct |
7 | Correct | 401 ms | 26380 KB | Output is correct |
8 | Correct | 369 ms | 26380 KB | Output is correct |
9 | Correct | 367 ms | 26380 KB | Output is correct |
10 | Correct | 404 ms | 26380 KB | Output is correct |
11 | Correct | 335 ms | 26380 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 18040 KB | Output is correct |
2 | Correct | 25 ms | 18212 KB | Output is correct |
3 | Correct | 30 ms | 18336 KB | Output is correct |
4 | Correct | 31 ms | 18408 KB | Output is correct |
5 | Correct | 27 ms | 18444 KB | Output is correct |
6 | Correct | 27 ms | 18632 KB | Output is correct |
7 | Correct | 35 ms | 18756 KB | Output is correct |
8 | Correct | 248 ms | 21012 KB | Output is correct |
9 | Correct | 221 ms | 21148 KB | Output is correct |
10 | Correct | 193 ms | 22548 KB | Output is correct |
11 | Correct | 268 ms | 22836 KB | Output is correct |
12 | Correct | 231 ms | 22836 KB | Output is correct |
13 | Correct | 267 ms | 22836 KB | Output is correct |
14 | Correct | 211 ms | 22836 KB | Output is correct |
15 | Correct | 187 ms | 22836 KB | Output is correct |
16 | Correct | 185 ms | 22940 KB | Output is correct |
17 | Correct | 192 ms | 22940 KB | Output is correct |
18 | Correct | 228 ms | 22940 KB | Output is correct |
19 | Correct | 196 ms | 22940 KB | Output is correct |
20 | Correct | 289 ms | 22992 KB | Output is correct |
21 | Correct | 178 ms | 22992 KB | Output is correct |
22 | Correct | 221 ms | 22992 KB | Output is correct |
23 | Correct | 210 ms | 22992 KB | Output is correct |
24 | Correct | 190 ms | 22992 KB | Output is correct |
25 | Correct | 215 ms | 22992 KB | Output is correct |
26 | Correct | 190 ms | 22992 KB | Output is correct |
27 | Correct | 427 ms | 26380 KB | Output is correct |
28 | Correct | 523 ms | 26380 KB | Output is correct |
29 | Correct | 349 ms | 26380 KB | Output is correct |
30 | Correct | 381 ms | 26380 KB | Output is correct |
31 | Correct | 492 ms | 26380 KB | Output is correct |
32 | Correct | 404 ms | 26380 KB | Output is correct |
33 | Correct | 401 ms | 26380 KB | Output is correct |
34 | Correct | 369 ms | 26380 KB | Output is correct |
35 | Correct | 367 ms | 26380 KB | Output is correct |
36 | Correct | 404 ms | 26380 KB | Output is correct |
37 | Correct | 335 ms | 26380 KB | Output is correct |
38 | Correct | 706 ms | 28700 KB | Output is correct |
39 | Correct | 674 ms | 29380 KB | Output is correct |
40 | Correct | 464 ms | 29380 KB | Output is correct |
41 | Correct | 683 ms | 30912 KB | Output is correct |
42 | Correct | 390 ms | 30912 KB | Output is correct |
43 | Correct | 353 ms | 30912 KB | Output is correct |
44 | Correct | 548 ms | 30912 KB | Output is correct |
45 | Correct | 542 ms | 30912 KB | Output is correct |
46 | Correct | 557 ms | 30912 KB | Output is correct |
47 | Correct | 443 ms | 30912 KB | Output is correct |
48 | Correct | 324 ms | 30912 KB | Output is correct |
49 | Correct | 513 ms | 30912 KB | Output is correct |
50 | Correct | 580 ms | 30912 KB | Output is correct |
51 | Correct | 539 ms | 31080 KB | Output is correct |
52 | Correct | 432 ms | 31788 KB | Output is correct |
53 | Correct | 489 ms | 35468 KB | Output is correct |
54 | Correct | 614 ms | 39640 KB | Output is correct |
55 | Correct | 519 ms | 39640 KB | Output is correct |