#include "bits/stdc++.h"
using namespace std;
const int MAXN = 2e6 + 5;
int seg[MAXN * 4];
void update(int v, int tl, int tr, int pos, int val)
{
if(tl == tr)
{
seg[v] = max(seg[v], val);
return;
}
int 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]);
}
int get(int v, int tl, int tr, int l, int r)
{
if(l > r)
return 0;
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(), 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";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1364 ms |
63496 KB |
Output is correct |
2 |
Correct |
1264 ms |
63548 KB |
Output is correct |
3 |
Correct |
1284 ms |
63504 KB |
Output is correct |
4 |
Correct |
1235 ms |
63480 KB |
Output is correct |
5 |
Correct |
1078 ms |
59376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
94 ms |
6832 KB |
Output is correct |
2 |
Correct |
110 ms |
6712 KB |
Output is correct |
3 |
Correct |
71 ms |
5708 KB |
Output is correct |
4 |
Correct |
73 ms |
5788 KB |
Output is correct |
5 |
Correct |
71 ms |
5836 KB |
Output is correct |
6 |
Correct |
60 ms |
5392 KB |
Output is correct |
7 |
Correct |
60 ms |
5452 KB |
Output is correct |
8 |
Correct |
61 ms |
5464 KB |
Output is correct |
9 |
Correct |
37 ms |
4696 KB |
Output is correct |
10 |
Correct |
60 ms |
5508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |