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>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))
typedef long long int lli;
typedef pair <lli,lli> ii;
typedef pair <lli,ii> iii;
typedef vector <lli> vi;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
iii segt[4000001];
lli n,m,ans;
void up(lli node,lli l,lli r,lli in,lli v)
{
if(l==r)
{
segt[node]=mp(0,mp(v,v));
return;
}
lli m=(l+r)/2;
if(in<=m)
up(2*node+1,l,m,in,v);
else
up(2*node+2,m+1,r,in,v);
ans=max(segt[2*node+1].F,segt[2*node+2].F);
ans=max(segt[2*node+1].S.F-segt[2*node+2].S.S,ans);
segt[node]=mp(ans,mp(max(segt[2*node+1].S.F,segt[2*node+2].S.F),min(segt[2*node+1].S.S,segt[2*node+2].S.S)));
}
iii qu(lli node,lli l,lli r,lli s,lli e)
{
if(l>e||r<s)
return(mp(0,mp(0,15000000000)));
if(l>=s&&r<=e)
return(segt[node]);
lli m=(l+r)/2;
iii q1=qu(2*node+1,l,m,s,e),q2=qu(2*node+2,m+1,r,s,e);
ans=max(q1.F,q2.F);
ans=max(q1.S.F-q2.S.S,ans);
return(mp(ans,mp(max(q1.S.F,q2.S.F),min(q1.S.S,q2.S.S))));
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>m;
for(int i=0;i<n;++i)
{
lli f;
cin>>f;
up(0,0,n-1,i,f);
}
for(lli i=0;i<m;++i)
{
lli f,s,k;
cin>>f>>s>>k;
f--;
s--;
iii a=qu(0,0,n-1,f,s);
if(a.F<=k)
cout<<1<<endl;
else
cout<<0<<endl;
}
return(0);
}
# | 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... |