#include <bits//stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_multiset;
#define ll long long
#define iloop(m, h) for (auto i = m; i != h; i += (m < h ? 1 : -1))
#define jloop(m, h) for (auto j = m; j != h; j += (m < h ? 1 : -1))
#define kloop(m, h) for (auto k = m; k != h; k += (m < h ? 1 : -1))
#define pll pair<ll, ll>
#define INF 1000000000000000
#define MOD1 1000000007
#define MOD2 998244353
#define MOD3 1000000009
ll n, m, a[1000005];
pair<pll, pll> b[1000005];
ll ans[1000005], cptr = 0;
ll fenw[1000005];
void upd(ll X, ll V) {
X++;
for (; X; X -= (X&(-X))) fenw[X] = max(fenw[X], V);
}
ll qu(ll X) {
X++;
ll cans = 0;
for (; X <= n; X += (X&(-X))) cans = max(cans, fenw[X]);
return cans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
iloop(0, n) cin >> a[i];
iloop(0, m) {
cin >> b[i].first.second >> b[i].first.first >> b[i].second.first;
b[i].first.first--, b[i].first.second--;
b[i].second.second = i;
}
sort(b, b+m);
vector<ll> st;
iloop(0, n) {
while (st.size() && a[st.back()] <= a[i]) st.pop_back();
if (st.size()) upd(st.back(), a[st.back()] + a[i]);
while (cptr < m && b[cptr].first.first == i) {
ans[b[cptr].second.second] = qu(b[cptr].first.second) <= b[cptr].second.first;
cptr++;
}
st.push_back(i);
}
iloop(0, m) cout << ans[i] << "\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... |