#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
const int maxn = 1e6 + 69;
int n, q, a[maxn], st[4 * maxn], ans[maxn];
vector<tuple<int, int, int>> g[maxn];
void upd(int v, int tl, int tr, int l, int r, int x) {
if (tl > r || tr < l)
return;
if (tl >= l && tr <= r)
st[v] = max(st[v], x);
else {
int mid = (tl + tr) / 2;
upd(v * 2, tl, mid, l, r, x);
upd(v * 2 + 1, mid + 1, tr, l, r, x);
st[v] = max(st[v * 2], st[v * 2 + 1]);
}
}
int qry(int v, int tl, int tr, int l, int r) {
if (tl > r || tr < l)
return 0;
else if (tl >= l && tr <= r)
return st[v];
else {
int mid = (tl + tr) / 2;
return max(qry(v * 2, tl, mid, l, r), qry(v * 2 + 1, mid + 1, tr, l, r));
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
cin >> n >> q;
for (int i = 1;i <= n;i++)
cin >> a[i];
vector<int> stck;
for (int i = 1;i <= q;i++) {
int l, r, k;
cin >> l >> r >> k;
g[r].push_back({l, k, i});
}
for (int i = 1;i <= n;i++) {
while (!stck.empty() && a[stck.back()] <= a[i])
stck.pop_back();
if (!stck.empty())
upd(1, 1, n, stck.back(), i, a[i] + a[stck.back()]);
for (auto u : g[i]) {
int l, k, ind;
tie(l, k, ind) = u;
ans[ind] = (qry(1, 1, n, l, i) <= k);
}
stck.push_back(i);
}
for (int i = 1;i <= q;i++)
cout << ans[i] << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
27224 KB |
Output is correct |
2 |
Correct |
5 ms |
27232 KB |
Output is correct |
3 |
Incorrect |
6 ms |
27228 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
27224 KB |
Output is correct |
2 |
Correct |
5 ms |
27232 KB |
Output is correct |
3 |
Incorrect |
6 ms |
27228 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1229 ms |
91608 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
84 ms |
32592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
27224 KB |
Output is correct |
2 |
Correct |
5 ms |
27232 KB |
Output is correct |
3 |
Incorrect |
6 ms |
27228 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
27224 KB |
Output is correct |
2 |
Correct |
5 ms |
27232 KB |
Output is correct |
3 |
Incorrect |
6 ms |
27228 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |