Submission #167139

#TimeUsernameProblemLanguageResultExecution timeMemory
167139rzbtHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
100 / 100
2213 ms141576 KiB
#include <bits/stdc++.h> #define mp make_pair #define pb push_back #define F first #define S second #define all(x) x.begin(),x.end() #define MAXN 1000006 typedef long long ll; using namespace std; int n,m; vector<int> s; vector<pair<pair<int,int>,int> > query[MAXN]; vector<int> gube[MAXN]; int niz[MAXN],res[MAXN]; int tr[MAXN]; int seg[4*MAXN]; void dodaj(int l,int d,int p,int k,int x){ if(l==d){ seg[k]=x; return; } int mid=(l+d)/2; if(p<=mid)dodaj(l,mid,p,k+k,x); else dodaj(mid+1,d,p,k+k+1,x); seg[k]=max(seg[k+k],seg[k+k+1]); } int dobij(int l,int d,int tl,int td,int k){ if(l>td || d<tl)return 0; if(l>=tl && d<=td)return seg[k]; int mid=(l+d)/2; return max(dobij(l,mid,tl,td,k+k), dobij(mid+1,d,tl,td,k+k+1)); } void izgradi(int l,int d,int k){ if(l==d){ seg[k]=tr[l]; return; } int mid=(l+d)/2; izgradi(l,mid,k+k); izgradi(mid+1,d,k+k+1); seg[k]=max(seg[k+k],seg[k+k+1]); } int main() { scanf("%d %d", &n, &m); for(int i=1;i<=n;i++){ scanf("%d",niz+i); while(!s.empty() && niz[s.back()] <= niz[i])s.pop_back(); if(s.empty())s.pb(i); else{ int o=s.back(); gube[o].pb(i); tr[i]=niz[i]+niz[o]; s.push_back(i); } } izgradi(1,n,1); for(int i=1;i<=m;i++){ int t1,t2,t3; scanf("%d %d %d", &t1, &t2, &t3); query[t1].pb(mp(mp(t2,t3), i)); } for(int i=1;i<=n;i++){ for(auto x:query[i]){ if(dobij(1,n,i,x.F.F,1)<=x.F.S)res[x.S]=1; else res[x.S]=0; } for(auto x:gube[i]){ dodaj(1,n,x,1,0); } } for(int i=1;i<=m;i++)printf("%d\n",res[i]); return 0;// }

Compilation message (stderr)

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:54:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
sortbooks.cpp:56:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",niz+i);
         ~~~~~^~~~~~~~~~~~
sortbooks.cpp:69:14: 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...