Submission #95291

# Submission time Handle Problem Language Result Execution time Memory
95291 2019-01-29T18:09:06 Z dalgerok Long Mansion (JOI17_long_mansion) C++14
100 / 100
304 ms 52432 KB
#include<bits/stdc++.h>
using namespace std;


const int N = 5e5 + 5;



int n, m, c[N], last[N], le[N], ri[N], st[N], en[N];
vector < int > q[N];

inline bool check_left(int i){
    return st[i] > 1 && ri[st[i] - 1] != -1 && ri[st[i] - 1] <= en[i];
}
inline bool check_right(int i){
    return en[i] < n && le[en[i]] != -1 && st[i] <= le[en[i]];
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.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(check_left(i)){
                en[i] = max(en[i], en[st[i] - 1]);
                st[i] = min(st[i], st[st[i] - 1]);
            }
            else if(check_right(i)){
                en[i] += 1;
            }
            else{
                break;
            }
        }
    }
    cin >> m;
    while(m--){
        int x, y;
        cin >> x >> y;
        cout << (st[x] <= y && y <= en[x] ? "YES\n" : "NO\n");
    }
}
# Verdict Execution time Memory Grader output
1 Correct 16 ms 14200 KB Output is correct
2 Correct 16 ms 14328 KB Output is correct
3 Correct 16 ms 14456 KB Output is correct
4 Correct 16 ms 14328 KB Output is correct
5 Correct 16 ms 14200 KB Output is correct
6 Correct 16 ms 14316 KB Output is correct
7 Correct 15 ms 14200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 14200 KB Output is correct
2 Correct 16 ms 14328 KB Output is correct
3 Correct 16 ms 14456 KB Output is correct
4 Correct 16 ms 14328 KB Output is correct
5 Correct 16 ms 14200 KB Output is correct
6 Correct 16 ms 14316 KB Output is correct
7 Correct 15 ms 14200 KB Output is correct
8 Correct 111 ms 20092 KB Output is correct
9 Correct 110 ms 20092 KB Output is correct
10 Correct 109 ms 20552 KB Output is correct
11 Correct 107 ms 20788 KB Output is correct
12 Correct 97 ms 19660 KB Output is correct
13 Correct 107 ms 20392 KB Output is correct
14 Correct 106 ms 20344 KB Output is correct
15 Correct 105 ms 20216 KB Output is correct
16 Correct 104 ms 20132 KB Output is correct
17 Correct 103 ms 20288 KB Output is correct
18 Correct 107 ms 20216 KB Output is correct
19 Correct 262 ms 20216 KB Output is correct
20 Correct 103 ms 20344 KB Output is correct
21 Correct 100 ms 20088 KB Output is correct
22 Correct 102 ms 20172 KB Output is correct
23 Correct 104 ms 20176 KB Output is correct
24 Correct 102 ms 19960 KB Output is correct
25 Correct 101 ms 20092 KB Output is correct
26 Correct 101 ms 20060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 181 ms 28820 KB Output is correct
2 Correct 182 ms 28596 KB Output is correct
3 Correct 173 ms 28380 KB Output is correct
4 Correct 188 ms 28792 KB Output is correct
5 Correct 190 ms 28792 KB Output is correct
6 Correct 160 ms 27512 KB Output is correct
7 Correct 162 ms 27256 KB Output is correct
8 Correct 156 ms 27260 KB Output is correct
9 Correct 159 ms 27196 KB Output is correct
10 Correct 156 ms 27128 KB Output is correct
11 Correct 151 ms 27256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 14200 KB Output is correct
2 Correct 16 ms 14328 KB Output is correct
3 Correct 16 ms 14456 KB Output is correct
4 Correct 16 ms 14328 KB Output is correct
5 Correct 16 ms 14200 KB Output is correct
6 Correct 16 ms 14316 KB Output is correct
7 Correct 15 ms 14200 KB Output is correct
8 Correct 111 ms 20092 KB Output is correct
9 Correct 110 ms 20092 KB Output is correct
10 Correct 109 ms 20552 KB Output is correct
11 Correct 107 ms 20788 KB Output is correct
12 Correct 97 ms 19660 KB Output is correct
13 Correct 107 ms 20392 KB Output is correct
14 Correct 106 ms 20344 KB Output is correct
15 Correct 105 ms 20216 KB Output is correct
16 Correct 104 ms 20132 KB Output is correct
17 Correct 103 ms 20288 KB Output is correct
18 Correct 107 ms 20216 KB Output is correct
19 Correct 262 ms 20216 KB Output is correct
20 Correct 103 ms 20344 KB Output is correct
21 Correct 100 ms 20088 KB Output is correct
22 Correct 102 ms 20172 KB Output is correct
23 Correct 104 ms 20176 KB Output is correct
24 Correct 102 ms 19960 KB Output is correct
25 Correct 101 ms 20092 KB Output is correct
26 Correct 101 ms 20060 KB Output is correct
27 Correct 181 ms 28820 KB Output is correct
28 Correct 182 ms 28596 KB Output is correct
29 Correct 173 ms 28380 KB Output is correct
30 Correct 188 ms 28792 KB Output is correct
31 Correct 190 ms 28792 KB Output is correct
32 Correct 160 ms 27512 KB Output is correct
33 Correct 162 ms 27256 KB Output is correct
34 Correct 156 ms 27260 KB Output is correct
35 Correct 159 ms 27196 KB Output is correct
36 Correct 156 ms 27128 KB Output is correct
37 Correct 151 ms 27256 KB Output is correct
38 Correct 291 ms 47544 KB Output is correct
39 Correct 304 ms 52432 KB Output is correct
40 Correct 265 ms 41484 KB Output is correct
41 Correct 278 ms 50808 KB Output is correct
42 Correct 162 ms 28280 KB Output is correct
43 Correct 162 ms 28300 KB Output is correct
44 Correct 227 ms 36216 KB Output is correct
45 Correct 221 ms 36292 KB Output is correct
46 Correct 228 ms 36472 KB Output is correct
47 Correct 157 ms 28408 KB Output is correct
48 Correct 155 ms 28280 KB Output is correct
49 Correct 221 ms 35960 KB Output is correct
50 Correct 215 ms 36216 KB Output is correct
51 Correct 260 ms 36472 KB Output is correct
52 Correct 207 ms 34936 KB Output is correct
53 Correct 255 ms 41872 KB Output is correct
54 Correct 276 ms 48508 KB Output is correct
55 Correct 257 ms 41848 KB Output is correct