#include "bits/stdc++.h"
using namespace std;
const int MAXN = 1e5+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 |
1 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 |
1 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 |
Runtime error |
672 ms |
107908 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
91 ms |
6860 KB |
Output is correct |
2 |
Correct |
93 ms |
6668 KB |
Output is correct |
3 |
Correct |
72 ms |
5644 KB |
Output is correct |
4 |
Correct |
100 ms |
5812 KB |
Output is correct |
5 |
Correct |
91 ms |
5840 KB |
Output is correct |
6 |
Correct |
64 ms |
5472 KB |
Output is correct |
7 |
Correct |
61 ms |
5420 KB |
Output is correct |
8 |
Correct |
91 ms |
5492 KB |
Output is correct |
9 |
Correct |
37 ms |
4744 KB |
Output is correct |
10 |
Correct |
59 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 |
1 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 |
1 ms |
340 KB |
Output is correct |
5 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |