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 int long long
#define nl '\n'
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
const int mod = 1000000007;
const int mod2 = 998244353;
// change this
const int N = 1000005;
int n, m, a, b, c, arr[N], ans[N];
vector< vector<int> > queries[N];
struct node {
node *l, *r;
int s, e, m, maxi = 0, val = 0, lazy = 0;
node(int _s, int _e): s(_s), e(_e), m((_s+_e)/2) {
if (s == e) {
maxi = arr[s];
} else {
l = new node(s, m), r = new node(m+1, e);
maxi = max(l->maxi, r->maxi);
}
}
int value() {
val = max(lazy, val);
if (s == e) {
if (val) return maxi + val;
else return 0;
}
l->lazy = max(lazy, l->lazy);
r->lazy = max(lazy, r->lazy);
lazy = 0;
if (val) return maxi + val;
else return 0;
}
void modify(int x, int y, int v) {
if (y < x) return;
if (v >= maxi) return;
if (s == x && e == y) {
lazy = max(lazy, v);
} else {
if (x > m) r->modify(x, y, v);
else if (y <= m) l->modify(x, y, v);
else l->modify(x, m, v), r->modify(m+1, y, v);
lazy = max(lazy, max(l->lazy, r->lazy));
}
}
int query(int x, int y) {
value();
if (s == x && e == y) return value();
if (x > m) return r->query(x, y);
if (y <= m) return l->query(x, y);
return max(l->query(x, m), r->query(m+1, y));
}
} *root;
signed main() {
io;
cin >> n >> m;
for (int i=0; i<n; i++) cin >> arr[i];
root = new node(0, n-1);
for (int i=0; i<m; i++) {
cin >> a >> b >> c;
queries[b-1].push_back({a-1, c, i});
}
for (int i=0; i<n; i++) {
root->modify(0, i-1, arr[i]);
for (auto j : queries[i]) {
int l = j[0], v = j[1], ai = j[2];
ans[ai] = (root->query(l, i) <= v);
}
}
for (int i=0; i<m; i++) cout << ans[i] << nl;
}
# | 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... |