# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
296308 | 2020-09-10T13:24:12 Z | BThero | Long Mansion (JOI17_long_mansion) | C++17 | 1572 ms | 121636 KB |
// chrono::system_clock::now().time_since_epoch().count() #include<bits/stdc++.h> #define pb push_back #define eb emplace_back #define mp make_pair #define fi first #define se second #define all(x) (x).begin(), (x).end() #define debug(x) cerr << #x << " = " << x << endl; using namespace std; typedef long long ll; typedef pair<int, int> pii; const int MAXN = (int)5e5 + 5; vector<int> group[MAXN]; vector<int> keys[MAXN]; int betw[MAXN]; int A[MAXN], B[MAXN]; int L[MAXN], R[MAXN]; int n, q; void calcB() { B[0] = n + 1; for (int i = 1; i <= n; ++i) { group[i].clear(); B[i] = n + 1; } for (int i = 2; i <= n; ++i) { group[betw[i - 1]].pb(i - 1); for (int x : keys[i]) { for (int y : group[x]) { B[y] = i; } group[x].clear(); } } } void calcA() { A[n + 1] = 0; for (int i = 1; i <= n; ++i) { group[i].clear(); A[i] = 0; } for (int i = n - 1; i > 0; --i) { group[betw[i]].pb(i + 1); for (int x : keys[i]) { for (int y : group[x]) { A[y] = i; } group[x].clear(); } } } void calcR() { for (int i = 1; i <= n; ++i) { R[i] = n + 1; } for (int i = 0; i <= n + 1; ++i) { group[i].clear(); } for (int i = 1; i <= n; ++i) { group[B[i - 1]].pb(i); } set<int> S, T; for (int i = 1; i <= n + 1; ++i) { S.insert(i); T.insert(i); } for (int r = 1; r <= n; ++r) { for (int x : group[r]) { S.erase(x); } // A[r + 1] < l int l = A[r + 1] + 1; l = *S.lower_bound(l); // B[l - 1] > r auto it = T.lower_bound(l); while (*it <= r) { R[*it] = r; it = T.erase(it); } } } void calcL() { for (int i = 1; i <= n; ++i) { L[i] = 0; } for (int i = 0; i <= n + 1; ++i) { group[i].clear(); } for (int i = 1; i <= n; ++i) { group[A[i + 1]].pb(i); } set<int> S, T; for (int i = 0; i <= n + 1; ++i) { S.insert(i); T.insert(i); } for (int l = n; l > 0; --l) { for (int x : group[l]) { S.erase(x); } // B[l - 1] > r int r = B[l - 1] - 1; r = *(--S.upper_bound(r)); // A[r + 1] < l auto it = T.lower_bound(l); while (*it <= r) { L[*it] = l; it = T.erase(it); } } } void solve() { scanf("%d", &n); for (int i = 1; i < n; ++i) { scanf("%d", &betw[i]); } for (int i = 1; i <= n; ++i) { int sz; scanf("%d", &sz); keys[i].resize(sz); for (int j = 0; j < sz; ++j) { scanf("%d", &keys[i][j]); } } calcB(); calcA(); calcR(); calcL(); scanf("%d", &q); for (int i = 1; i <= q; ++i) { int a, b; scanf("%d %d", &a, &b); // a -> b bool ans = 1; if (a < b) { if (R[a] < b) { ans = 0; } } else { if (L[a] > b) { ans = 0; } } if (ans) { printf("YES\n"); } else { printf("NO\n"); } } } int main() { int tt = 1; while (tt--) { solve(); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 21 ms | 24192 KB | Output is correct |
2 | Correct | 22 ms | 24320 KB | Output is correct |
3 | Correct | 25 ms | 24704 KB | Output is correct |
4 | Correct | 21 ms | 24192 KB | Output is correct |
5 | Correct | 22 ms | 24320 KB | Output is correct |
6 | Correct | 21 ms | 24192 KB | Output is correct |
7 | Correct | 21 ms | 24264 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 21 ms | 24192 KB | Output is correct |
2 | Correct | 22 ms | 24320 KB | Output is correct |
3 | Correct | 25 ms | 24704 KB | Output is correct |
4 | Correct | 21 ms | 24192 KB | Output is correct |
5 | Correct | 22 ms | 24320 KB | Output is correct |
6 | Correct | 21 ms | 24192 KB | Output is correct |
7 | Correct | 21 ms | 24264 KB | Output is correct |
8 | Correct | 172 ms | 25848 KB | Output is correct |
9 | Correct | 174 ms | 25720 KB | Output is correct |
10 | Correct | 173 ms | 25976 KB | Output is correct |
11 | Correct | 173 ms | 26488 KB | Output is correct |
12 | Correct | 168 ms | 25864 KB | Output is correct |
13 | Correct | 166 ms | 26104 KB | Output is correct |
14 | Correct | 169 ms | 25976 KB | Output is correct |
15 | Correct | 164 ms | 25976 KB | Output is correct |
16 | Correct | 163 ms | 26360 KB | Output is correct |
17 | Correct | 172 ms | 25976 KB | Output is correct |
18 | Correct | 167 ms | 25976 KB | Output is correct |
19 | Correct | 165 ms | 25976 KB | Output is correct |
20 | Correct | 157 ms | 26104 KB | Output is correct |
21 | Correct | 155 ms | 26248 KB | Output is correct |
22 | Correct | 162 ms | 25976 KB | Output is correct |
23 | Correct | 167 ms | 25792 KB | Output is correct |
24 | Correct | 168 ms | 25792 KB | Output is correct |
25 | Correct | 172 ms | 25920 KB | Output is correct |
26 | Correct | 170 ms | 25792 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 426 ms | 42616 KB | Output is correct |
2 | Correct | 427 ms | 42780 KB | Output is correct |
3 | Correct | 422 ms | 42872 KB | Output is correct |
4 | Correct | 432 ms | 42636 KB | Output is correct |
5 | Correct | 423 ms | 42668 KB | Output is correct |
6 | Correct | 385 ms | 43256 KB | Output is correct |
7 | Correct | 374 ms | 43384 KB | Output is correct |
8 | Correct | 358 ms | 43536 KB | Output is correct |
9 | Correct | 347 ms | 43512 KB | Output is correct |
10 | Correct | 348 ms | 43512 KB | Output is correct |
11 | Correct | 344 ms | 43384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 21 ms | 24192 KB | Output is correct |
2 | Correct | 22 ms | 24320 KB | Output is correct |
3 | Correct | 25 ms | 24704 KB | Output is correct |
4 | Correct | 21 ms | 24192 KB | Output is correct |
5 | Correct | 22 ms | 24320 KB | Output is correct |
6 | Correct | 21 ms | 24192 KB | Output is correct |
7 | Correct | 21 ms | 24264 KB | Output is correct |
8 | Correct | 172 ms | 25848 KB | Output is correct |
9 | Correct | 174 ms | 25720 KB | Output is correct |
10 | Correct | 173 ms | 25976 KB | Output is correct |
11 | Correct | 173 ms | 26488 KB | Output is correct |
12 | Correct | 168 ms | 25864 KB | Output is correct |
13 | Correct | 166 ms | 26104 KB | Output is correct |
14 | Correct | 169 ms | 25976 KB | Output is correct |
15 | Correct | 164 ms | 25976 KB | Output is correct |
16 | Correct | 163 ms | 26360 KB | Output is correct |
17 | Correct | 172 ms | 25976 KB | Output is correct |
18 | Correct | 167 ms | 25976 KB | Output is correct |
19 | Correct | 165 ms | 25976 KB | Output is correct |
20 | Correct | 157 ms | 26104 KB | Output is correct |
21 | Correct | 155 ms | 26248 KB | Output is correct |
22 | Correct | 162 ms | 25976 KB | Output is correct |
23 | Correct | 167 ms | 25792 KB | Output is correct |
24 | Correct | 168 ms | 25792 KB | Output is correct |
25 | Correct | 172 ms | 25920 KB | Output is correct |
26 | Correct | 170 ms | 25792 KB | Output is correct |
27 | Correct | 426 ms | 42616 KB | Output is correct |
28 | Correct | 427 ms | 42780 KB | Output is correct |
29 | Correct | 422 ms | 42872 KB | Output is correct |
30 | Correct | 432 ms | 42636 KB | Output is correct |
31 | Correct | 423 ms | 42668 KB | Output is correct |
32 | Correct | 385 ms | 43256 KB | Output is correct |
33 | Correct | 374 ms | 43384 KB | Output is correct |
34 | Correct | 358 ms | 43536 KB | Output is correct |
35 | Correct | 347 ms | 43512 KB | Output is correct |
36 | Correct | 348 ms | 43512 KB | Output is correct |
37 | Correct | 344 ms | 43384 KB | Output is correct |
38 | Correct | 1455 ms | 99864 KB | Output is correct |
39 | Correct | 1572 ms | 121636 KB | Output is correct |
40 | Correct | 1033 ms | 86656 KB | Output is correct |
41 | Correct | 1296 ms | 121636 KB | Output is correct |
42 | Correct | 424 ms | 50936 KB | Output is correct |
43 | Correct | 404 ms | 50808 KB | Output is correct |
44 | Correct | 681 ms | 71032 KB | Output is correct |
45 | Correct | 671 ms | 71288 KB | Output is correct |
46 | Correct | 682 ms | 71104 KB | Output is correct |
47 | Correct | 406 ms | 50808 KB | Output is correct |
48 | Correct | 370 ms | 50424 KB | Output is correct |
49 | Correct | 609 ms | 70904 KB | Output is correct |
50 | Correct | 640 ms | 71032 KB | Output is correct |
51 | Correct | 682 ms | 71400 KB | Output is correct |
52 | Correct | 630 ms | 70672 KB | Output is correct |
53 | Correct | 871 ms | 90404 KB | Output is correct |
54 | Correct | 1084 ms | 109904 KB | Output is correct |
55 | Correct | 910 ms | 90552 KB | Output is correct |