#include<iostream>
#include<stack>
using namespace std;
long long maxi[10000000], a[10000000];
stack<long long>st;
void build(long long le,long long ri,long long ind)
{
if(le==ri)
{
maxi[ind]=a[le];return;
}
long long mid=(le+ri)/2;
build(le,mid,2*ind);
build(mid+1,ri,2*ind+1);
maxi[ind]=max(maxi[2*ind],maxi[2*ind+1]);
}
long long query(long long le,long long ri,long long l,long long r,long long ind)
{
if(le>r || ri<l)return 0;
if(l<=le && ri<=r)
{
return maxi[ind];
}
long long mid=(le+ri)/2;
long long r1,r2;
r1=query(le,mid,l,r,2*ind);
r2=query(mid+1,ri,l,r,2*ind+1);
return max(r1,r2);
}
int main()
{
long long i,j,n,m,l,r,k,p;
cin>>n>>m;
for(i=1;i<=n;i++)
{
cin>>p;
while(!st.empty() && st.top()<=p)st.pop();
if(st.empty())
{
a[i]=-1;
}
else
{
a[i]=st.top();
}
st.push(p);
}
build(1,n,1);
for(i=1;i<=m;i++)
{
cin>>l>>r>>k;
long long res=query(1,n,l,r,1);
if(res<=k)cout<<1<<endl;
else cout<<0<<endl;
}
}
Compilation message
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:40:17: warning: unused variable 'j' [-Wunused-variable]
40 | long long i,j,n,m,l,r,k,p;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2996 ms |
26544 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
253 ms |
3396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |