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, INF = 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;
}
inline void print(bool flag){
flag ? putchar_unlocked('1') : putchar_unlocked('0');
putchar_unlocked('\n');
}
int n, m;
bool ans[N];
vector<int> a;
vector<pair<int, pair<int, int>>> q[N];
int tMax[N << 2], tInv[N << 2];
void build(int v, int vl, int vr){
if(vl == vr){ tMax[v] = a[vl]; return;}
int vm = (vl + vr) >> 1;
build(v*2+1, vl, vm);
build(v*2+2, vm+1, vr);
tMax[v] = max(tMax[v*2+1], tMax[v*2+2]);
}
void maximize(int v, int vl, int vr, int l, int r, int val){
if(vl > r || vr < l){ return;}
if(l <= vl && vr <= r){
tInv[v] = max(tInv[v], val);
return;
}
int vm = (vl + vr) >> 1;
maximize(v*2+1, vl, vm, l, r, val);
maximize(v*2+2, vm+1, vr, l, r, val);
}
int down(int v, int vl, int vr, int i){
if(tMax[v] <= a[i] || i <= vl){ return -1;}
if(vl == vr){ return tMax[v] > a[i] ? vl : -1;}
int vm = (vl + vr) >> 1;
int q1 = down(v*2+2, vm+1, vr, i);
if(q1 != -1){
return q1;
}
return down(v*2+1, vl, vm, i);
}
int query(int v, int vl, int vr, int l){
if(vl == vr){ return tInv[v];}
int vm = (vl + vr) >> 1;
if(l <= vm){
return max(tInv[v], query(v*2+1, vl, vm, l));
}else{
return max(tInv[v], query(v*2+2, vm+1, vr, l));
}
}
int main(){
n = read(); m = read();
a.resize(n);
for(int i = 0; i < n; i++){
a[i] = read();
}
for(int i = 0; i < m; i++){
int l = read()-1, r = read()-1, k = read();
q[r].pb({l, {i, k}});
}
build(0, 0, n-1);
for(int i = 0; i < n; i++){
int res = down(0, 0, n-1, i);
if(res != -1){
maximize(0, 0, n-1, 0, res, a[res] + a[i]);
}
for(auto j : q[i]){
ans[j.s.f] = (query(0, 0, n-1, j.f) <= j.s.s);
}
}
for(int i = 0; i < m; i++){
print(ans[i]);
}
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... |