#include <bits/stdc++.h>
/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
*/
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
using namespace std;
#define SZ(a) (ll)a.size()
#define pb push_back
#define F first
#define S second
#define all(a) a.begin(), a.end()
#define md(a) (a%mod+mod)%mod
#define lc (id<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair<int, int> pii;
const ll maxn=1e6+5, LOG=30, mod=1e9+7, INF=1e18;
struct Node{
int ans, mx;
set<int> st;
Node(int ans_, int mx_, set<int> st_)
{
ans=ans_;
mx=mx_;
st=st_;
}
Node () {};
} seg[maxn<<2];
int n, q, A[maxn];
Node Merge(Node L, Node R)
{
int mx=max(L.mx, R.mx);
set<int> st;
for(int j:L.st) st.insert(j);
for(int j:R.st) st.insert(j);
int ans=max(L.ans, R.ans);
auto t=R.st.lower_bound(L.mx);
if(t!=R.st.begin()) ans=max(ans, L.mx+(*prev(t)));
return Node(ans, mx, st);
}
void Build(int l=1, int r=n+1, int id=1)
{
if(l==r-1)
{
seg[id]=Node(0, A[l], set<int>{A[l]});
return;
}
Build(l, mid, lc);
Build(mid, r, rc);
seg[id]=Merge(seg[lc], seg[rc]);
}
Node Get(int s, int e, int l=1, int r=n+1, int id=1)
{
if(l>=e || r<=s) return Node(0, 0, set<int>{});
if(s<=l && r<=e) return seg[id];
return Merge(Get(s, e, l, mid, lc), Get(s, e, mid, r, rc));
}
int main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n>>q;
for(int i=1;i<=n;i++) cin>>A[i];
Build();
while(q--)
{
int l, r, k;
cin>>l>>r>>k;
Node nd=Get(l, r+1);
if(nd.ans<=k) cout<<1<<"\n";
else cout<<"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... |