이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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);
int templazy = lazy;
lazy = 0;
if (!val) return 0;
if (s == e) return maxi + val;
if (templazy < l->maxi) l->lazy = max(templazy, l->lazy);
if (templazy < r->maxi) r->lazy = max(templazy, r->lazy);
return maxi + val;
}
void modify(int x, int y, int v) {
if (y < x) return;
if (v >= maxi) return; // no element here can actually do this
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);
val = 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... |