# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
344109 | Nurlykhan | Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) | C++17 | 717 ms | 3820 KiB |
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;
const int N = (int)2e5 + 10;
const int K = 450;
int n, m;
int w[N];
bool bad[N];
int max_value[N], max_mood[N];
vector<int> v[N / K];
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%d", &w[i]);
}
for (int i = 0; i < n; i++) {
int block_id = i / K;
max_value[block_id] = max(max_value[block_id], w[i]);
v[block_id].push_back(w[i]);
for (int j = i; j < (block_id + 1) * K; j++) {
if (w[i] > w[j]) {
max_mood[block_id] = max(max_mood[block_id], w[i] + w[j]);
}
}
}
for (int i = 0; i <= (n - 1) / K; i++) {
sort(v[i].begin(), v[i].end());
}
while (m--) {
int l, r, k;
scanf("%d%d%d", &l, &r, &k);
--l, --r;
int mx = 0, mxx = 0;
for (int i = l; i <= r; ) {
if (i % K == 0 && i + K - 1 <= r) {
int block_id = i / K;
mx = max(mx, max_mood[block_id]);
int id = lower_bound(v[block_id].begin(), v[block_id].end(), mxx) - v[block_id].begin() - 1;
if (id >= 0) {
mx = max(mx, mxx + v[block_id][id]);
}
mxx = max(mxx, max_value[block_id]);
i += K;
} else {
if (mxx <= w[i]) {
mxx = w[i];
} else {
mx = max(mx, mxx + w[i]);
}
i++;
}
}
if (k >= mx) {
printf("1\n");
} else {
printf("0\n");
}
}
return 0;
}
Compilation message (stderr)
# | 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... |