Submission #129167

# Submission time Handle Problem Language Result Execution time Memory
129167 2019-07-11T18:39:51 Z doowey Long Mansion (JOI17_long_mansion) C++14
100 / 100
525 ms 56568 KB
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ld, ld> pdd;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)5e5 + 9;

int value[N * 4 + 512];

void modify(int node,int cl, int cr, int p, int v){
    if(cl == cr){
        value[node] = v;
        return;
    }
    int mid = (cl + cr) / 2;
    if(mid >= p)
        modify(node * 2, cl, mid, p, v);
    else
        modify(node * 2 + 1, mid + 1, cr, p, v);
    value[node] = min(value[node * 2], value[node * 2 + 1]);
}

int ask(int node, int cl, int cr, int x){
    if(cl == cr)
        return cl;
    int mid = (cl + cr) / 2;
    if(value[node * 2] < x)
        return ask(node * 2, cl, mid, x); 
    else
        return ask(node * 2 + 1, mid + 1, cr, x);
}

int fin(int node, int cl, int cr, int p){
    if(cl == cr){
        return value[node];
    }
    int mid = (cl + cr) / 2;
    if(mid >= p)
        return fin(node * 2, cl, mid, p);
    else
        return fin(node * 2 + 1, mid + 1, cr, p);
}

int gl[N];
int gr[N];
int req[N];
vector<int> col[N];
int las[N];
int lm[N];
int rm[N];

int m;


int main(){
    fastIO;
    int n;
    cin >> n;
    for(int i = 1; i < n; i ++ )
        cin >> req[i];
    int k, m;
    for(int i = 1; i <= n; i ++ ){
        cin >> k;
        for(int j = 0 ; j < k ; j ++ ){
            cin >> m;
            col[i].push_back(m);
        }
    }
    m = n + 1;
    for(int i = 1; i <= n; i ++ )
        las[i] = n + 1;
    for(int i = n ;i > 1; i -- ){
        for(auto p : col[i])
            las[p] = i;
        gl[i - 1] = las[req[i - 1]];
    }
    for(int i = 1; i <= n ; i ++ )
        las[i] = 0;
    for(int i = 1; i < n; i ++ ){
        for(auto p : col[i])
            las[p] = i;
        gr[i + 1] = las[req[i]];
    }
    modify(1, 1, m, 1, N);
    for(int i = 2; i <= n; i ++ )
        modify(1, 1, m, i, gr[i]);
    vector<int> id;
    rm[1] = ask(1, 1, m, 1) - 1;
    lm[1] = 1;
    for(int i = 2 ; i <= n; i ++ ){
        lm[i] = i;
        rm[i] = i;
        modify(1, 1, m, i, N);
        while(1){
            rm[i] = ask(1, 1, m, lm[i]) - 1;
            if(lm[i] == 1 || gl[lm[i] - 1] > rm[i]) break;
            lm[i] = lm[lm[i] - 1];
        }
    }
    int q;
    cin >> q;
    int x, y;
    for(int i = 0 ; i < q; i ++ ){
        cin >> x >> y;
        if(y >= lm[x] && y <= rm[x])
            cout << "YES\n";
        else
            cout << "NO\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 16 ms 12280 KB Output is correct
2 Correct 16 ms 12408 KB Output is correct
3 Correct 17 ms 12536 KB Output is correct
4 Correct 16 ms 12408 KB Output is correct
5 Correct 16 ms 12268 KB Output is correct
6 Correct 16 ms 12536 KB Output is correct
7 Correct 15 ms 12280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 12280 KB Output is correct
2 Correct 16 ms 12408 KB Output is correct
3 Correct 17 ms 12536 KB Output is correct
4 Correct 16 ms 12408 KB Output is correct
5 Correct 16 ms 12268 KB Output is correct
6 Correct 16 ms 12536 KB Output is correct
7 Correct 15 ms 12280 KB Output is correct
8 Correct 130 ms 13916 KB Output is correct
9 Correct 128 ms 13944 KB Output is correct
10 Correct 132 ms 14072 KB Output is correct
11 Correct 130 ms 14456 KB Output is correct
12 Correct 118 ms 14284 KB Output is correct
13 Correct 131 ms 14144 KB Output is correct
14 Correct 127 ms 18424 KB Output is correct
15 Correct 126 ms 18336 KB Output is correct
16 Correct 125 ms 18172 KB Output is correct
17 Correct 127 ms 18332 KB Output is correct
18 Correct 131 ms 18476 KB Output is correct
19 Correct 126 ms 18436 KB Output is correct
20 Correct 127 ms 18396 KB Output is correct
21 Correct 125 ms 18168 KB Output is correct
22 Correct 128 ms 18300 KB Output is correct
23 Correct 128 ms 18168 KB Output is correct
24 Correct 132 ms 18156 KB Output is correct
25 Correct 128 ms 18152 KB Output is correct
26 Correct 126 ms 18168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 252 ms 21112 KB Output is correct
2 Correct 258 ms 21052 KB Output is correct
3 Correct 241 ms 20984 KB Output is correct
4 Correct 254 ms 21112 KB Output is correct
5 Correct 256 ms 21112 KB Output is correct
6 Correct 222 ms 20600 KB Output is correct
7 Correct 216 ms 26744 KB Output is correct
8 Correct 214 ms 26608 KB Output is correct
9 Correct 213 ms 26744 KB Output is correct
10 Correct 233 ms 26692 KB Output is correct
11 Correct 215 ms 26744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 12280 KB Output is correct
2 Correct 16 ms 12408 KB Output is correct
3 Correct 17 ms 12536 KB Output is correct
4 Correct 16 ms 12408 KB Output is correct
5 Correct 16 ms 12268 KB Output is correct
6 Correct 16 ms 12536 KB Output is correct
7 Correct 15 ms 12280 KB Output is correct
8 Correct 130 ms 13916 KB Output is correct
9 Correct 128 ms 13944 KB Output is correct
10 Correct 132 ms 14072 KB Output is correct
11 Correct 130 ms 14456 KB Output is correct
12 Correct 118 ms 14284 KB Output is correct
13 Correct 131 ms 14144 KB Output is correct
14 Correct 127 ms 18424 KB Output is correct
15 Correct 126 ms 18336 KB Output is correct
16 Correct 125 ms 18172 KB Output is correct
17 Correct 127 ms 18332 KB Output is correct
18 Correct 131 ms 18476 KB Output is correct
19 Correct 126 ms 18436 KB Output is correct
20 Correct 127 ms 18396 KB Output is correct
21 Correct 125 ms 18168 KB Output is correct
22 Correct 128 ms 18300 KB Output is correct
23 Correct 128 ms 18168 KB Output is correct
24 Correct 132 ms 18156 KB Output is correct
25 Correct 128 ms 18152 KB Output is correct
26 Correct 126 ms 18168 KB Output is correct
27 Correct 252 ms 21112 KB Output is correct
28 Correct 258 ms 21052 KB Output is correct
29 Correct 241 ms 20984 KB Output is correct
30 Correct 254 ms 21112 KB Output is correct
31 Correct 256 ms 21112 KB Output is correct
32 Correct 222 ms 20600 KB Output is correct
33 Correct 216 ms 26744 KB Output is correct
34 Correct 214 ms 26608 KB Output is correct
35 Correct 213 ms 26744 KB Output is correct
36 Correct 233 ms 26692 KB Output is correct
37 Correct 215 ms 26744 KB Output is correct
38 Correct 438 ms 51292 KB Output is correct
39 Correct 517 ms 56568 KB Output is correct
40 Correct 407 ms 44792 KB Output is correct
41 Correct 525 ms 55016 KB Output is correct
42 Correct 218 ms 27768 KB Output is correct
43 Correct 222 ms 27848 KB Output is correct
44 Correct 323 ms 37076 KB Output is correct
45 Correct 334 ms 37056 KB Output is correct
46 Correct 336 ms 37240 KB Output is correct
47 Correct 220 ms 27896 KB Output is correct
48 Correct 221 ms 27644 KB Output is correct
49 Correct 324 ms 36988 KB Output is correct
50 Correct 324 ms 37112 KB Output is correct
51 Correct 345 ms 37388 KB Output is correct
52 Correct 334 ms 35844 KB Output is correct
53 Correct 390 ms 45160 KB Output is correct
54 Correct 455 ms 52252 KB Output is correct
55 Correct 385 ms 45404 KB Output is correct