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];
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];
}
build(1, 1, n);
while (m--) {
int l, r, k;
cin >> l >> r >> k;
if (get(1, 1, n, l, r) > k) {
cout << "0\n";
continue;
}
bool is = 1;
for (int i = l; i <= r && is; i++) {
for (int j = i + 1; j <= r && is; j++) {
if (a[i] > a[j] && a[i] + a[j] > k) is = 0;
}
}
cout << is << '\n';
}
}
Compilation message (stderr)
sortbooks.cpp: In function 'void build(long long int, long long int, long long int)':
sortbooks.cpp:19:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
19 | 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:30:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
30 | 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... |