제출 #868540

#제출 시각아이디문제언어결과실행 시간메모리
868540alexddHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
0 / 100
592 ms65452 KiB
#include<bits/stdc++.h> using namespace std; int n,m; int a[1000005]; int tole[1000005]; int rez[1000005]; deque<int> dq; vector<pair<pair<int,int>,int>> qrys[1000005]; int aib[10000005]; int qry(int poz) { int aux=0; for(int i=poz;i<=n;i+=(i&(-i))) aux=max(aux,aib[i]); return aux; } void upd(int poz, int newv) { for(int i=poz;i>0;i-=(i&(-i))) aib[poz]=max(aib[poz],newv); } signed main() { ios_base::sync_with_stdio(0);cin.tie(0); cin>>n>>m; for(int i=1;i<=n;i++) { cin>>a[i]; while(!dq.empty() && a[dq.back()]<=a[i]) dq.pop_back(); if(dq.empty()) tole[i]=0; else tole[i]=dq.back(); dq.push_back(i); } int ql,qr,k; for(int i=1;i<=m;i++) { cin>>ql>>qr>>k; qrys[qr].push_back({{ql,k},i}); } for(int i=1;i<=n;i++) { if(tole[i]>0) upd(tole[i],a[i]+tole[i]); for(auto x:qrys[i]) { int le=x.first.first; int mxm=qry(le); /*for(int j=le;j<=i;j++) if(tole[j]>=le) mxm=max(mxm, a[j]+a[tole[j]]);*/ if(mxm<=x.first.second) rez[x.second]=1; else rez[x.second]=0; } } for(int i=1;i<=m;i++) cout<<rez[i]<<"\n"; return 0; } /** tole[i] = prima pozitie din stanga lui i > a[i] max(a[j] + a[tole[j]]) pt j = le..ri && tole[j] >= le */
#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...