답안 #990326

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
990326 2024-05-30T08:04:54 Z xyzaa Long Mansion (JOI17_long_mansion) C++17
100 / 100
610 ms 50256 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 500008;
int n, q, c[N], sz[N], L[N], R[N], cl[N], cr[N];
bool proc[N];
vector<int> key[N];

void dnc(int l, int r) {
    if (l > r) return;
    int mid = (l + r) / 2;
    if (proc[mid]) return;
    while (true) {
        if (L[mid] != 1 && cr[L[mid] - 1] <= R[mid]) {
            L[mid]--;
            if (proc[L[mid]]) {
                L[mid] = min(L[L[mid]], L[mid]);
                R[mid] = max(R[L[mid]], R[mid]);
            }
        } else if (R[mid] != n && cl[R[mid]] >= L[mid]) {
            R[mid]++;
            if (proc[R[mid]]) {
                L[mid] = min(L[R[mid]], L[mid]);
                R[mid] = max(R[R[mid]], R[mid]);
            }
        } else break;
    }
    proc[mid] = true;
    dnc(l, mid);
    dnc(mid + 1, r);
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for (int i = 1; i < n; i++) cin >> c[i];
    for (int i = 1; i <= n; i++) {
        cin >> sz[i];
        L[i] = R[i] = i;
        for (int j = 0, x; j < sz[i]; j++) {
            cin >> x;
            key[x].push_back(i);
        }
    }
    for (int i = 1; i <= n - 1; i++) {
        auto it = upper_bound(key[c[i]].begin(), key[c[i]].end(), i);
        if (it == key[c[i]].begin()) cl[i] = -1;
        else cl[i] = *(--it);
        it = lower_bound(key[c[i]].begin(), key[c[i]].end(), i + 1);
        if (it == key[c[i]].end()) cr[i] = n + 1;
        else cr[i] = *it;
    }
    dnc(1, n);
    // for (int i = 1; i <= n; i++) cout << L[i] << ' ' << R[i] << '\n';
    cin >> q;
    while (q--) {
        int x, y;
        cin >> x >> y;
        if (L[x] <= y && y <= R[x]) cout << "YES\n";
        else cout << "NO\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 23132 KB Output is correct
2 Correct 4 ms 23336 KB Output is correct
3 Correct 5 ms 23212 KB Output is correct
4 Correct 4 ms 23132 KB Output is correct
5 Correct 4 ms 23132 KB Output is correct
6 Correct 4 ms 23132 KB Output is correct
7 Correct 4 ms 23132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 23132 KB Output is correct
2 Correct 4 ms 23336 KB Output is correct
3 Correct 5 ms 23212 KB Output is correct
4 Correct 4 ms 23132 KB Output is correct
5 Correct 4 ms 23132 KB Output is correct
6 Correct 4 ms 23132 KB Output is correct
7 Correct 4 ms 23132 KB Output is correct
8 Correct 58 ms 29012 KB Output is correct
9 Correct 63 ms 29020 KB Output is correct
10 Correct 60 ms 29268 KB Output is correct
11 Correct 59 ms 29624 KB Output is correct
12 Correct 58 ms 28712 KB Output is correct
13 Correct 70 ms 29268 KB Output is correct
14 Correct 55 ms 29268 KB Output is correct
15 Correct 54 ms 29268 KB Output is correct
16 Correct 51 ms 29124 KB Output is correct
17 Correct 54 ms 29268 KB Output is correct
18 Correct 54 ms 29268 KB Output is correct
19 Correct 55 ms 29268 KB Output is correct
20 Correct 54 ms 29264 KB Output is correct
21 Correct 51 ms 29012 KB Output is correct
22 Correct 54 ms 29144 KB Output is correct
23 Correct 58 ms 28904 KB Output is correct
24 Correct 64 ms 29080 KB Output is correct
25 Correct 60 ms 29048 KB Output is correct
26 Correct 60 ms 29012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 270 ms 34388 KB Output is correct
2 Correct 234 ms 33876 KB Output is correct
3 Correct 159 ms 33720 KB Output is correct
4 Correct 287 ms 34380 KB Output is correct
5 Correct 255 ms 34388 KB Output is correct
6 Correct 130 ms 32700 KB Output is correct
7 Correct 80 ms 32340 KB Output is correct
8 Correct 81 ms 32340 KB Output is correct
9 Correct 80 ms 32360 KB Output is correct
10 Correct 81 ms 32340 KB Output is correct
11 Correct 80 ms 32340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 23132 KB Output is correct
2 Correct 4 ms 23336 KB Output is correct
3 Correct 5 ms 23212 KB Output is correct
4 Correct 4 ms 23132 KB Output is correct
5 Correct 4 ms 23132 KB Output is correct
6 Correct 4 ms 23132 KB Output is correct
7 Correct 4 ms 23132 KB Output is correct
8 Correct 58 ms 29012 KB Output is correct
9 Correct 63 ms 29020 KB Output is correct
10 Correct 60 ms 29268 KB Output is correct
11 Correct 59 ms 29624 KB Output is correct
12 Correct 58 ms 28712 KB Output is correct
13 Correct 70 ms 29268 KB Output is correct
14 Correct 55 ms 29268 KB Output is correct
15 Correct 54 ms 29268 KB Output is correct
16 Correct 51 ms 29124 KB Output is correct
17 Correct 54 ms 29268 KB Output is correct
18 Correct 54 ms 29268 KB Output is correct
19 Correct 55 ms 29268 KB Output is correct
20 Correct 54 ms 29264 KB Output is correct
21 Correct 51 ms 29012 KB Output is correct
22 Correct 54 ms 29144 KB Output is correct
23 Correct 58 ms 28904 KB Output is correct
24 Correct 64 ms 29080 KB Output is correct
25 Correct 60 ms 29048 KB Output is correct
26 Correct 60 ms 29012 KB Output is correct
27 Correct 270 ms 34388 KB Output is correct
28 Correct 234 ms 33876 KB Output is correct
29 Correct 159 ms 33720 KB Output is correct
30 Correct 287 ms 34380 KB Output is correct
31 Correct 255 ms 34388 KB Output is correct
32 Correct 130 ms 32700 KB Output is correct
33 Correct 80 ms 32340 KB Output is correct
34 Correct 81 ms 32340 KB Output is correct
35 Correct 80 ms 32360 KB Output is correct
36 Correct 81 ms 32340 KB Output is correct
37 Correct 80 ms 32340 KB Output is correct
38 Correct 151 ms 40200 KB Output is correct
39 Correct 153 ms 40276 KB Output is correct
40 Correct 133 ms 38736 KB Output is correct
41 Correct 610 ms 37928 KB Output is correct
42 Correct 89 ms 33876 KB Output is correct
43 Correct 159 ms 33736 KB Output is correct
44 Correct 141 ms 38740 KB Output is correct
45 Correct 124 ms 38736 KB Output is correct
46 Correct 125 ms 38992 KB Output is correct
47 Correct 91 ms 34188 KB Output is correct
48 Correct 89 ms 33616 KB Output is correct
49 Correct 122 ms 37904 KB Output is correct
50 Correct 128 ms 38484 KB Output is correct
51 Correct 124 ms 39504 KB Output is correct
52 Correct 143 ms 39760 KB Output is correct
53 Correct 128 ms 44752 KB Output is correct
54 Correct 144 ms 50256 KB Output is correct
55 Correct 128 ms 45052 KB Output is correct