# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
166422 | GioChkhaidze | Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) | C++14 | 2420 ms | 127432 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define Tree int h,int l,int r
#define Left (h<<1),l,((l+r)>>1)
#define Right ((h<<1)|1),((l+r)>>1)+1,r
using namespace std;
const int N=2e6+5;
bool ANS[N];
int n,q,idx,val,L,R;
int w[N],a[N],b[N],c[N],Greater[N],v[6*N];
stack < int > st;
vector < int > Query[N];
void Upd(Tree) {
if (idx<l || r<idx) return;
if (l==idx && r==idx) { v[h]=val; return; }
Upd(Left),Upd(Right);
if (v[(h<<1)]>v[((h<<1)|1)]) v[h]=v[(h<<1)];
else v[h]=v[((h<<1)|1)];
}
int Get(Tree) {
if (r<L || R<l) return 0;
if (L<=l && r<=R) return v[h];
int x=Get(Left),y=Get(Right);
if (x<y) return y;
return x;
}
main () {
scanf("%d%d",&n,&q);
for (int i=1; i<=n; i++)
scanf("%d",&w[i]);
w[0]=2e9+1;
st.push(0);
for (int i=1; i<=n; i++) {
while (st.size() && w[st.top()]<=w[i]) st.pop();
Greater[i]=st.top();
st.push(i);
}
for (int i=1; i<=q; i++) {
scanf("%d%d%d",&a[i],&b[i],&c[i]);
Query[b[i]].push_back(i);
}
for (int i=1; i<=n; i++) {
if (Greater[i]) {
idx=Greater[i],val=w[idx]+w[i];
Upd(1,1,n);
}
for (int j=0; j<Query[i].size(); j++) {
idx=Query[i][j],R=i,L=a[idx];
if (Get(1,1,n)<=c[idx]) ANS[idx]=1;
else ANS[idx]=0;
}
}
for (int i=1; i<=q; i++)
printf("%d\n",ANS[i]);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |