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 lli long long int
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define pii pair<int,int>
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T i, U ...j) {
cout << i << ' ', abc(j...);
}
template <typename T> void printv(T l, T r) {
for (; l != r; ++l)
cout << *l << " \n"[l + 1 == r];
}
#ifdef Doludu
#define test(x...) abc("[" + string(#x) + "]", x);
#define owo freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#else
#define test(x...) void(0)
#define owo ios::sync_with_stdio(false)
#endif
const int N = 1e6 + 87;
int bit[N];
void add(int p, int v) {
for (; p > 0; p -= p & (-p))
bit[p] = max(bit[p], v);
}
int query(int p) {
int ans = 0;
for (; p < N; p += p & (-p))
ans = max(ans, bit[p]);
return ans;
}
vector <int> seg[N], queries[N];
int l[N], r[N], k[N];
int main () {
owo;
int n, q;
cin >> n >> q;
vector <int> a(n);
for (int i = 0; i < n; ++i)
cin >> a[i];
vector <int> stk;
for (int i = 0; i < n; ++i) {
while (!stk.empty() && a[stk.back()] <= a[i])
stk.pop_back();
if (!stk.empty()) {
seg[i].pb(stk.back());
}
stk.pb(i);
}
stk.clear();
for (int i = n - 1; ~i; --i) {
while (!stk.empty() && a[stk.back()] >= a[i])
stk.pop_back();
if (!stk.empty()) {
seg[stk.back()].pb(i);
}
stk.pb(i);
}
for (int i = 0; i < q; ++i)
cin >> l[i] >> r[i] >> k[i], --l[i], --r[i], queries[r[i]].pb(i);
vector <int> ans(q);
for (int i = 0; i < n; ++i) {
for (int j : seg[i]) {
add(j + 2, a[i] + a[j]);
}
for (int id : queries[i]) {
ans[id] = query(l[id] + 2);
}
}
for (int i = 0; i < q; ++i)
cout << (ans[i] <= k[i] ? 1 : 0) << '\n';
}
# | 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... |