#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const ll MAXN = 4e6 + 5;
ll seg[MAXN * 4];
void update(ll v, ll tl, ll tr, ll pos, ll val)
{
if(tl == tr)
{
seg[v] = max(seg[v], val);
return;
}
ll tm = (tl + tr) / 2;
if(pos <= tm)
update(2 * v, tl, tm, pos, val);
else
update(2 * v + 1, tm + 1, tr, pos, val);
seg[v] = max(seg[v * 2], seg[v * 2 + 1]);
}
ll get(ll v, ll tl, ll tr, ll l, ll r)
{
if(l > r)
return 0;
if(l == tl && r == tr)
{
return seg[v];
}
ll tm = (tl + tr) / 2;
return max(get(2 * v, tl, tm, l, min(r, tm)), get(2 * v + 1, tm + 1, tr, max(tm + 1, l), r));
}
int main()
{
ios_base::sync_with_stdio(0);
ll n, m;
cin >> n >> m;
ll w[n+5];
for(ll i = 1; i <= n; i++)
cin >> w[i];
vector< vector < pair<pair<ll, ll>, ll> > > q(m+5);
for(ll i = 1; i <= m; i++)
{
ll l, r, k;
cin >> l >> r >> k;
q[l].push_back({{r, k}, i});
}
ll ans[m+5];
vector<ll> curr;
for(ll i = n; i >= 1; i--)
{
while(!curr.empty() && w[curr.back()] <= w[i])
{
if(w[curr.back()] != w[i])
update(1, 1, n, curr.back(), w[curr.back()] + w[i]);
curr.pop_back();
}
curr.push_back(i);
for(pair< pair<ll, ll>, ll> elem : q[i])
{
ll temp = get(1, 1, n, i, elem.first.first);
if(temp <= elem.first.second)
ans[elem.second] = 1;
else
ans[elem.second] = 0;
}
}
for(ll i = 1; i <= m; i++)
cout << ans[i] << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Runtime error |
3 ms |
400 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Runtime error |
3 ms |
400 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1434 ms |
90320 KB |
Output is correct |
2 |
Correct |
1454 ms |
90308 KB |
Output is correct |
3 |
Correct |
1457 ms |
90692 KB |
Output is correct |
4 |
Correct |
1390 ms |
90472 KB |
Output is correct |
5 |
Correct |
1090 ms |
82012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
102 ms |
9688 KB |
Output is correct |
2 |
Correct |
99 ms |
10212 KB |
Output is correct |
3 |
Correct |
76 ms |
7684 KB |
Output is correct |
4 |
Correct |
73 ms |
7676 KB |
Output is correct |
5 |
Correct |
73 ms |
7604 KB |
Output is correct |
6 |
Correct |
80 ms |
7996 KB |
Output is correct |
7 |
Correct |
63 ms |
7996 KB |
Output is correct |
8 |
Correct |
61 ms |
7360 KB |
Output is correct |
9 |
Correct |
38 ms |
6588 KB |
Output is correct |
10 |
Correct |
64 ms |
7428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Runtime error |
3 ms |
400 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Runtime error |
3 ms |
400 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |