// 01001100 01001111 01010100 01000001 \\
// \\
// ╦ ╔═╗╔╦╗╔═╗ \\
// ║ ║ ║ ║ ╠═╣ \\
// ╩═╝╚═╝ ╩ ╩ ╩ \\
// \\
// 01001100 01001111 01010100 01000001 \\
#include <bits/stdc++.h>
using namespace std;
#define N 1000001
#define nl '\n'
#define ff first
#define ss second
#define add insert
#define ll long long
#define ld long double
#define terminator main
#define pll pair<ll,ll>
#define append push_back
#define pii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define L0TA ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int n;
int a[N];
bool ans[N];
int seg[4 * N];
vector<pair<pii, int>> q[N];
void modify(int p, int x, int v = 1, int s = 0, int e = n){
if(e - s == 1){
seg[v] = max(seg[v], x);
return;
}
int mid, rc, lc;
mid = (s + e) / 2;
rc = 2 * v + 1;
lc = 2 * v;
if(p < mid) modify(p, x, lc, s, mid);
else modify(p, x, rc, mid, e);
}
int get(int l, int r, int v = 1, int s = 0, int e = n){
if(r <= s || e <= l) return 0;
if(l <= s && e <= r) return seg[v];
int mid, rc, lc;
mid = (s + e) / 2;
rc = 2 * v + 1;
lc = 2 * v;
return max(get(l, r, lc, s, mid), get(l, r, rc, mid, e));
}
void solve(){
int m, l, r, k;
cin >> n >> m;
for(int i = 0; i < n; i++)
cin >> a[i];
for(int i = 0; i < m; i++){
cin >> l >> r >> k;
q[r - 1].append({{l - 1, k}, i});
}
stack<pii> s;
for(int i = 0; i < n; i++){
while(!s.empty() && s.top().ff <= a[i])
s.pop();
if(!s.empty()) modify(s.top().ss, s.top().ff + a[i]);
s.push({a[i], i});
for(auto & [j, k] : q[i])
ans[k] = (get(j.ff, i) <= j.ss);
}
for(int i = 0; i < m; i++)
cout << ans[i] << nl;
}
int terminator(){
L0TA;
int T;
solve();
return 0;
}
# | 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... |