#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
vector<int> st[4*N];
int mx[4*N], n;
void build(vector<int> &a, int i = 1, int l2 = 1, int r2 = n) {
if (l2 == r2) {
st[i]= {a[l2]};
mx[i] = 0;
return;
}
int m2 = (l2 + r2)/2;
build(a, 2*i, l2, m2);
build(a, 2*i+1, m2+1, r2);
st[i].resize(r2 - l2 + 1);
merge(st[2*i].begin(), st[2*i].end(), st[2*i+1].begin(), st[2*i+1].end(), st[i].begin());
int id = upper_bound(st[2*i+1].begin(), st[2*i+1].end(), st[2*i].back()) - st[2*i+1].begin();
if (!id) mx[i] = max(mx[2*i], mx[2*i+1]);
else {
mx[i] = max({mx[2*i], mx[2*i+1], st[2*i].back() + st[2*i+1][id-1]});
}
}
int M = 0, MS = 0;
void qry(int l, int r, int i = 1, int l2 = 1, int r2 = n) {
if (l <= l2 && r2 <= r) {
int id = upper_bound(st[i].begin(), st[i].end(), M) - st[i].begin();
MS = max(MS, mx[i]);
if (id) MS = max({MS, M + st[i][id-1]});
M = max(M, st[i].back());
return;
}
int m2 = (l2 + r2)/2;
if (l <= m2) qry(l, r, 2*i, l2, m2);
if (m2 +1 <= r) qry(l, r, 2*i+1, m2+1, r2);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int m;
cin >> n >> m;
vector<int> a(n+1);
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
build(a);
while (m--) {
int l, r, k;
cin >> l >> r >> k;
M = 0, MS = 0;
qry(l, r);
cout << (MS <= k) << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
95312 KB |
Output is correct |
2 |
Correct |
17 ms |
95508 KB |
Output is correct |
3 |
Correct |
17 ms |
95312 KB |
Output is correct |
4 |
Correct |
18 ms |
95312 KB |
Output is correct |
5 |
Correct |
17 ms |
95536 KB |
Output is correct |
6 |
Correct |
21 ms |
95568 KB |
Output is correct |
7 |
Correct |
17 ms |
95524 KB |
Output is correct |
8 |
Correct |
17 ms |
95740 KB |
Output is correct |
9 |
Correct |
19 ms |
95540 KB |
Output is correct |
10 |
Incorrect |
22 ms |
95312 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
95312 KB |
Output is correct |
2 |
Correct |
17 ms |
95508 KB |
Output is correct |
3 |
Correct |
17 ms |
95312 KB |
Output is correct |
4 |
Correct |
18 ms |
95312 KB |
Output is correct |
5 |
Correct |
17 ms |
95536 KB |
Output is correct |
6 |
Correct |
21 ms |
95568 KB |
Output is correct |
7 |
Correct |
17 ms |
95524 KB |
Output is correct |
8 |
Correct |
17 ms |
95740 KB |
Output is correct |
9 |
Correct |
19 ms |
95540 KB |
Output is correct |
10 |
Incorrect |
22 ms |
95312 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1999 ms |
247188 KB |
Output is correct |
2 |
Correct |
2021 ms |
262144 KB |
Output is correct |
3 |
Correct |
2140 ms |
262144 KB |
Output is correct |
4 |
Correct |
2221 ms |
262144 KB |
Output is correct |
5 |
Incorrect |
1900 ms |
262144 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
127 ms |
109648 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
95312 KB |
Output is correct |
2 |
Correct |
17 ms |
95508 KB |
Output is correct |
3 |
Correct |
17 ms |
95312 KB |
Output is correct |
4 |
Correct |
18 ms |
95312 KB |
Output is correct |
5 |
Correct |
17 ms |
95536 KB |
Output is correct |
6 |
Correct |
21 ms |
95568 KB |
Output is correct |
7 |
Correct |
17 ms |
95524 KB |
Output is correct |
8 |
Correct |
17 ms |
95740 KB |
Output is correct |
9 |
Correct |
19 ms |
95540 KB |
Output is correct |
10 |
Incorrect |
22 ms |
95312 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
95312 KB |
Output is correct |
2 |
Correct |
17 ms |
95508 KB |
Output is correct |
3 |
Correct |
17 ms |
95312 KB |
Output is correct |
4 |
Correct |
18 ms |
95312 KB |
Output is correct |
5 |
Correct |
17 ms |
95536 KB |
Output is correct |
6 |
Correct |
21 ms |
95568 KB |
Output is correct |
7 |
Correct |
17 ms |
95524 KB |
Output is correct |
8 |
Correct |
17 ms |
95740 KB |
Output is correct |
9 |
Correct |
19 ms |
95540 KB |
Output is correct |
10 |
Incorrect |
22 ms |
95312 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |