#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[1000005];
int tole[1000005];
int rez[1000005];
deque<int> dq;
vector<pair<pair<int,int>,int>> qrys[1000005];
int aib[10000005];
int qry(int poz)
{
int aux=0;
for(int i=poz;i<=n;i+=(i&(-i)))
aux=max(aux,aib[i]);
return aux;
}
void upd(int poz, int newv)
{
for(int i=poz;i>0;i-=(i&(-i)))
aib[i]=max(aib[i],newv);
}
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i];
while(!dq.empty() && a[dq.back()]<=a[i])
dq.pop_back();
if(dq.empty())
tole[i]=0;
else
tole[i]=dq.back();
dq.push_back(i);
}
int ql,qr,k;
for(int i=1;i<=m;i++)
{
cin>>ql>>qr>>k;
qrys[qr].push_back({{ql,k},i});
}
for(int i=1;i<=n;i++)
{
if(tole[i]>0) upd(tole[i],a[i]+tole[i]);
for(auto x:qrys[i])
{
int le=x.first.first;
int mxm=qry(le);
/**int mxm=0;
for(int j=1;j<=i;j++)
if(tole[j]>=le)
mxm=max(mxm, a[j]+a[tole[j]]);*/
if(mxm<=x.first.second)
rez[x.second]=1;
else
rez[x.second]=0;
}
}
for(int i=1;i<=m;i++)
cout<<rez[i]<<"\n";
return 0;
}
/**
tole[i] = prima pozitie din stanga lui i > a[i]
max(a[j] + a[tole[j]]) pt j = le..ri && tole[j] >= le
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
31068 KB |
Output is correct |
2 |
Correct |
8 ms |
31240 KB |
Output is correct |
3 |
Incorrect |
6 ms |
31068 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
31068 KB |
Output is correct |
2 |
Correct |
8 ms |
31240 KB |
Output is correct |
3 |
Incorrect |
6 ms |
31068 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
642 ms |
65320 KB |
Output is correct |
2 |
Correct |
667 ms |
94820 KB |
Output is correct |
3 |
Correct |
664 ms |
94712 KB |
Output is correct |
4 |
Correct |
713 ms |
94792 KB |
Output is correct |
5 |
Correct |
606 ms |
90960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
46 ms |
33872 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
31068 KB |
Output is correct |
2 |
Correct |
8 ms |
31240 KB |
Output is correct |
3 |
Incorrect |
6 ms |
31068 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
31068 KB |
Output is correct |
2 |
Correct |
8 ms |
31240 KB |
Output is correct |
3 |
Incorrect |
6 ms |
31068 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |