#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->value() - l->maxi, r->value() - r->maxi);
val = max(val, 0ll);
}
}
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);
// cout << root->query(l, i) << endl;
}
}
for (int i=0; i<m; i++) cout << ans[i] << nl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23788 KB |
Output is correct |
2 |
Correct |
15 ms |
23788 KB |
Output is correct |
3 |
Correct |
17 ms |
24044 KB |
Output is correct |
4 |
Correct |
16 ms |
23916 KB |
Output is correct |
5 |
Correct |
15 ms |
23916 KB |
Output is correct |
6 |
Correct |
19 ms |
23916 KB |
Output is correct |
7 |
Correct |
16 ms |
23916 KB |
Output is correct |
8 |
Correct |
19 ms |
23916 KB |
Output is correct |
9 |
Correct |
16 ms |
23916 KB |
Output is correct |
10 |
Correct |
17 ms |
23916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23788 KB |
Output is correct |
2 |
Correct |
15 ms |
23788 KB |
Output is correct |
3 |
Correct |
17 ms |
24044 KB |
Output is correct |
4 |
Correct |
16 ms |
23916 KB |
Output is correct |
5 |
Correct |
15 ms |
23916 KB |
Output is correct |
6 |
Correct |
19 ms |
23916 KB |
Output is correct |
7 |
Correct |
16 ms |
23916 KB |
Output is correct |
8 |
Correct |
19 ms |
23916 KB |
Output is correct |
9 |
Correct |
16 ms |
23916 KB |
Output is correct |
10 |
Correct |
17 ms |
23916 KB |
Output is correct |
11 |
Incorrect |
19 ms |
24428 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3103 ms |
262144 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
261 ms |
47596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23788 KB |
Output is correct |
2 |
Correct |
15 ms |
23788 KB |
Output is correct |
3 |
Correct |
17 ms |
24044 KB |
Output is correct |
4 |
Correct |
16 ms |
23916 KB |
Output is correct |
5 |
Correct |
15 ms |
23916 KB |
Output is correct |
6 |
Correct |
19 ms |
23916 KB |
Output is correct |
7 |
Correct |
16 ms |
23916 KB |
Output is correct |
8 |
Correct |
19 ms |
23916 KB |
Output is correct |
9 |
Correct |
16 ms |
23916 KB |
Output is correct |
10 |
Correct |
17 ms |
23916 KB |
Output is correct |
11 |
Incorrect |
19 ms |
24428 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23788 KB |
Output is correct |
2 |
Correct |
15 ms |
23788 KB |
Output is correct |
3 |
Correct |
17 ms |
24044 KB |
Output is correct |
4 |
Correct |
16 ms |
23916 KB |
Output is correct |
5 |
Correct |
15 ms |
23916 KB |
Output is correct |
6 |
Correct |
19 ms |
23916 KB |
Output is correct |
7 |
Correct |
16 ms |
23916 KB |
Output is correct |
8 |
Correct |
19 ms |
23916 KB |
Output is correct |
9 |
Correct |
16 ms |
23916 KB |
Output is correct |
10 |
Correct |
17 ms |
23916 KB |
Output is correct |
11 |
Incorrect |
19 ms |
24428 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |