This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// In The Name Of God
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <bitset>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <unordered_set>
#include <unordered_map>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define sagyndym_seni ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
const ll N = 2e5+5, p1 = 911382323, p2 = 972663749, mod = 1e9+123;
inline int read(){
char c = getchar_unlocked();
bool minus = 0;
while (c < '0' || '9' < c){
if(c == '-'){ minus = 1;}
c = getchar_unlocked();
if(c == '-'){ minus = 1;}
}
int res = 0;
while ('0' <= c && c <= '9') {
res = (res << 3) + (res << 1) + c - '0';
c = getchar_unlocked();
}
if(minus){ res *= -1;}
return res;
}
struct node{
ll max_val, max_inv;
vector<ll> v;
node(ll x = 0){
v = vector<ll>(1, x); max_val = x;
max_inv = 0;
}
bool operator == (const node& B) const{
return (max_val == B.max_val);
}
};
int n, m;
vector<ll> a;
node t[N << 2], badAss = node(-1LL);
node unite(node A, node B){
node C = node();
C.max_val = max(A.max_val, B.max_val);
C.max_inv = max(A.max_inv, B.max_inv);
merge(all(A.v), all(B.v), back_inserter(C.v));
if(A.max_val > B.v[0]){
C.max_inv = max(C.max_inv, *(lower_bound(all(B.v), A.max_val)--) + A.max_val);
}
return C;
}
void build(int v, int vl, int vr){
if(vl == vr){
t[v] = node(a[vl]);
return;
}
int vm = (vl + vr) >> 1;
build(v*2+1, vl, vm);
build(v*2+2, vm+1, vr);
t[v] = unite(t[v*2+1], t[v*2+2]);
}
node query(int v, int vl, int vr, int l, int r){
if(vl > r || vr < l){ return badAss;}
if(l <= vl && vr <= r){ return t[v];}
int vm = (vl + vr) >> 1;
node q1 = query(v*2+1, vl, vm, l, r);
node q2 = query(v*2+2, vm+1, vr, l, r);
if(q1 == badAss){ return q2;}
if(q2 == badAss){ return q1;}
return unite(q1, q2);
}
int main(){
n = read(); m = read();
a.resize(n);
for(int i = 0; i < n; i++){
cin>>a[i];
}
build(0, 0, n - 1);
while(m--){
int l = read()-1, r = read()-1, k = read();
node res = query(0, 0, n-1, l, r);
res.max_inv <= k ? cout<<"1\n" : cout<<"0\n";
}
return 0;
}
/* TIMUS: 292220YC*/
# | 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... |