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 ll long long
#define int long long
#define pb push_back
#define all(x) x.begin(), x.end()
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
int t[4 * maxn], a[maxn];
int d[5005][5005];
void build(int v, int tl, int tr) {
if (tl == tr) {
t[v] = a[tl];
return;
}
int mid = tl + tr >> 1;
build(v + v, tl, mid);
build(v + v + 1, mid + 1, tr);
t[v] = min(t[v + v], t[v + v + 1]);
}
int get(int v, int tl, int tr, int l, int r) {
if (l > tr || r < tl) return (int)1e9 + 5;
if (l <= tl && tr <= r) {
return t[v];
}
int mid = tl + tr >> 1;
return min(get(v + v, tl, mid, l, r), get(v + v + 1, mid + 1, tr, l, r));
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
if (n <= 5000 && m <= 5000) {
for (int i = 1; i <= n; i++) {
int x = a[i];
for (int j = i + 1; j <= n; j++) {
d[i][j] = d[i][j - 1];
x = max(x, a[j]);
if (x > a[j]) {
d[i][j] = max(d[i][j], x + a[j]);
}
}
}
while (m--) {
int l, r, k;
cin >> l >> r >> k;
cout << (d[l][r] <= k) << '\n';
}
}
}
Compilation message (stderr)
sortbooks.cpp: In function 'void build(long long int, long long int, long long int)':
sortbooks.cpp:20:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
20 | int mid = tl + tr >> 1;
| ~~~^~~~
sortbooks.cpp: In function 'long long int get(long long int, long long int, long long int, long long int, long long int)':
sortbooks.cpp:31:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
31 | int mid = tl + tr >> 1;
| ~~~^~~~
# | 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... |