Submission #533350

#TimeUsernameProblemLanguageResultExecution timeMemory
533350couplefireLong Mansion (JOI17_long_mansion)C++17
100 / 100
1721 ms56468 KiB
#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 (stderr)

long_mansion.cpp: In function 'int main()':
long_mansion.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     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]
   25 |     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]
   27 |         scanf("%d",&t);
      |         ~~~~~^~~~~~~~~
long_mansion.cpp:28:25: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         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]
   60 |     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]
   61 |         scanf("%d%d",&x,&y);
      |         ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...