Submission #335029

#TimeUsernameProblemLanguageResultExecution timeMemory
335029ivan_tudorHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
64 / 100
316 ms20076 KiB
#include<bits/stdc++.h> using namespace std; const int N = 2 * 1e5 + 5; int aint[4*N]; void build(int nod,int l,int r){ if(l == r){ aint[nod] = INT_MIN; return; } int mid = (l + r)/2; build(2*nod, l, mid); build(2*nod + 1, mid+1, r); aint[nod] = INT_MIN; } void update(int nod, int l, int r, int upoz,int val){ if(upoz < l || upoz > r) return; if(l == r){ aint[nod] = val; return; } int mid = (l + r)/2; update(2*nod, l, mid, upoz, val); update(2*nod + 1, mid+1, r, upoz, val); aint[nod] = max(aint[2*nod], aint[2*nod + 1]); } int query(int nod,int l,int r, int ql, int qr){ if(r < ql || l > qr) return INT_MIN; if(ql <=l && r <= qr) return aint[nod]; int mid = (l + r)/2; int ls = query(2*nod, l, mid, ql, qr); int rs = query(2*nod + 1, mid+1, r, ql, qr); return max(ls, rs); } struct qry{ int poz, w; int id; }; int v[N]; int ans[N]; vector<qry> qu[N]; int st[N]; int main() { //freopen(".in","r",stdin); ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); int n, q; cin>>n>>q; for(int i=1;i<=n;i++){ cin>>v[i]; } build(1, 1, n); for(int i = 1; i<=q;i ++){ int l, r, w; cin>>l>>r>>w; qu[r].push_back({l, w, i}); } int vf =0; for(int i=1;i<=n;i++){ while(vf > 0 && v[st[vf]] <= v[i]) vf--; if(vf){ update(1, 1, n, st[vf], v[i] + v[st[vf]]); } st[++vf] = i; for(auto x:qu[i]){ if(query(1, 1, n, x.poz, i) > x.w) ans[x.id] = 0; else ans[x.id] = 1; } } for(int i=1;i<=q;i++) cout<<ans[i]<<"\n"; 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...