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
*/
#include <bits/stdc++.h>
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef long double ld;
#define F first
#define S second
#define Mp make_pair
#define pb push_back
#define pf push_front
#define size(x) ((ll)x.size())
#define all(x) (x).begin(),(x).end()
#define kill(x) cout << x << '\n', exit(0);
#define fuck(x) cout << "(" << #x << " , " << x << ")" << endl
#define endl '\n'
const int N = 1e6+23, lg = 20;
ll Mod = 1e9+7; //998244353;
inline ll MOD(ll a, ll mod=Mod) {a%=mod; (a<0)&&(a+=mod); return a;}
inline ll poww(ll a, ll b, ll mod=Mod) {
ll ans = 1;
a=MOD(a, mod);
while (b) {
if (b & 1) ans = MOD(ans*a, mod);
b >>= 1;
a = MOD(a*a, mod);
}
return ans;
}
int n, m, a[N], ans[N], ptr=1;
vector<vector<int>> q[N];
int seg[4*N], lazy[4*N];
inline void pushdown(int ind) {
if(lazy[ind] == 0) return;
seg[ind] += lazy[ind];
if(ind < (1<<lg)) {
lazy[2*ind] += lazy[ind];
lazy[2*ind+1] += lazy[ind];
}
lazy[ind] = 0;
}
void update(int l, int r, int val, int ind=1, int lc=1, int rc=(1<<lg)+1) {
if(lc>=l && rc<=r) {
lazy[ind] += val;
pushdown(ind);
return;
}
pushdown(ind);
if(lc>=r || l>=rc) {
return;
}
int mid = (lc+rc)/2;
update(l, r, val, 2*ind, lc, mid);
update(l, r, val, 2*ind+1, mid, rc);
seg[ind] = max(seg[2*ind], seg[2*ind+1]);
}
int query(int l, int r, int ind=1, int lc=1, int rc=(1<<lg)+1) {
pushdown(ind);
if(lc>=l && rc<=r) {
return seg[ind];
}
if(lc>=r || l>=rc) {
return 0;
}
int mid = (lc+rc)/2;
return max(query(l, r, 2*ind, lc, mid), query(l, r, 2*ind+1, mid, rc));
}
vector<int> st;
int main () {
ios_base::sync_with_stdio(false), cin.tie(0);
cin>>n>>m;
for(int i=1; i<=n; i++) {
cin>>a[i];
}
for(int l,r,k,i=1; i<=m; i++) {
cin>>l>>r>>k;
q[l].pb({r, k, i});
}
a[n+1] = (int)2e9;
st.pb(n+1);
for(int i=n; i>=1; i--) {
update(i, i+1, a[i]);
while(size(st)>0 && a[i] > a[st.back()]) {
int tmp = st.back();
st.pop_back();
update(tmp, tmp+1, a[i]);
update(tmp+1, st.back(), a[i]-a[tmp]);
}
st.pb(i);
for(auto it : q[i]) {
if(query(i, it[0]+1) <= it[1]) {
ans[it[2]] = 1;
}
}
}
for(int i=1; i<=m; i++) cout<<ans[i]<<'\n';
return 0;
}
# | 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... |