Submission #107073

# Submission time Handle Problem Language Result Execution time Memory
107073 2019-04-21T17:17:01 Z thebes Long Mansion (JOI17_long_mansion) C++14
100 / 100
1926 ms 56596 KB
#include <bits/stdc++.h>
using namespace std;

const int MN = 5e5+5;
int N, Q, t, i, x, y, l[MN], r[MN], c[MN], pre[MN], suf[MN], st[3*MN], lst[MN];
vector<int> a[MN];

void build(int i,int s,int e){
    if(s!=e){
        build(2*i,s,(s+e)/2);
        build(2*i+1,(s+e)/2+1,e);
        st[i]=min(st[2*i],st[2*i+1]);
    }
    else st[i]=pre[s];
}

int qu(int i,int s,int e,int ss,int se){
    if(s>=ss&&e<=se) return st[i];
    else if((s+e)/2<ss) return qu(2*i+1,(s+e)/2+1,e,ss,se);
    else if((s+e)/2>=se) return qu(2*i,s,(s+e)/2,ss,se);
    else return min(qu(2*i,s,(s+e)/2,ss,se),qu(2*i+1,(s+e)/2+1,e,ss,se));
}

int main(){
    for(scanf("%d",&N),i=1;i<N;i++) scanf("%d",&c[i]);
    for(i=1;i<=N;i++){
        scanf("%d",&t);
        while(t--) scanf("%d",&x), a[i].push_back(x);
    }
    for(i=1;i<N;i++){
        for(auto v : a[i]) lst[v]=i;
        pre[i]=lst[c[i]];
    }
    memset(lst,0,sizeof(lst));
    for(i=N;i>1;i--){
        for(auto v : a[i]) lst[v]=i;
        suf[i-1]=lst[c[i-1]];
    }
    build(1,1,N-1);
    for(i=1;i<=N;i++){
        int L=i, R=i;
        while(1){
            if(L>1&&suf[L-1]&&R>=suf[L-1]){
                R = max(R, r[L-1]);
                L = l[L-1];
            }
            else{
                int lo = R, hi = N;
                while(lo<hi){
                    int m = (lo+hi)/2;
                    if(qu(1,1,N-1,R,m)>=L) lo=m+1;
                    else hi=m;
                }
                if(lo==R) break;
                else R=lo;
            }
        }
        l[i]=L, r[i]=R;
    }
    for(scanf("%d",&Q);Q;Q--){
        scanf("%d%d",&x,&y);
        printf("%s\n",(r[x]>=y&&l[x]<=y)?"YES":"NO");
    }
    return 0;
}

Compilation message

long_mansion.cpp: In function 'int main()':
long_mansion.cpp:25:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(scanf("%d",&N),i=1;i<N;i++) scanf("%d",&c[i]);
         ~~~~~~~~~~~~~~^~~~
long_mansion.cpp:25:42: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(scanf("%d",&N),i=1;i<N;i++) scanf("%d",&c[i]);
                                     ~~~~~^~~~~~~~~~~~
long_mansion.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&t);
         ~~~~~^~~~~~~~~
long_mansion.cpp:28:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         while(t--) scanf("%d",&x), a[i].push_back(x);
                    ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
long_mansion.cpp:60:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(scanf("%d",&Q);Q;Q--){
         ~~~~~^~~~~~~~~
long_mansion.cpp:61:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&x,&y);
         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 23 ms 14336 KB Output is correct
2 Correct 23 ms 14336 KB Output is correct
3 Correct 25 ms 14336 KB Output is correct
4 Correct 20 ms 14336 KB Output is correct
5 Correct 17 ms 14208 KB Output is correct
6 Correct 19 ms 14336 KB Output is correct
7 Correct 20 ms 14208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 14336 KB Output is correct
2 Correct 23 ms 14336 KB Output is correct
3 Correct 25 ms 14336 KB Output is correct
4 Correct 20 ms 14336 KB Output is correct
5 Correct 17 ms 14208 KB Output is correct
6 Correct 19 ms 14336 KB Output is correct
7 Correct 20 ms 14208 KB Output is correct
8 Correct 184 ms 20208 KB Output is correct
9 Correct 181 ms 20120 KB Output is correct
10 Correct 188 ms 20452 KB Output is correct
11 Correct 176 ms 20876 KB Output is correct
12 Correct 160 ms 19748 KB Output is correct
13 Correct 186 ms 20432 KB Output is correct
14 Correct 159 ms 20216 KB Output is correct
15 Correct 189 ms 20292 KB Output is correct
16 Correct 150 ms 20076 KB Output is correct
17 Correct 178 ms 20216 KB Output is correct
18 Correct 206 ms 20344 KB Output is correct
19 Correct 157 ms 20344 KB Output is correct
20 Correct 166 ms 20264 KB Output is correct
21 Correct 168 ms 20088 KB Output is correct
22 Correct 195 ms 20120 KB Output is correct
23 Correct 212 ms 20088 KB Output is correct
24 Correct 181 ms 20088 KB Output is correct
25 Correct 192 ms 20216 KB Output is correct
26 Correct 178 ms 20088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 585 ms 29880 KB Output is correct
2 Correct 559 ms 29680 KB Output is correct
3 Correct 529 ms 29304 KB Output is correct
4 Correct 739 ms 29816 KB Output is correct
5 Correct 575 ms 29944 KB Output is correct
6 Correct 427 ms 28588 KB Output is correct
7 Correct 318 ms 28212 KB Output is correct
8 Correct 229 ms 28152 KB Output is correct
9 Correct 257 ms 28280 KB Output is correct
10 Correct 314 ms 28280 KB Output is correct
11 Correct 222 ms 28280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 14336 KB Output is correct
2 Correct 23 ms 14336 KB Output is correct
3 Correct 25 ms 14336 KB Output is correct
4 Correct 20 ms 14336 KB Output is correct
5 Correct 17 ms 14208 KB Output is correct
6 Correct 19 ms 14336 KB Output is correct
7 Correct 20 ms 14208 KB Output is correct
8 Correct 184 ms 20208 KB Output is correct
9 Correct 181 ms 20120 KB Output is correct
10 Correct 188 ms 20452 KB Output is correct
11 Correct 176 ms 20876 KB Output is correct
12 Correct 160 ms 19748 KB Output is correct
13 Correct 186 ms 20432 KB Output is correct
14 Correct 159 ms 20216 KB Output is correct
15 Correct 189 ms 20292 KB Output is correct
16 Correct 150 ms 20076 KB Output is correct
17 Correct 178 ms 20216 KB Output is correct
18 Correct 206 ms 20344 KB Output is correct
19 Correct 157 ms 20344 KB Output is correct
20 Correct 166 ms 20264 KB Output is correct
21 Correct 168 ms 20088 KB Output is correct
22 Correct 195 ms 20120 KB Output is correct
23 Correct 212 ms 20088 KB Output is correct
24 Correct 181 ms 20088 KB Output is correct
25 Correct 192 ms 20216 KB Output is correct
26 Correct 178 ms 20088 KB Output is correct
27 Correct 585 ms 29880 KB Output is correct
28 Correct 559 ms 29680 KB Output is correct
29 Correct 529 ms 29304 KB Output is correct
30 Correct 739 ms 29816 KB Output is correct
31 Correct 575 ms 29944 KB Output is correct
32 Correct 427 ms 28588 KB Output is correct
33 Correct 318 ms 28212 KB Output is correct
34 Correct 229 ms 28152 KB Output is correct
35 Correct 257 ms 28280 KB Output is correct
36 Correct 314 ms 28280 KB Output is correct
37 Correct 222 ms 28280 KB Output is correct
38 Correct 1654 ms 51796 KB Output is correct
39 Correct 1904 ms 56596 KB Output is correct
40 Correct 1199 ms 45532 KB Output is correct
41 Correct 1503 ms 54924 KB Output is correct
42 Correct 476 ms 29416 KB Output is correct
43 Correct 402 ms 29432 KB Output is correct
44 Correct 751 ms 38264 KB Output is correct
45 Correct 704 ms 38368 KB Output is correct
46 Correct 712 ms 38460 KB Output is correct
47 Correct 372 ms 29492 KB Output is correct
48 Correct 371 ms 29176 KB Output is correct
49 Correct 719 ms 38276 KB Output is correct
50 Correct 635 ms 38396 KB Output is correct
51 Correct 649 ms 38392 KB Output is correct
52 Correct 944 ms 37212 KB Output is correct
53 Correct 1351 ms 46008 KB Output is correct
54 Correct 1926 ms 52856 KB Output is correct
55 Correct 1541 ms 46092 KB Output is correct