#include<bits/stdc++.h>
using namespace std;
long long n,m,a[1000006],rmn[30][1000006],rmx[30][1000006];
void buildd()
{
for(int i=1;i<=n;i++)
{
rmn[0][i]=a[i];
rmx[0][i]=a[i];
}
for(int i=1;i<=21;i++)
{
for(int j=1;j<=n;j++)
{
rmn[i][j]=min(rmn[i-1][j],rmn[i-1][j+(1<<(i-1))]);
rmx[i][j]=max(rmx[i-1][j],rmx[i-1][j+(1<<(i-1))]);
}
}
}
long long getmx(long long l,long long r)
{
long long k=__lg(r-l+1);
return max(rmx[k][l],rmx[k][r-(1<<k)+1]);
}
long long getmn(long long l,long long r)
{
long long k=__lg(r-l+1);
return min(rmn[k][l],rmn[k][r-(1<<k)+1]);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
// freopen(".inp","r",stdin);
// freopen(".out","w",stdout);
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
buildd();
while(m--)
{
long long l,r,k;
cin>>l>>r>>k;
while(a[r]==getmx(l,r)&&r>=l)
{
r--;
}
if(r<l) cout<<1<<"\n";
else
{
// cout<<getmx(l,r)+getmn(l,r)<<"\n";
if(getmx(l,r)+getmn(l,r)<=k)
{
cout<<1<<"\n";
}
else cout<<0<<"\n";
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
608 KB |
Output is correct |
2 |
Correct |
0 ms |
616 KB |
Output is correct |
3 |
Incorrect |
0 ms |
860 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
608 KB |
Output is correct |
2 |
Correct |
0 ms |
616 KB |
Output is correct |
3 |
Incorrect |
0 ms |
860 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
158 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
39 ms |
38236 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
608 KB |
Output is correct |
2 |
Correct |
0 ms |
616 KB |
Output is correct |
3 |
Incorrect |
0 ms |
860 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
608 KB |
Output is correct |
2 |
Correct |
0 ms |
616 KB |
Output is correct |
3 |
Incorrect |
0 ms |
860 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |