Submission #798878

#TimeUsernameProblemLanguageResultExecution timeMemory
798878AlkaratHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
0 / 100
1459 ms66748 KiB
#include <bits/stdc++.h> #define ll long long #define f first #define s second const int N=1e6+10; using namespace std; int n,m,a[N],res[N]; struct query { int id,l,r,lim; bool operator<(const query &x)const { return l>x.l; } }; int bit[N]; void update(int id,int val) { while(id<=n) { bit[id]=max(bit[id],val); id+=id&-id; } } int get(int id) { int kq=0; while(id>0) { kq=max(kq,bit[id]); id-=id&-id; } return kq; } vector<query>q; stack<int>st; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>m; q.resize(m); for(int i=1; i<=n; i++) cin>>a[i]; for(int i=0; i<=m-1; i++) { cin>>q[i].l>>q[i].r>>q[i].lim; q[i].id=i; } sort(q.begin(),q.end()); int now=n+1; for(auto [id,l,r,lim]:q) { while(now>l) { now--; while(st.size()&&a[st.top()]<=a[now]) { int x=st.top(); update(x,a[now]+a[x]); st.pop(); } st.push(now); } res[id]=(get(r)<=lim); } for(int i=0; i<=m-1; i++) cout<<res[i]<<endl; }

Compilation message (stderr)

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:52:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   52 |     for(auto [id,l,r,lim]:q)
      |              ^
#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...