Submission #146922

#TimeUsernameProblemLanguageResultExecution timeMemory
146922PajarajaHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
100 / 100
2638 ms171212 KiB
#include <bits/stdc++.h> #define MAXN 1000007 using namespace std; int seg[4*MAXN],a[MAXN],ans[MAXN]; vector<int> ul[MAXN],uk[MAXN],ind[MAXN]; void upd(int l,int r,int x,int v,int ind) { if(l==r) {seg[ind]=v; return;} int s=(l+r)/2; if(x<=s) upd(l,s,x,v,2*ind); else upd(s+1,r,x,v,2*ind+1); seg[ind]=max(seg[2*ind],seg[2*ind+1]); } int nmax(int l,int r,int lt,int rt,int ind) { if(l>=lt && r<=rt) return seg[ind]; if(l>rt || r<lt) return 0; int s=(l+r)/2; return max(nmax(l,s,lt,rt,2*ind),nmax(s+1,r,lt,rt,2*ind+1)); } int main() { int n,m; scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) scanf("%d",&a[i]); a[0]=1000000007; for(int i=0;i<m;i++) { int t1,t2,t3; scanf("%d%d%d",&t1,&t2,&t3); ul[t2].push_back(t1); uk[t2].push_back(t3); ind[t2].push_back(i); } stack<int> st; st.push(0); for(int i=1;i<=n;i++) { while(a[st.top()]<=a[i]) st.pop(); upd(0,n,st.top(),a[i]+a[st.top()],1); st.push(i); for(int j=0;j<ul[i].size();j++) ans[ind[i][j]]=(nmax(0,n,ul[i][j],i,1)>uk[i][j]?0:1); } for(int i=0;i<m;i++) printf("%d\n",ans[i]); }

Compilation message (stderr)

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:39:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0;j<ul[i].size();j++) ans[ind[i][j]]=(nmax(0,n,ul[i][j],i,1)>uk[i][j]?0:1);
               ~^~~~~~~~~~~~~
sortbooks.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&m);
  ~~~~~^~~~~~~~~~~~~~
sortbooks.cpp:25:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=n;i++) scanf("%d",&a[i]);
                        ~~~~~^~~~~~~~~~~~
sortbooks.cpp:30:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d",&t1,&t2,&t3);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...