Submission #1110008

# Submission time Handle Problem Language Result Execution time Memory
1110008 2024-11-08T12:33:18 Z Warinchai Long Mansion (JOI17_long_mansion) C++14
100 / 100
297 ms 46628 KB
#include<bits/stdc++.h>
using namespace std;
int c[500005];
vector<int>key[500005];
int l[500005];
int r[500005];
int have[500005];
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;
    vector<int>del;
    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);
        }
        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;
    }
    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);
        }
        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;
    }
    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 19024 KB Output is correct
2 Correct 6 ms 19024 KB Output is correct
3 Correct 6 ms 19048 KB Output is correct
4 Correct 5 ms 19024 KB Output is correct
5 Correct 5 ms 18940 KB Output is correct
6 Correct 5 ms 19024 KB Output is correct
7 Correct 4 ms 19024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 19024 KB Output is correct
2 Correct 6 ms 19024 KB Output is correct
3 Correct 6 ms 19048 KB Output is correct
4 Correct 5 ms 19024 KB Output is correct
5 Correct 5 ms 18940 KB Output is correct
6 Correct 5 ms 19024 KB Output is correct
7 Correct 4 ms 19024 KB Output is correct
8 Correct 65 ms 24812 KB Output is correct
9 Correct 67 ms 24700 KB Output is correct
10 Correct 70 ms 24392 KB Output is correct
11 Correct 68 ms 25416 KB Output is correct
12 Correct 63 ms 23728 KB Output is correct
13 Correct 63 ms 24916 KB Output is correct
14 Correct 62 ms 24904 KB Output is correct
15 Correct 63 ms 24180 KB Output is correct
16 Correct 58 ms 23120 KB Output is correct
17 Correct 62 ms 24904 KB Output is correct
18 Correct 64 ms 25072 KB Output is correct
19 Correct 64 ms 25072 KB Output is correct
20 Correct 62 ms 24904 KB Output is correct
21 Correct 58 ms 24704 KB Output is correct
22 Correct 59 ms 24904 KB Output is correct
23 Correct 65 ms 24836 KB Output is correct
24 Correct 62 ms 22856 KB Output is correct
25 Correct 63 ms 24660 KB Output is correct
26 Correct 60 ms 24648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 170 ms 31500 KB Output is correct
2 Correct 162 ms 30024 KB Output is correct
3 Correct 174 ms 31048 KB Output is correct
4 Correct 172 ms 31560 KB Output is correct
5 Correct 159 ms 31408 KB Output is correct
6 Correct 129 ms 27208 KB Output is correct
7 Correct 125 ms 30028 KB Output is correct
8 Correct 119 ms 30024 KB Output is correct
9 Correct 118 ms 28744 KB Output is correct
10 Correct 122 ms 30024 KB Output is correct
11 Correct 120 ms 30024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 19024 KB Output is correct
2 Correct 6 ms 19024 KB Output is correct
3 Correct 6 ms 19048 KB Output is correct
4 Correct 5 ms 19024 KB Output is correct
5 Correct 5 ms 18940 KB Output is correct
6 Correct 5 ms 19024 KB Output is correct
7 Correct 4 ms 19024 KB Output is correct
8 Correct 65 ms 24812 KB Output is correct
9 Correct 67 ms 24700 KB Output is correct
10 Correct 70 ms 24392 KB Output is correct
11 Correct 68 ms 25416 KB Output is correct
12 Correct 63 ms 23728 KB Output is correct
13 Correct 63 ms 24916 KB Output is correct
14 Correct 62 ms 24904 KB Output is correct
15 Correct 63 ms 24180 KB Output is correct
16 Correct 58 ms 23120 KB Output is correct
17 Correct 62 ms 24904 KB Output is correct
18 Correct 64 ms 25072 KB Output is correct
19 Correct 64 ms 25072 KB Output is correct
20 Correct 62 ms 24904 KB Output is correct
21 Correct 58 ms 24704 KB Output is correct
22 Correct 59 ms 24904 KB Output is correct
23 Correct 65 ms 24836 KB Output is correct
24 Correct 62 ms 22856 KB Output is correct
25 Correct 63 ms 24660 KB Output is correct
26 Correct 60 ms 24648 KB Output is correct
27 Correct 170 ms 31500 KB Output is correct
28 Correct 162 ms 30024 KB Output is correct
29 Correct 174 ms 31048 KB Output is correct
30 Correct 172 ms 31560 KB Output is correct
31 Correct 159 ms 31408 KB Output is correct
32 Correct 129 ms 27208 KB Output is correct
33 Correct 125 ms 30028 KB Output is correct
34 Correct 119 ms 30024 KB Output is correct
35 Correct 118 ms 28744 KB Output is correct
36 Correct 122 ms 30024 KB Output is correct
37 Correct 120 ms 30024 KB Output is correct
38 Correct 195 ms 45012 KB Output is correct
39 Correct 200 ms 42704 KB Output is correct
40 Correct 187 ms 40264 KB Output is correct
41 Correct 297 ms 46628 KB Output is correct
42 Correct 134 ms 31560 KB Output is correct
43 Correct 111 ms 31200 KB Output is correct
44 Correct 165 ms 36936 KB Output is correct
45 Correct 181 ms 37148 KB Output is correct
46 Correct 171 ms 37192 KB Output is correct
47 Correct 140 ms 31536 KB Output is correct
48 Correct 136 ms 31052 KB Output is correct
49 Correct 205 ms 36316 KB Output is correct
50 Correct 209 ms 32424 KB Output is correct
51 Correct 220 ms 36656 KB Output is correct
52 Correct 138 ms 36244 KB Output is correct
53 Correct 168 ms 41080 KB Output is correct
54 Correct 202 ms 46324 KB Output is correct
55 Correct 157 ms 41280 KB Output is correct