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(REALBOY)
// не, не надо меня узнавать
/*#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;
int n, Q;
int a[N], ans[N];
struct st {
int l, k, id;
};
vector <st> q[N];
int d[N * 4];
void update (int v, int l, int r, int pos, int x) {
if (l == r) {
d[v] = max (d[v], x);
return;
}
int mid = l + r >> 1;
if (pos <= mid) update (v * 2, l, mid, pos, x);
else update (v * 2 + 1, mid + 1, r, pos, x);
d[v] = max (d[v * 2], d[v * 2 + 1]);
}
int get (int v, int l, int r, int nl, int nr) {
if (nl > r || l > nr) return 0;
if (nl <= l && r <= nr) return d[v];
int mid = l + r >> 1;
return max (get (v * 2, l, mid, nl, nr), get (v * 2 + 1, mid + 1, r, nl, nr));
}
void solve () {
cin >> n >> Q;
for (int i = 1; i <= n; i ++) cin >> a[i];
for (int i = 1; i <= Q; i ++) {
int l, r, k;
cin >> l >> r >> k;
q[r].pb ({l, k, i});
}
stack <int> s;
for (int i = 1; i <= n; i ++) {
while (sz (s) && a[s.top()] <= a[i]) s.pop();
if (sz (s) != 0) {
update (1, 1, n, s.top(), a[s.top()] + a[i]);
}
s.push (i);
for (auto it : q[i]) {
if (get (1, 1, n, it.l, i) > it.k) ans[it.id] = 0;
else ans[it.id] = 1;
}
}
for (int i = 1; i <= Q; i ++) {
cout << ans[i] << '\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 'void update(int, int, int, int, int)':
sortbooks.cpp:48:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
48 | int mid = l + r >> 1;
| ~~^~~
sortbooks.cpp: In function 'int get(int, int, int, int, int)':
sortbooks.cpp:56:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
56 | int mid = l + r >> 1;
| ~~^~~
sortbooks.cpp: At global scope:
sortbooks.cpp:84:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
84 | 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... |