#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 p, int x) {
if (tl == tr)
st[v] = max(st[v], x);
else {
int mid = (tl + tr) / 2;
if (p <= mid)
upd(v * 2, tl, mid, p, x);
else
upd(v * 2 + 1, mid + 1, tr, p, 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(), a[i] + 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 |
6 ms |
27228 KB |
Output is correct |
2 |
Correct |
6 ms |
27224 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 |
6 ms |
27228 KB |
Output is correct |
2 |
Correct |
6 ms |
27224 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 |
1290 ms |
107676 KB |
Output is correct |
2 |
Correct |
1278 ms |
124128 KB |
Output is correct |
3 |
Correct |
1264 ms |
123996 KB |
Output is correct |
4 |
Correct |
1245 ms |
124376 KB |
Output is correct |
5 |
Correct |
984 ms |
107672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
76 ms |
33936 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
27228 KB |
Output is correct |
2 |
Correct |
6 ms |
27224 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 |
6 ms |
27228 KB |
Output is correct |
2 |
Correct |
6 ms |
27224 KB |
Output is correct |
3 |
Incorrect |
6 ms |
27228 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |