#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<random>
#include<cmath>
#include<stack>
#include<map>
#include <iomanip>
#include <queue>
#include <set>
using namespace std;
using ll = long long;
using ull = unsigned long long;
ll mod = 1e9 + 7;
ll pv(ll a, ll b) {
if (b == 0)return 1;
ll res = (pv(a, b / 2));
if (b % 2) {
return (((res * res) % mod) * (a % mod)) % mod;
}
else {
return (res * res) % mod;
}
}
ll gcd(ll a, ll b) {
while (b) {
a %= b;
swap(a, b);
}
return a;
}
ll n,s=1;
vector<ll> v;
map<ll,ll>seg;
void build(ll l, ll r, ll u) {
if(l == r) {
if(l < n) seg[u] = v[l];
return;
}
ll m = (l + r) / 2;
build(l, m, 2 * u + 1), build(m + 1, r, 2 * u + 2);
seg[u] = max(seg[2 * u + 1],seg[2 * u + 2]);
}
ll get(ll l, ll r, ll lx, ll rx, ll u) {
if(lx >= l && rx <= r) return seg[u];
if(lx > r || rx < l) return 0;
ll m = (lx + rx) / 2;
ll a = get(l, r, lx, m, 2 * u + 1), b = get(l, r, m + 1, rx, 2 * u + 2);
return max(a,b) ;
}
void modify(ll l, ll r, ll u, ll i, ll val) {
if(l == r) {
seg[u] = val;
return;
}
ll m = (l + r) / 2;
if(i <= m) modify(l, m, 2 * u + 1, i, val);
else modify(m + 1, r, 2 * u + 2, i, val);
seg[u] = max(seg[2 * u + 1],seg[2 * u + 2]);
}
void solve() {
ll q;
cin >> n >> q;
v=vector<ll>(n);
ll ara=0;
for(ll i=0; i<n; i++) {
cin >> v[i];
ara=max(ara,v[i]);
}
while(s<=ara)s<<=1;
while(q--) {
ll l,r,k;
cin >> l >> r >> k;
--l,--r;
ll mx=0;
seg.clear();
for(ll i=r; i>=l; i--) {
if(v[i]==0)continue;
ll aper=get(0,v[i]-1,0,s-1,0);
mx=max(mx,aper+v[i]);
modify(0,s-1,0,v[i],v[i]);
}
if(mx<=k)cout<<1<<endl;
else cout<<0<<endl;
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll _ = 1;
// cin >> _;
while (_--) {
solve();
}
}
# | 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... |