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> v;
vector<pair<int, pair<int, int>>> q[N];
struct node{
int max_high, max_low, add;
node(int mv = -1, int mi = -INF, int a = -1){
max_high = mv; max_low = mi; add = a;
}
};
node t[N << 2];
void push(int v, int vl, int vr){
if(t[v].add != -1){
if(t[v].max_high > t[v].add){
t[v].max_low = max(t[v].max_low, t[v].add);
}
if(vl != vr){
if(t[v*2+1].max_high > t[v].add){
t[v*2+1].add = max(t[v*2+1].add, t[v].add);
}
if(t[v*2+2].max_high > t[v].add){
t[v*2+2].add = max(t[v*2+2].add, t[v].add);
}
}
t[v].add = -1;
}
}
node unite(node& a, node& b){
if(a.max_high > b.max_high){
return a;
}else
if(a.max_high < b.max_high){
return b;
}else{
return a.max_low > b.max_low ? a : b;
}
}
void modify_segment(int v, int vl, int vr, int l, int r, int val){
push(v, vl, vr);
if(vl > r || vr < l){ return;}
if(l <= vl && vr <= r){
t[v].add = val;
push(v, vl, vr);
return;
}
int vm = (vl + vr) >> 1;
modify_segment(v*2+1, vl, vm, l, r, val);
modify_segment(v*2+2, vm+1, vr, l, r, val);
t[v] = unite(t[v*2+1], t[v*2+2]);
}
void modify_position(int v, int vl, int vr, int pos, int val){
push(v, vl, vr);
if(vl == vr){ t[v] = node(val, -INF, -1); return;}
int vm = (vl + vr) >> 1;
if(pos <= vm){
modify_position(v*2+1, vl, vm, pos, val);
}else{
modify_position(v*2+2, vm+1, vr, pos, val);
}
t[v] = unite(t[v*2+1], t[v*2+2]);
}
pair<int, int> query(int v, int vl, int vr, int l, int r){
push(v, vl, vr);
if(vl > r || vr < l){ return {-1, -1};}
if(l <= vl && vr <= r){
return {t[v].max_high, t[v].max_low};
}
int vm = (vl + vr) >> 1;
pair<int, int> q1 = query(v*2+1, vl, vm, l, r);
pair<int, int> q2 = query(v*2+2, vm+1, vr, l, r);
return q1.f + q1.s > q2.f + q2.s ? q1 : q2;
}
int main(){
n = read(); m = read();
v.resize(n);
for(int i = 0; i < n; i++){
v[i] = read();
}
for(int i = 0; i < m; i++){
int l = read()-1, r = read()-1, k = read();
q[r].pb({l, {i, k}});
}
for(int i = 0; i < n; i++){
modify_segment(0, 0, n-1, 0, i, v[i]);
for(auto j : q[i]){
pair<int, int> res = query(0, 0, n-1, j.f, i);
ans[j.s.f] = ((res.f + res.s) <= j.s.s);
}
modify_position(0, 0, n-1, i, v[i]);
}
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... |