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 = 1e6+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{
int max_val, max_inv;
vector<int> v;
bool operator == (const node& B) const{
return (max_val == B.max_val);
}
};
int n, m;
vector<int> a;
node t[N << 2], badAss;
void build(int v, int vl, int vr){
if(vl == vr){
t[v].max_val = a[vl];
t[v].max_inv = 0;
t[v].v = vector<int> (1, a[vl]);
return;
}
int vm = (vl + vr) >> 1;
build(v*2+1, vl, vm);
build(v*2+2, vm+1, vr);
t[v].max_val = max(t[v*2+1].max_val, t[v*2+2].max_val);
t[v].max_inv = max(t[v*2+1].max_inv, t[v*2+2].max_inv);
merge(all(t[v*2+1].v), all(t[v*2+2].v), back_inserter(t[v].v));
if(t[v*2+1].max_val > t[v*2+2].v[0]){
t[v].max_inv = max(t[v].max_inv, *(--lower_bound(all(t[v*2+2].v), t[v*2+1].max_val)) + t[v*2+1].max_val);
}
}
//{max_val, max_inv}
pair<int, int> query(int v, int vl, int vr, int l, int r, int max_left){
if(vl > r || vr < l){ return {-1, 0};}
if(l <= vl && vr <= r){
pair<int, int> res = {t[v].max_val, t[v].max_inv};
if(max_left > t[v].v[0]){
res.s = *(--lower_bound(all(t[v].v), max_left)) + max_left;
}
res.s = max(res.s, t[v].max_inv);
res.f = max(res.f, max_left);
return res;
}
int vm = (vl + vr) >> 1;
pair<int, int> q1 = query(v*2+1, vl, vm, l, r, max_left);
pair<int, int> q2 = query(v*2+2, vm+1, vr, l, r, max(max_left, q1.f));
return {max(max(q1.f, q2.f), max_left), max(q1.s, q2.s)};
}
int main(){
sagyndym_seni;
badAss.max_val = -1;
badAss.max_inv = -1;
badAss.v = vector<int>(1, -1);
n = read(); m = read();
a.resize(n);
for(int i = 0; i < n; i++){
a[i] = read();
}
build(0, 0, n - 1);
while(m--){
int l = read()-1, r = read()-1, k = read();
pair<int, int> res = query(0, 0, n-1, l, r, -1);
res.s <= k ? putchar_unlocked('1') : putchar_unlocked('0');
putchar_unlocked('\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... |