/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <stack>
#include <cassert>
#include <iterator>
#include <bitset>
#include <fstream>
#define mod 998244353ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(),v.end()
using namespace std;
int n,m,a[1000006];
LL ans,mx[4*1000006];
pair<LL,LL> t[4*1000006];
pair<LL,LL> merge(pair<LL,LL> a,pair<LL,LL> b)
{
a.first=max(a.first,b.first);
a.second=min(a.second,b.second);
return a;
}
void build(int v,int l,int r)
{
int MX=0;
for(int i=l;i<=r;i++)
{
mx[v]=max(mx[v],MX-(LL)a[i]);
MX=max(MX,a[i]);
}
if(l==r)
{
t[v]=MP(a[l],a[l]);
mx[v]=0;
return;
}
int m=(l+r)/2;
build(v*2,l,m);
build(v*2+1,m+1,r);
t[v]=merge(t[v*2],t[v*2+1]);
}
pair<LL,LL> get(int v,int l,int r,int i,int j)
{
if(i>j)
return MP(0,0);
if(l==i && r==j)
{
ans=max(ans,mx[v]);
return t[v];
}
int m=(l+r)>>1;
pair<LL,LL> p1,p2;
p1=get(v*2,l,m,i,min(j,m));
p2=get(v*2+1,m+1,r,max(m+1,i),j);
if(j<=m)
return p1;
else if(i>=m+1)
return p2;
else
{
//cout<<p1.first<<" : "<<p2.second<<endl;
ans=max(p1.first-p2.second,ans);
return merge(p1,p2);
}
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
scanf("%d",a+i);
build(1,1,n);
while(m--)
{
int l,r;
LL k;
ans=0;
scanf("%d%d%lld",&l,&r,&k);
get(1,1,n,l,r);
k-=ans;
//cout<<ans<<endl;
printf("%d\n",(k>0));
}
return 0;
}
/*
5 1
9 8 8 8 8
1 5 1
*/
Compilation message
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:87:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",a+i);
~~~~~^~~~~~~~~~
sortbooks.cpp:94:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%lld",&l,&r,&k);
~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1699 ms |
61160 KB |
Output is correct |
2 |
Incorrect |
1714 ms |
57184 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
125 ms |
9080 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |