/*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];
int ans;
vector<int> g[4*1000006];
int t[4*1000006],mx[4*1000006];
int mergeSerge(vector<int>& a,vector<int>& b,vector<int> &c)
{
int p=0,q=0,d=0;
while(p<a.size())
{
while(q<b.size() && b[q]<=a[p])
{
d=max(d,a[p]+b[q]);
c.PB(b[q++]);
}
c.PB(a[p++]);
}
while(q<b.size())
c.PB(b[q++]);
return d;
}
void build(int v,int l,int r)
{
if(l==r)
{
t[v]=a[l];
g[v].PB(a[l]);
return;
}
int m=(l+r)/2;
build(v*2,l,m);
build(v*2+1,m+1,r);
mx[v]=mergeSerge(g[v*2],g[v*2+1],g[v]);
mx[v]=max(mx[v],max(mx[v*2],mx[v*2+1]));
t[v]=max(t[v*2],t[v*2+1]);
}
int get(int v,int l,int r,int i,int j,int lmax)
{
if(i>j)
return 0;
if(l==i && r==j)
{
//cout<<"["<<l<<":"<<r<<"]"<<" "<<lmax<<endl;
if(g[v].back()>=lmax)
ans=max(ans,lmax+(*(lower_bound(all(g[v]),lmax)-1)));
ans=max(ans,mx[v]);
return t[v];
}
int m=(l+r)>>1;
int p1,p2;
p1=get(v*2,l,m,i,min(j,m),lmax);
lmax=max(lmax,p1);
p2=get(v*2+1,m+1,r,max(m+1,i),j,lmax);
if(j<=m)
return p1;
else if(i>=m+1)
return p2;
else
{
//cout<<p1.first<<" : "<<p2.second<<endl;
return max(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,k;
ans=0;
scanf("%d%d%d",&l,&r,&k);
get(1,1,n,l,r,0);
//cout<<ans<<endl;
printf("%d\n",(k>=ans));
}
return 0;
}
/*
5 2
3 5 1 8 2
1 3 6
2 5 3
*/
Compilation message
sortbooks.cpp: In function 'int mergeSerge(std::vector<int>&, std::vector<int>&, std::vector<int>&)':
sortbooks.cpp:34:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(p<a.size())
~^~~~~~~~~
sortbooks.cpp:36:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(q<b.size() && b[q]<=a[p])
~^~~~~~~~~
sortbooks.cpp:43:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(q<b.size())
~^~~~~~~~~
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:97:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",a+i);
~~~~~^~~~~~~~~~
sortbooks.cpp:103: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);
~~~~~^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
89 ms |
94200 KB |
Output is correct |
2 |
Correct |
89 ms |
94200 KB |
Output is correct |
3 |
Incorrect |
89 ms |
94328 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
89 ms |
94200 KB |
Output is correct |
2 |
Correct |
89 ms |
94200 KB |
Output is correct |
3 |
Incorrect |
89 ms |
94328 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3048 ms |
247204 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
367 ms |
111636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
89 ms |
94200 KB |
Output is correct |
2 |
Correct |
89 ms |
94200 KB |
Output is correct |
3 |
Incorrect |
89 ms |
94328 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
89 ms |
94200 KB |
Output is correct |
2 |
Correct |
89 ms |
94200 KB |
Output is correct |
3 |
Incorrect |
89 ms |
94328 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |