Submission #98134

# Submission time Handle Problem Language Result Execution time Memory
98134 2019-02-21T00:58:35 Z silxikys Long Mansion (JOI17_long_mansion) C++14
100 / 100
371 ms 41592 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int maxn = 5e5+5;
int n, Q, c[maxn], last[maxn], le[maxn], ri[maxn], st[maxn], en[maxn];
vector<int> q[maxn];

bool cleft(int i) {
    return st[i] > 1 && ri[st[i]-1] != -1 && ri[st[i]-1] <= en[i];
}

bool cright(int i) {
    return en[i] < n && le[en[i]] != -1 && st[i] <= le[en[i]];
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n;
    for (int i = 1; i < n; i++) cin >> c[i];
    for (int i = 1; i <= n; i++) {
        int x, y; cin >> x;
        while (x--) {
            cin >> y;
            q[i].push_back(y);
        }
    }
    memset(last,-1,sizeof(last));
    for (int i = 1; i < n; i++) {
        for (int j: q[i]) {
            last[j] = i;
        }
        le[i] = last[c[i]];
    }
    memset(last,-1,sizeof(last));
    for (int i = n - 1; i >= 1; i--) {
        for (int j: q[i+1]) {
            last[j] = i + 1;
        }
        ri[i] = last[c[i]];
    }
    for (int i = 1; i <= n; i++) {
        st[i] = en[i] = i;
        while (true) {
            if (cleft(i)) {
                en[i] = max(en[i],en[st[i]-1]);
                st[i] = min(st[i],st[st[i]-1]);
            }
            else if (cright(i)) ++en[i];
            else break;
        }
    }
    cin >> Q;
    while (Q--) {
        int a, b; cin >> a >> b;
        cout << (st[a] <= b && b <= en[a] ? "YES" : "NO") << '\n';
    }
}

# Verdict Execution time Memory Grader output
1 Correct 22 ms 14208 KB Output is correct
2 Correct 17 ms 14336 KB Output is correct
3 Correct 19 ms 14336 KB Output is correct
4 Correct 16 ms 14336 KB Output is correct
5 Correct 16 ms 14208 KB Output is correct
6 Correct 17 ms 14336 KB Output is correct
7 Correct 16 ms 14208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 14208 KB Output is correct
2 Correct 17 ms 14336 KB Output is correct
3 Correct 19 ms 14336 KB Output is correct
4 Correct 16 ms 14336 KB Output is correct
5 Correct 16 ms 14208 KB Output is correct
6 Correct 17 ms 14336 KB Output is correct
7 Correct 16 ms 14208 KB Output is correct
8 Correct 129 ms 16528 KB Output is correct
9 Correct 137 ms 16476 KB Output is correct
10 Correct 156 ms 16736 KB Output is correct
11 Correct 135 ms 16888 KB Output is correct
12 Correct 139 ms 16888 KB Output is correct
13 Correct 143 ms 16760 KB Output is correct
14 Correct 163 ms 16892 KB Output is correct
15 Correct 135 ms 16888 KB Output is correct
16 Correct 134 ms 17016 KB Output is correct
17 Correct 128 ms 16760 KB Output is correct
18 Correct 165 ms 16756 KB Output is correct
19 Correct 124 ms 16760 KB Output is correct
20 Correct 125 ms 16888 KB Output is correct
21 Correct 121 ms 17016 KB Output is correct
22 Correct 145 ms 16840 KB Output is correct
23 Correct 125 ms 16640 KB Output is correct
24 Correct 133 ms 16632 KB Output is correct
25 Correct 141 ms 16632 KB Output is correct
26 Correct 210 ms 16504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 219 ms 22296 KB Output is correct
2 Correct 226 ms 22048 KB Output is correct
3 Correct 217 ms 21908 KB Output is correct
4 Correct 216 ms 22008 KB Output is correct
5 Correct 213 ms 21948 KB Output is correct
6 Correct 184 ms 21488 KB Output is correct
7 Correct 180 ms 21752 KB Output is correct
8 Correct 180 ms 21708 KB Output is correct
9 Correct 192 ms 21544 KB Output is correct
10 Correct 189 ms 21624 KB Output is correct
11 Correct 205 ms 21700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 14208 KB Output is correct
2 Correct 17 ms 14336 KB Output is correct
3 Correct 19 ms 14336 KB Output is correct
4 Correct 16 ms 14336 KB Output is correct
5 Correct 16 ms 14208 KB Output is correct
6 Correct 17 ms 14336 KB Output is correct
7 Correct 16 ms 14208 KB Output is correct
8 Correct 129 ms 16528 KB Output is correct
9 Correct 137 ms 16476 KB Output is correct
10 Correct 156 ms 16736 KB Output is correct
11 Correct 135 ms 16888 KB Output is correct
12 Correct 139 ms 16888 KB Output is correct
13 Correct 143 ms 16760 KB Output is correct
14 Correct 163 ms 16892 KB Output is correct
15 Correct 135 ms 16888 KB Output is correct
16 Correct 134 ms 17016 KB Output is correct
17 Correct 128 ms 16760 KB Output is correct
18 Correct 165 ms 16756 KB Output is correct
19 Correct 124 ms 16760 KB Output is correct
20 Correct 125 ms 16888 KB Output is correct
21 Correct 121 ms 17016 KB Output is correct
22 Correct 145 ms 16840 KB Output is correct
23 Correct 125 ms 16640 KB Output is correct
24 Correct 133 ms 16632 KB Output is correct
25 Correct 141 ms 16632 KB Output is correct
26 Correct 210 ms 16504 KB Output is correct
27 Correct 219 ms 22296 KB Output is correct
28 Correct 226 ms 22048 KB Output is correct
29 Correct 217 ms 21908 KB Output is correct
30 Correct 216 ms 22008 KB Output is correct
31 Correct 213 ms 21948 KB Output is correct
32 Correct 184 ms 21488 KB Output is correct
33 Correct 180 ms 21752 KB Output is correct
34 Correct 180 ms 21708 KB Output is correct
35 Correct 192 ms 21544 KB Output is correct
36 Correct 189 ms 21624 KB Output is correct
37 Correct 205 ms 21700 KB Output is correct
38 Correct 371 ms 36308 KB Output is correct
39 Correct 356 ms 41464 KB Output is correct
40 Correct 360 ms 31252 KB Output is correct
41 Correct 343 ms 41592 KB Output is correct
42 Correct 188 ms 21328 KB Output is correct
43 Correct 212 ms 21240 KB Output is correct
44 Correct 273 ms 26428 KB Output is correct
45 Correct 356 ms 26364 KB Output is correct
46 Correct 280 ms 26492 KB Output is correct
47 Correct 204 ms 21240 KB Output is correct
48 Correct 205 ms 21496 KB Output is correct
49 Correct 269 ms 26360 KB Output is correct
50 Correct 301 ms 26408 KB Output is correct
51 Correct 285 ms 26332 KB Output is correct
52 Correct 290 ms 26252 KB Output is correct
53 Correct 327 ms 31152 KB Output is correct
54 Correct 370 ms 36088 KB Output is correct
55 Correct 318 ms 31236 KB Output is correct