This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include "debug.hpp"
#define debug(x...) cerr << "[" << #x << "] = [", _print(x)
#else
#define debug(x...)
#endif
#define int long long
struct Query {
int l, w, id;
};
const int MAX = 1e6 + 5;
int n, Q, a[MAX], L[MAX], rs[MAX], tree[MAX];
vector<Query> g[MAX];
void update(int idx, int val) {
for (int i = idx; i; i -= i & -i)
tree[i] = max(tree[i], val);
}
int query(int idx) {
int rs = 0;
for (int i = idx; i <= n; i += i & -i)
rs = max(rs, tree[i]);
return rs;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef DEBUG
freopen("../_input", "r", stdin);
#endif
cin >> n >> Q;
for (int i = 1; i <= n; i++) {
cin >> a[i];
L[i] = i - 1;
int tmp = i - 1;
while (tmp && a[i] >= a[tmp])
L[i] = tmp = L[tmp];
}
int l, r, w;
for (int i = 1; i <= Q; i++) {
cin >> l >> r >> w;
g[r].push_back({l, w, i});
}
for (int i = 1; i <= n; i++) {
if (L[i])
update(L[i], a[L[i]] + a[i]);
for (auto q: g[i])
rs[q.id] = query(q.l) <= q.w;
}
for (int i = 1; i <= Q; i++)
cout << rs[i] << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |