#include <bits/stdc++.h>
using namespace std;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
long long n,m,a[1000001];
void read()
{
cin>>n>>m;
for(long long i=1;i<=n;i++)
cin>>a[i];
}
long long maxx[1000001][32];
long long minn[1000001][32];
long long pw[1000001];
void prec()
{
long long x=1,y=0;
while(x<=n)
{
pw[x]=y;
if(x+1==(1<<(y+1)))
y++;
x++;
}
for(long long i=1;i<=n;i++)
maxx[i][0]=minn[i][0]=a[i];
for(long long j=1;j<20;j++)
{
for(long long i=1;i<=n;i++)
{
minn[i][j]=min(minn[i][j-1],minn[i+(1<<(j-1))][j-1]);
maxx[i][j]=max(maxx[i][j-1],maxx[i+(1<<(j-1))][j-1]);
}
}
}
long long max_(long long l,long long r)
{
long long len=r-l+1;
return max(maxx[l][pw[len]],maxx[r-(1<<(pw[len]))+1][pw[len]]);
}
long long min_(long long l,long long r)
{
long long len=r-l+1;
return min(minn[l][pw[len]],minn[r-(1<<(pw[len]))+1][pw[len]]);
}
void solve()
{
for(long long i=1;i<=m;i++)
{
long long l,r,k;
cin>>l>>r>>k;
long long ans=0;
for(long long j=l;j<r;j++)
{
ans=max(ans,max_(l,j)-min_(j+1,r));
}
if(ans<=k)cout<<1<<endl;
else cout<<0<<endl;
}
}
int main()
{
speed();
read();
prec();
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Incorrect |
2 ms |
6488 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Incorrect |
2 ms |
6488 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
153 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3066 ms |
60276 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Incorrect |
2 ms |
6488 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Incorrect |
2 ms |
6488 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |