#include <bits/stdc++.h>
using namespace std;
int n,m,v[2000005],st[2000005],dr[2000005],cost[2000005];
vector <int> ev[2000005];
int aib[2000005],sol[2000005];
stack <int> stac;
int ub (int x)
{
return x&(-x);
}
void update(int poz2,int x)
{
int i;
for (i=poz2;i<=n;i+=ub(i))
{
aib[i]=max(aib[i],x);
}
}
int maxi(int poz2)
{
int i,maxim=0;
for (i=poz2;i>=1;i-=ub(i))
{
maxim=max(aib[i],maxim);
}
return maxim;
}
int i,j;
vector <pair <int,int>> ceau;
int main()
{
ios_base :: sync_with_stdio(false);
cin.tie(0);
#ifdef HOME
ifstream cin("date.in");
ofstream cout("date.out");
#endif // HOME
cin>>n>>m;
for (i=1;i<=n;i++)
{
cin>>v[i];
}
for (i=1;i<=m;i++)
{
cin>>st[i]>>dr[i]>>cost[i];
ev[st[i]].push_back(i);
}
for (i=1;i<=n;i++)
{
while (!stac.empty()&&v[stac.top()]<=v[i])
{
stac.pop();
}
if (!stac.empty())
{
ceau.push_back({stac.top(),i});
}
stac.push(i);
}
int poz=((int)ceau.size())-1;
for (i=n;i>=1;i--)
{
while (poz>=0&&ceau[poz].first>=i)
{
update(ceau[poz].second,v[ceau[poz].first]+v[ceau[poz].second]);
poz--;
}
for (j=0;j<(int)ev[i].size();j++)
{
if (maxi(dr[ev[i][j]])<=cost[ev[i][j]])
{
sol[ev[i][j]]=1;
}
}
}
for (i=1;i<=m;i++)
{
cout<<sol[i]<<'\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
47304 KB |
Output is correct |
2 |
Correct |
22 ms |
47308 KB |
Output is correct |
3 |
Incorrect |
22 ms |
47288 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
47304 KB |
Output is correct |
2 |
Correct |
22 ms |
47308 KB |
Output is correct |
3 |
Incorrect |
22 ms |
47288 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
964 ms |
98704 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
93 ms |
52668 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
47304 KB |
Output is correct |
2 |
Correct |
22 ms |
47308 KB |
Output is correct |
3 |
Incorrect |
22 ms |
47288 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
47304 KB |
Output is correct |
2 |
Correct |
22 ms |
47308 KB |
Output is correct |
3 |
Incorrect |
22 ms |
47288 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |