Submission #1110009

# Submission time Handle Problem Language Result Execution time Memory
1110009 2024-11-08T12:35:48 Z Warinchai Long Mansion (JOI17_long_mansion) C++14
100 / 100
275 ms 37192 KB
#include<bits/stdc++.h>
using namespace std;
int c[500005];
vector<int>key[500005];
int l[500005];
int r[500005];
int have[500005];
vector<int>del;
void upd(int i,int &curl,int &curr,int st,int en){
    while(1){
        int check=0;
        while(curr<en&&have[c[curr]]){
            curr++;
            for(auto a:key[curr])if(!(have[a]++))del.push_back(a);
            check=1;
        }
        while(curl>st&&have[c[curl-1]]){
            curl--;
            for(auto a:key[curl])if(!(have[a]++))del.push_back(a);
            check=1;
        }
        if(!check)break;
    }
    r[i]=curr;
    l[i]=curl;
}
void solve(int st,int en){
    int m=(st+en)/2;
    if(st==en)return l[m]=m,r[m]=m,void();
    vector<pair<int,int>>ll,lr,rl,rr;
    solve(st,m);
    solve(m+1,en);
    int curr=m,curl=m+1;
    for(int i=m;i>=st;i--){
        if(r[i]<m)continue;
        while(curl>st&&curl>l[i]){
            curl--;
            for(auto a:key[curl])if(!(have[a]++))del.push_back(a);
        }
        upd(i,curl,curr,st,en);
    }
    for(auto x:del)have[x]=0;
    del.clear();
    curr=m,curl=m+1;
    for(int i=m+1;i<=en;i++){
        if(l[i]>m+1)continue;
        while(curr<en&&curr<r[i]){
            curr++;
            for(auto a:key[curr])if(!(have[a]++))del.push_back(a);
        }
        upd(i,curl,curr,st,en);
    }
    for(auto x:del)have[x]=0;
    del.clear();
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;cin>>n;
    for(int i=1;i<n;i++)cin>>c[i];
    for(int i=1;i<=n;i++){
        int b;cin>>b;
        for(int j=0;j<b;j++){
            int x;cin>>x;
            key[i].push_back(x);
        }
    }
    solve(1,n);
    int q;cin>>q;
    for(int i=0;i<q;i++){
        int x,y;cin>>x>>y;
        if(y>=l[x]&&y<=r[x])cout<<"YES\n";
        else cout<<"NO\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 18768 KB Output is correct
2 Correct 4 ms 19024 KB Output is correct
3 Correct 5 ms 19024 KB Output is correct
4 Correct 4 ms 19024 KB Output is correct
5 Correct 4 ms 18768 KB Output is correct
6 Correct 4 ms 19024 KB Output is correct
7 Correct 5 ms 19024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 18768 KB Output is correct
2 Correct 4 ms 19024 KB Output is correct
3 Correct 5 ms 19024 KB Output is correct
4 Correct 4 ms 19024 KB Output is correct
5 Correct 4 ms 18768 KB Output is correct
6 Correct 4 ms 19024 KB Output is correct
7 Correct 5 ms 19024 KB Output is correct
8 Correct 69 ms 20388 KB Output is correct
9 Correct 59 ms 20296 KB Output is correct
10 Correct 58 ms 20552 KB Output is correct
11 Correct 63 ms 20808 KB Output is correct
12 Correct 57 ms 20464 KB Output is correct
13 Correct 60 ms 20544 KB Output is correct
14 Correct 59 ms 20552 KB Output is correct
15 Correct 58 ms 20564 KB Output is correct
16 Correct 55 ms 20808 KB Output is correct
17 Correct 57 ms 20552 KB Output is correct
18 Correct 58 ms 20504 KB Output is correct
19 Correct 60 ms 20720 KB Output is correct
20 Correct 63 ms 20808 KB Output is correct
21 Correct 57 ms 20808 KB Output is correct
22 Correct 57 ms 20552 KB Output is correct
23 Correct 68 ms 20396 KB Output is correct
24 Correct 61 ms 20552 KB Output is correct
25 Correct 62 ms 20568 KB Output is correct
26 Correct 63 ms 20564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 155 ms 24140 KB Output is correct
2 Correct 160 ms 24136 KB Output is correct
3 Correct 160 ms 24136 KB Output is correct
4 Correct 155 ms 24136 KB Output is correct
5 Correct 152 ms 24136 KB Output is correct
6 Correct 133 ms 23852 KB Output is correct
7 Correct 113 ms 23880 KB Output is correct
8 Correct 116 ms 23880 KB Output is correct
9 Correct 111 ms 23880 KB Output is correct
10 Correct 127 ms 23880 KB Output is correct
11 Correct 118 ms 23880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 18768 KB Output is correct
2 Correct 4 ms 19024 KB Output is correct
3 Correct 5 ms 19024 KB Output is correct
4 Correct 4 ms 19024 KB Output is correct
5 Correct 4 ms 18768 KB Output is correct
6 Correct 4 ms 19024 KB Output is correct
7 Correct 5 ms 19024 KB Output is correct
8 Correct 69 ms 20388 KB Output is correct
9 Correct 59 ms 20296 KB Output is correct
10 Correct 58 ms 20552 KB Output is correct
11 Correct 63 ms 20808 KB Output is correct
12 Correct 57 ms 20464 KB Output is correct
13 Correct 60 ms 20544 KB Output is correct
14 Correct 59 ms 20552 KB Output is correct
15 Correct 58 ms 20564 KB Output is correct
16 Correct 55 ms 20808 KB Output is correct
17 Correct 57 ms 20552 KB Output is correct
18 Correct 58 ms 20504 KB Output is correct
19 Correct 60 ms 20720 KB Output is correct
20 Correct 63 ms 20808 KB Output is correct
21 Correct 57 ms 20808 KB Output is correct
22 Correct 57 ms 20552 KB Output is correct
23 Correct 68 ms 20396 KB Output is correct
24 Correct 61 ms 20552 KB Output is correct
25 Correct 62 ms 20568 KB Output is correct
26 Correct 63 ms 20564 KB Output is correct
27 Correct 155 ms 24140 KB Output is correct
28 Correct 160 ms 24136 KB Output is correct
29 Correct 160 ms 24136 KB Output is correct
30 Correct 155 ms 24136 KB Output is correct
31 Correct 152 ms 24136 KB Output is correct
32 Correct 133 ms 23852 KB Output is correct
33 Correct 113 ms 23880 KB Output is correct
34 Correct 116 ms 23880 KB Output is correct
35 Correct 111 ms 23880 KB Output is correct
36 Correct 127 ms 23880 KB Output is correct
37 Correct 118 ms 23880 KB Output is correct
38 Correct 163 ms 33288 KB Output is correct
39 Correct 177 ms 36936 KB Output is correct
40 Correct 155 ms 29776 KB Output is correct
41 Correct 275 ms 37192 KB Output is correct
42 Correct 109 ms 23732 KB Output is correct
43 Correct 107 ms 23888 KB Output is correct
44 Correct 151 ms 26952 KB Output is correct
45 Correct 161 ms 27112 KB Output is correct
46 Correct 184 ms 26956 KB Output is correct
47 Correct 135 ms 24264 KB Output is correct
48 Correct 127 ms 23880 KB Output is correct
49 Correct 231 ms 27120 KB Output is correct
50 Correct 205 ms 27332 KB Output is correct
51 Correct 222 ms 27328 KB Output is correct
52 Correct 136 ms 27752 KB Output is correct
53 Correct 175 ms 31164 KB Output is correct
54 Correct 205 ms 35768 KB Output is correct
55 Correct 160 ms 32188 KB Output is correct