이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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[idx] = max(tree[idx], 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... |