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;
#define ll long long
#define pb push_back
#define ii pair<int, int>
#define all(x) x.begin(), x.end()
#define fo(i, a, b) for (int i = (a), b_ = (b); i <= b_; ++i)
#define fd(i, a, b) for (int i = (a), b_ = (b); i >= b_; --i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define fi first
#define se second
const int N = 1e6+5;
int n, m, a[N], l[N], ans[N], k[N];
ll t[N];
vector<ii> g[N];
void upd(int p, ll v) {
for (; p; p -= p & -p)
chmax(t[p], v);
}
ll get(int p) {
ll tot = 0;
for (; p <= n; p += p & -p)
chmax(tot, t[p]);
return tot;
}
void sol() {
cin >> n >> m;
fo(i,1,n) cin >> a[i];
fo(i,1,m) {
static int l, r;
cin >> l >> r >> k[i];
g[r].pb({l, i});
}
fo(i,1,n) {
l[i] = i-1;
while (l[i] && a[i] >= a[l[i]]) l[i] = l[l[i]];
if (l[i]) upd(l[i], a[l[i]] + a[i]);
for (ii q : g[i]) ans[q.se] = (get(q.fi) <= k[q.se]);
}
fo(i,1,m) cout << ans[i] << '\n';
}
signed main() {
cin.tie(0) -> sync_with_stdio(0);
if (fopen("A.inp", "r")) freopen("A.inp", "r", stdin);
int tc = 1, test = 0; // cin >> tc;
while (++test <= tc) sol();
}
Compilation message (stderr)
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:51:37: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
51 | if (fopen("A.inp", "r")) freopen("A.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# | 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... |