답안 #1109990

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1109990 2024-11-08T11:30:53 Z ttamx Long Mansion (JOI17_long_mansion) C++17
100 / 100
289 ms 48200 KB
#include<bits/stdc++.h>

using namespace std;

const int N=5e5+5;

int n,q;
int a[N];
vector<int> keys[N];
int l[N],r[N];
int cnt[N];

void update(int x,int v){
    for(auto i:keys[x]){
        cnt[i]+=v;
    }
}

void solve(int cl,int cr){
    if(cl==cr){
        l[cl]=r[cl]=cl;
        return;
    }
    int m=(cl+cr)/2;
    solve(cl,m);
    solve(m+1,cr);
    int st=m+1,ed=m;
    for(int i=m;i>=cl;i--){
        if(r[i]<m){
            continue;
        }
        while(st>i){
            st--;
            update(st,+1);
        }
        while(true){
            if(st>cl&&cnt[a[st-1]]>0){
                st--;
                update(st,+1);
            }else if(ed<cr&&cnt[a[ed]]>0){
                ed++;
                update(ed,+1);
            }else{
                break;
            }
        }
        l[i]=st;
        r[i]=ed;
    }
    while(st<=ed){
        update(st,-1);
        st++;
    }
    st=m+1;
    ed=m;
    for(int i=m+1;i<=cr;i++){
        if(l[i]>m+1){
            continue;
        }
        while(ed<i){
            ed++;
            update(ed,+1);
        }
        while(true){
            if(st>cl&&cnt[a[st-1]]>0){
                st--;
                update(st,+1);
            }else if(ed<cr&&cnt[a[ed]]>0){
                ed++;
                update(ed,+1);
            }else{
                break;
            }
        }
        l[i]=st;
        r[i]=ed;
    }
    while(st<=ed){
        update(st,-1);
        st++;
    }
}

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n;
    for(int i=1;i<=n-1;i++){
        cin >> a[i];
    }
    for(int i=1;i<=n;i++){
        int s;
        cin >> s;
        keys[i].resize(s);
        for(auto &x:keys[i]){
            cin >> x;
        }
    }
    solve(1,n);
    cin >> q;
    while(q--){
        int x,y;
        cin >> x >> y;
        cout << ((l[x]<=y&&y<=r[x])?"YES":"NO") << "\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 19024 KB Output is correct
2 Correct 5 ms 18940 KB Output is correct
3 Correct 6 ms 19184 KB Output is correct
4 Correct 5 ms 18952 KB Output is correct
5 Correct 5 ms 19024 KB Output is correct
6 Correct 4 ms 19024 KB Output is correct
7 Correct 5 ms 19064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 19024 KB Output is correct
2 Correct 5 ms 18940 KB Output is correct
3 Correct 6 ms 19184 KB Output is correct
4 Correct 5 ms 18952 KB Output is correct
5 Correct 5 ms 19024 KB Output is correct
6 Correct 4 ms 19024 KB Output is correct
7 Correct 5 ms 19064 KB Output is correct
8 Correct 77 ms 24820 KB Output is correct
9 Correct 77 ms 24648 KB Output is correct
10 Correct 71 ms 25196 KB Output is correct
11 Correct 81 ms 25488 KB Output is correct
12 Correct 65 ms 24392 KB Output is correct
13 Correct 73 ms 25036 KB Output is correct
14 Correct 69 ms 24904 KB Output is correct
15 Correct 75 ms 24904 KB Output is correct
16 Correct 69 ms 24912 KB Output is correct
17 Correct 69 ms 24904 KB Output is correct
18 Correct 69 ms 24904 KB Output is correct
19 Correct 70 ms 24912 KB Output is correct
20 Correct 77 ms 25052 KB Output is correct
21 Correct 75 ms 24904 KB Output is correct
22 Correct 70 ms 24956 KB Output is correct
23 Correct 71 ms 24648 KB Output is correct
24 Correct 71 ms 24892 KB Output is correct
25 Correct 71 ms 24820 KB Output is correct
26 Correct 69 ms 24648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 168 ms 31048 KB Output is correct
2 Correct 173 ms 30792 KB Output is correct
3 Correct 164 ms 30804 KB Output is correct
4 Correct 167 ms 31048 KB Output is correct
5 Correct 172 ms 30812 KB Output is correct
6 Correct 128 ms 26184 KB Output is correct
7 Correct 118 ms 30028 KB Output is correct
8 Correct 119 ms 30024 KB Output is correct
9 Correct 121 ms 30108 KB Output is correct
10 Correct 122 ms 30024 KB Output is correct
11 Correct 115 ms 30024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 19024 KB Output is correct
2 Correct 5 ms 18940 KB Output is correct
3 Correct 6 ms 19184 KB Output is correct
4 Correct 5 ms 18952 KB Output is correct
5 Correct 5 ms 19024 KB Output is correct
6 Correct 4 ms 19024 KB Output is correct
7 Correct 5 ms 19064 KB Output is correct
8 Correct 77 ms 24820 KB Output is correct
9 Correct 77 ms 24648 KB Output is correct
10 Correct 71 ms 25196 KB Output is correct
11 Correct 81 ms 25488 KB Output is correct
12 Correct 65 ms 24392 KB Output is correct
13 Correct 73 ms 25036 KB Output is correct
14 Correct 69 ms 24904 KB Output is correct
15 Correct 75 ms 24904 KB Output is correct
16 Correct 69 ms 24912 KB Output is correct
17 Correct 69 ms 24904 KB Output is correct
18 Correct 69 ms 24904 KB Output is correct
19 Correct 70 ms 24912 KB Output is correct
20 Correct 77 ms 25052 KB Output is correct
21 Correct 75 ms 24904 KB Output is correct
22 Correct 70 ms 24956 KB Output is correct
23 Correct 71 ms 24648 KB Output is correct
24 Correct 71 ms 24892 KB Output is correct
25 Correct 71 ms 24820 KB Output is correct
26 Correct 69 ms 24648 KB Output is correct
27 Correct 168 ms 31048 KB Output is correct
28 Correct 173 ms 30792 KB Output is correct
29 Correct 164 ms 30804 KB Output is correct
30 Correct 167 ms 31048 KB Output is correct
31 Correct 172 ms 30812 KB Output is correct
32 Correct 128 ms 26184 KB Output is correct
33 Correct 118 ms 30028 KB Output is correct
34 Correct 119 ms 30024 KB Output is correct
35 Correct 121 ms 30108 KB Output is correct
36 Correct 122 ms 30024 KB Output is correct
37 Correct 115 ms 30024 KB Output is correct
38 Correct 171 ms 45128 KB Output is correct
39 Correct 180 ms 48200 KB Output is correct
40 Correct 176 ms 40520 KB Output is correct
41 Correct 289 ms 46792 KB Output is correct
42 Correct 104 ms 31392 KB Output is correct
43 Correct 123 ms 31156 KB Output is correct
44 Correct 145 ms 36936 KB Output is correct
45 Correct 151 ms 37192 KB Output is correct
46 Correct 155 ms 37448 KB Output is correct
47 Correct 115 ms 31460 KB Output is correct
48 Correct 115 ms 31048 KB Output is correct
49 Correct 159 ms 37156 KB Output is correct
50 Correct 169 ms 37208 KB Output is correct
51 Correct 164 ms 37456 KB Output is correct
52 Correct 127 ms 36088 KB Output is correct
53 Correct 180 ms 41032 KB Output is correct
54 Correct 177 ms 46152 KB Output is correct
55 Correct 157 ms 41212 KB Output is correct