Submission #993580

#TimeUsernameProblemLanguageResultExecution timeMemory
993580vivkostovHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
0 / 100
960 ms54736 KiB
#include<bits/stdc++.h> #define endl "\n" using namespace std; void speed() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } struct cell { int l,r,c; void read() { cin>>l>>r>>c; } }; bool cmp(cell a1,cell a2) { return a1.r<a2.r; } cell b[1000005]; int n,m,a[1000005],l,r,c,p[4000005]; void update(int l,int r,int ql,int qr,int h,int x) { if(l>qr||r<ql)return; if(l>=ql&&r<=qr) { p[h]=max(x,p[h]); return; } int m=(l+r)/2; update(l,m,ql,qr,h*2,x); update(m+1,r,ql,qr,h*2+1,x); p[h]=max(max(p[h*2],p[h*2+1]),p[h]); } int query(int l,int r,int ql,int qr,int h) { if(l>qr||r<ql)return 0; if(l>=ql&&r<=qr)return p[h]; int m=(l+r)/2; return max(query(l,m,ql,qr,h*2),query(m+1,r,ql,qr,h*2+1)); } stack<int>s; stack<int>in; void read() { cin>>n>>m; for(int i=1;i<=n;i++) { cin>>a[i]; } for(int i=1;i<=m;i++) { b[i].read(); } sort(b+1,b+m+1,cmp); int pos=0; for(int i=1;i<=m;i++) { for(int j=max(pos,b[i].l);j<=b[i].r;j++) { while(!s.empty()&&s.top()<=a[j]) { s.pop(); in.pop(); } if(s.empty()) { s.push(a[j]); in.push(j); } else { update(1,n,in.top(),in.top(),1,a[j]+s.top()); s.push(a[j]); in.push(j); } } if(b[i].c>=query(1,n,b[i].l,b[i].r,1))cout<<1<<endl; else cout<<0<<endl; pos=b[i].r; } } int main() { speed(); read(); return 0; }
#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...