Submission #166422

#TimeUsernameProblemLanguageResultExecution timeMemory
166422GioChkhaidzeHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
100 / 100
2420 ms127432 KiB
#include <bits/stdc++.h> #define Tree int h,int l,int r #define Left (h<<1),l,((l+r)>>1) #define Right ((h<<1)|1),((l+r)>>1)+1,r using namespace std; const int N=2e6+5; bool ANS[N]; int n,q,idx,val,L,R; int w[N],a[N],b[N],c[N],Greater[N],v[6*N]; stack < int > st; vector < int > Query[N]; void Upd(Tree) { if (idx<l || r<idx) return; if (l==idx && r==idx) { v[h]=val; return; } Upd(Left),Upd(Right); if (v[(h<<1)]>v[((h<<1)|1)]) v[h]=v[(h<<1)]; else v[h]=v[((h<<1)|1)]; } int Get(Tree) { if (r<L || R<l) return 0; if (L<=l && r<=R) return v[h]; int x=Get(Left),y=Get(Right); if (x<y) return y; return x; } main () { scanf("%d%d",&n,&q); for (int i=1; i<=n; i++) scanf("%d",&w[i]); w[0]=2e9+1; st.push(0); for (int i=1; i<=n; i++) { while (st.size() && w[st.top()]<=w[i]) st.pop(); Greater[i]=st.top(); st.push(i); } for (int i=1; i<=q; i++) { scanf("%d%d%d",&a[i],&b[i],&c[i]); Query[b[i]].push_back(i); } for (int i=1; i<=n; i++) { if (Greater[i]) { idx=Greater[i],val=w[idx]+w[i]; Upd(1,1,n); } for (int j=0; j<Query[i].size(); j++) { idx=Query[i][j],R=i,L=a[idx]; if (Get(1,1,n)<=c[idx]) ANS[idx]=1; else ANS[idx]=0; } } for (int i=1; i<=q; i++) printf("%d\n",ANS[i]); }

Compilation message (stderr)

sortbooks.cpp:28:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:54:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j=0; j<Query[i].size(); j++) {
                 ~^~~~~~~~~~~~~~~~
sortbooks.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&q);
  ~~~~~^~~~~~~~~~~~~~
sortbooks.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&w[i]);
   ~~~~~^~~~~~~~~~~~
sortbooks.cpp:44:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d",&a[i],&b[i],&c[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...