This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
no pain, no gain
*/
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx,avx2,fma")
#include <bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define szof(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define pii pair<int, int>
#define all(s) s.begin(), s.end()
#define prev myrza4321
#define y1 myrza1234
#define OK puts("OK")
using namespace std;
const int N = (int)1e6 + 6;
const int INF = (int)2e9 + 9;
int a[N];
int n, Q;
vector <int> tree[N * 4];
int get(int l, int r, int big, int v = 1, int tl = 1, int tr = n) {
if (l <= tl && tr <= r) {
if (tree[v][0] < big) {
int pos = lower_bound(all(tree[v]), big) - tree[v].begin() - 1;
return tree[v][pos];
} else {
return 0;
}
}
if (l > tr || tl > r) {
return 0;
}
int mid = tl + tr >> 1;
return max(get(l, r, big, v + v, tl, mid), get(l, r, big, v + v + 1, mid + 1, tr));
}
void build(int v, int tl, int tr) {
if (tl == tr) {
tree[v].pb(a[tl]);
return;
}
int mid = tl + tr >> 1;
build(v + v, tl, mid);
build(v + v + 1, mid + 1, tr);
merge(tree[v + v].begin(), tree[v + v].end(), tree[v + v + 1].begin(), tree[v + v + 1].end(), back_inserter(tree[v]));
}
void solve() {
int l, r, k;
scanf("%d %d %d", &l, &r, &k);
bool ok = 1;
for (int i = l; i < r; i++) {
int mxl = get(l, i, INF);
int mxr = get(i + 1, r, mxl);
if (mxl && mxr) {
ok &= (mxl + mxr <= k);
}
}
if (ok) {
puts("1");
} else {
puts("0");
}
}
main() {
cin >> n >> Q;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
build(1, 1, n);
while (Q--) {
solve();
}
}
Compilation message (stderr)
sortbooks.cpp: In function 'int get(int, int, int, int, int, int)':
sortbooks.cpp:39:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = tl + tr >> 1;
~~~^~~~
sortbooks.cpp: In function 'void build(int, int, int)':
sortbooks.cpp:48:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = tl + tr >> 1;
~~~^~~~
sortbooks.cpp: At global scope:
sortbooks.cpp:74:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
sortbooks.cpp: In function 'void solve()':
sortbooks.cpp:56:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &l, &r, &k);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:77:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &a[i]);
~~~~~^~~~~~~~~~~~~
# | 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... |