#include "bits/stdc++.h"
using namespace std;
const int MAXN = 1e6 + 5;
int seg[MAXN * 4];
void update(int v, int tl, int tr, int l, int r, int val)
{
if(l > r)
return;
if(l == tl && r == tr)
{
seg[v] = max(seg[v], val);
return;
}
int tm = (tl + tr) / 2;
update(2 * v, tl, tm, l, min(r, tm), val);
update(2 * v + 1, tm + 1, tr, max(tm + 1, l), r, val);
seg[v] = max(seg[v * 2], seg[v * 2 + 1]);
}
int get(int v, int tl, int tr, int l, int r)
{
if(l > r)
return - 1;
if(l == tl && r == tr)
{
return seg[v];
}
int 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);
int n, m;
cin >> n >> m;
int w[n+5];
for(int i = 1; i <= n; i++)
cin >> w[i];
vector< vector < pair<pair<int, int>, int> > > q(m+5);
for(int i = 1; i <= m; i++)
{
int l, r, k;
cin >> l >> r >> k;
q[l].push_back({{r, k}, i});
}
int ans[m+5];
vector<int> curr;
for(int 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(), n, w[curr.back()] + w[i]);
curr.pop_back();
}
curr.push_back(i);
for(pair< pair<int, int>, int> elem : q[i])
{
int temp = get(1, 1, n, i, elem.first.first);
if(temp <= elem.first.second)
ans[elem.second] = 1;
else
ans[elem.second] = 0;
}
}
for(int 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 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
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 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1350 ms |
63712 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
95 ms |
6904 KB |
Output isn't correct |
2 |
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 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
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 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |