This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Nurstan Duisengaliev
// не, не надо меня узнавать
/*#pragma GCC target ("avx2")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("O3")*/
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define all(x) x.begin(), x.end()
#define in insert
#define mp make_pair
#define F first
#define S second
#define ppf pop_front
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair <int, int>
#define pll pair <ll, ll>
#define boost() ios_base::sync_with_stdio(0), cin.tie(0)
#define sz(x) (int)x.size()
using namespace std;
//using namespace __gnu_pbds;
//template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = (int)1e6 + 123;
const int mod = (int)1e9 + 7;
const ll INF = (ll)1e18 + 1;
struct st {
int a, b, maxi;
};
st d[N * 4];
int n, q, a[N];
st merge (st f, st s) {
st ans;
ans.maxi = (f.maxi, s.maxi);
if (f.a + f.b >= s.a + s.b) ans.a = f.a, ans.b = f.b;
else ans.a = s.a, ans.b = s.b;
if (f.maxi + s.a > ans.a + ans.b && f.maxi > s.a) {
ans.a = f.maxi, ans.b = s.a;
}
return ans;
}
void build (int v, int l, int r) {
if (l == r) {
d[v].a = a[l], d[v].b = -mod, d[v].maxi = a[l];
return;
}
int mid = l + r >> 1;
build (v * 2, l, mid);
build (v * 2 + 1, mid + 1, r);
d[v] = merge (d[v * 2], d[v * 2 + 1]);
}
st get (int v, int l, int r, int nl, int nr) {
if (nl > r || l > nr) {
st o;
o.maxi = -1;
return o;
}
if (nl <= l && r <= nr) return d[v];
int mid = l + r >> 1;
st f, s;
f = get (v * 2, l, mid, nl, nr), s = get (v * 2 + 1, mid + 1, r, nl, nr);
if (f.maxi == -1) return s;
else if (s.maxi == -1) return f;
else return merge (f, s);
}
void solve () {
cin >> n >> q;
for (int i = 1; i <= n; i ++) cin >> a[i];
build (1, 1, n);
while (q --) {
int l, r, k;
cin >> l >> r >> k;
st o = get (1, 1, n, l, r);
if (o.a + o.b > k) cout << 0 << '\n';
else cout << 1 << '\n';
}
}
main () {
// freopen (".in", "r", stdin);
// freopen (".out", "w", stdout);
boost ();
int TT = 1;
// cin >> TT;
while (TT --) {
solve ();
}
return 0;
}
Compilation message (stderr)
sortbooks.cpp: In function 'st merge(st, st)':
sortbooks.cpp:43:16: warning: left operand of comma operator has no effect [-Wunused-value]
43 | ans.maxi = (f.maxi, s.maxi);
| ~~^~~~
sortbooks.cpp: In function 'void build(int, int, int)':
sortbooks.cpp:56:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
56 | int mid = l + r >> 1;
| ~~^~~
sortbooks.cpp: In function 'st get(int, int, int, int, int)':
sortbooks.cpp:68:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
68 | int mid = l + r >> 1;
| ~~^~~
sortbooks.cpp: At global scope:
sortbooks.cpp:88:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
88 | main () {
| ^
# | 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... |