/*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];
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].first=max(t[v*2].first,t[v*2+1].first);
t[v].second=min(t[v*2].second,t[v*2+1].second);
mx[v]=max(max(mx[v*2],mx[v*2+1]),t[v*2].first-t[v*2+1].second);
}
pair<LL,LL> get(int v,int l,int r,int i,int j)
{
if(i>j)
return MP(-1,mod*3ll);
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);
ans=max(p1.first-p2.second,ans);
return MP(max(p1.first,p2.first),min(p1.second,p2.second));
}
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,k;
ans=0;
scanf("%d%d%d",&l,&r,&k);
get(1,1,n,l,r);
k-=ans;
//cout<<ans<<endl;
printf("%d\n",(k>=0));
}
return 0;
}
/*
5 2
3 5 1 8 2
1 3 6
2 5 3
*/
Compilation message
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:73:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",a+i);
~~~~~^~~~~~~~~~
sortbooks.cpp:79:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d",&l,&r,&k);
~~~~~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1777 ms |
55712 KB |
Output is correct |
2 |
Incorrect |
1762 ms |
55696 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
131 ms |
7864 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |