#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, 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 solve() {
ll q;
cin >> n >> q;
v=vector<ll>(n);
for(ll i=0; i<n; i++) {
cin >> v[i];
}
while(s<n)s<<=1;
seg=vector<ll>(2*s-1);
build(0,s-1,0);
while(q--) {
ll l,r,k;
cin >> l >> r >> k;
--l,--r;
ll mx=0;
for(int i=l;i<=r;i++){
for(int j=i;j<=r;j++){
if(v[j]<v[i])mx=max(mx,v[j]+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... |