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 int long long
#define pii pair<int,pair<int,pair<int,int>>>
#define x first
#define y second.first
#define z second.second.first
#define p second.second.second
using namespace std;
const int N=(1e6)+3;
int n,q,a[N],t[4*N],gr[N],ans[N];
vector<pii> Q;
stack<int> st;
void UPD(int v,int i,int j,int pos,int val){
if(i==j && pos==i){
t[v]=val;
return;
}
int mid=(i+j)/2;
if(pos<=mid)
UPD(v*2,i,mid,pos,val);
else
UPD(v*2+1,mid+1,j,pos,val);
t[v]=max(t[v*2],t[v*2+1]);
}
int GET(int v,int i,int j,int l,int r){
if(l>r)
return -LONG_LONG_MAX;
if(i==l && j==r)
return t[v];
int mid=(i+j)/2;
int g1=GET(v*2,i,mid,l,min(r,mid));
int g2=GET(v*2+1,mid+1,j,max(mid+1,l),r);
return max(g1,g2);
}
bool comp_sort(pii a,pii b){
return a.y<b.y;
}
main(){
scanf("%lld%lld",&n,&q);
for(int k=1;k<=n;k++)
scanf("%lld",&a[k]);
a[0]=LONG_LONG_MAX;
st.push(0);
for(int k=1;k<=n;k++){
while(a[st.top()]<=a[k]){
st.pop();
}
gr[k]=st.top();
st.push(k);
}
for(int k=1;k<=q;k++){
int a,b,c;
scanf("%lld%lld%lld",&a,&b,&c);
Q.push_back({a,{b,{c,k}}});
}
sort(Q.begin(),Q.end(),comp_sort);
int j=0;
for(int k=1;k<=n;k++){
if(gr[k])
UPD(1,1,n,gr[k],a[gr[k]]+a[k]);
while(j<Q.size() && Q[j].y==k){
if(GET(1,1,n,Q[j].x,Q[j].y)<=Q[j].z)
ans[Q[j].p]=1;
j++;
}
}
for(int k=1;k<=q;k++)
printf("%lld\n",ans[k]);
return 0;
}
Compilation message (stderr)
sortbooks.cpp:38:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:59:4: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if(gr[k])
^~
sortbooks.cpp:61:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
while(j<Q.size() && Q[j].y==k){
^~~~~
sortbooks.cpp:61:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(j<Q.size() && Q[j].y==k){
~^~~~~~~~~
sortbooks.cpp:39:6: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld",&n,&q);
~~~~~^~~~~~~~~~~~~~~~~~
sortbooks.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&a[k]);
~~~~~^~~~~~~~~~~~~~
sortbooks.cpp:53:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld%lld",&a,&b,&c);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |