#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m;ll a[1000006],l[1000006],r[1000006],k[1000006],t[1000006];
vector<ll>as[1000006];
void add(int k,ll x)
{
while(k>0)
{
t[k]=max(t[k],x);
k-=k&-k;
}
}
ll get(int k)
{
ll s=0;
while(k<=n)
{
s=max(s,t[k]);
k+=k&-k;
}
return s;
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin>>n>>m;
for(int c=1;c<=n;c++)
{
cin>>a[c];
}
for(int c=1;c<=m;c++)
{
cin>>l[c]>>r[c]>>k[c];as[r[c]].push_back(c);
}
vector<ll>s;
vector<bool>ans(m+1);
for(int c=1;c<=n;c++)
{
while(s.size()&&a[s.back()]<=a[c])
{
s.pop_back();
}
ll x=(s.size()==0?0:s.back());
add(x,a[x]+a[c]);
for (auto i:as[c])
{
cout<<i<<" ";
ans[i]=(get(l[i])<=k[i]);
}
cout<<"\n";
s.push_back(c);
}
for(int c=1;c<=m;c++)
{
cout<<ans[c]<<"\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
23756 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
23756 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1062 ms |
92908 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
72 ms |
30404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
23756 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
23756 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |