Problem:
F: きっちり - Kitsuchiri -
問題
若ヶ松高校二年へ組の合津千里（あつちり）さんは数列が「きっちり」していなければ気がすまない。
合津さんによると、「きっちり」した数列とは、長さが偶数で左右対称である数列のことである。
すなわち、長さ
N
(
N
は偶数)の数列
S
について、次の条件を満たせば数列
S
は「きっちり」している。
S_1 = S_N, S_2 = S_{N − 1},
...
, S_{N/2} = S_{N − N/2 + 1}
二年へ組の数学担当の先生は、合津さんから「きっちりしてください。」と要望され、授業で用いる数列を作り直さなければならない。
先生は、数列の
l
番目から
r
番目までのそれぞれの要素に数字
x
を足すクエリをいくつも適用することで、数列を「きっちり」させようと奮闘しているが、うまくいかないようだ。
二年へ組に所属する凄腕プログラマーのあなたの仕事は、先生が絶望してしまう前に、先生が作り直している数列が「きっちり」しているかを調べるプログラムを作ることだ。
入力形式
入力は以下の形式からなる。
N
S_1
...
S_N
Q
q_1
...
q_Q
Q
はクエリの総数であり、
1 \≤ i \≤ Q
について、各
q_i
は
l
,
r
,
x
を順に1つの半角スペースで区切って与えらる。
また、次の制約を満たす。
2 \≤ N \≤ 500,000
である。
N
は偶数である。
1 \≤ j \≤ N
について、
−100,000,000 \≤ S_j \≤ 100,000,000
である。
i
番目の各クエリを適用した後の数列の各要素
T_{i,j}
は
−100,000,000 \≤ T_{i,j} \≤ 100,000,000
を満たす。
1 \≤ Q \≤ 100,000
である。
1 \≤ l \≤ r \≤ N
である。
−1,000 \≤ x \≤ 1,000
である。
出力形式
クエリ
i
まで処理した後の数列が「きっちり」していれば“1”を、そうでなければ“0”を
i
行目に出力せよ。
入力例1
10
0 1 2 3 4 4 3 2 1 0
7
2 6 0
2 4 5
7 9 10
2 4 5
3 8 100
4 6 1000
7 7 1000
出力例1
1
0
0
1
1
0
1
入力例2
10
4 4 4 4 4 4 4 4 6 4
5
9 9 -2
1 10 1000
1 10 -1000
3 8 100
5 6 1
出力例2
1
1
1
1
1

Submitted solutions:

code_snippet: #include<bits/stdc++.h>
using namespace std;

using LL = long long; using ll = LL;
using PII = pair<int, int>; using pii = PII;
using PLL = pair<LL, LL>; using pll = PLL;
using VI = vector<int>; using VL = vector<LL>;
const ll LINF = 1e18;
const int INF = 1e9;
#define FOR(i,s,t) for(int i =s; i < t;i++)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()

const ll INIT = 0;
struct SegTree {
	int N;
	ll init_v;
	vector<pll> node;
	VL lazy;
	SegTree(int _N) :init_v(INIT) {
		init_v = 0;
		N = 1;
		while (N < _N) N *= 2;
		node.resize(2 * N - 1, pll(0,0));
		lazy.resize(2 * N - 1, 0);
	}

	pll merge(pll a, pll b) {
		pll ret = pll(-1e9, 1e9);
		ret.first = max(a.first, b.first);
		ret.second = min(a.second, b.second);
		return ret;
	}
	void lazy_e(int l, int r, int k) {
		node[k].first += lazy[k];
		node[k].second += lazy[k];
		if (r - l > 1) {
			lazy[2 * k + 1] += lazy[k];
			lazy[2 * k + 2] += lazy[k];
		}
		lazy[k] = 0;
	}

	void update(int a, int b, ll x) {
		update(a, b, 0, 0, N, x);
	}
	void update(int a, int b, int k, int l, int r, ll x) {
		lazy_e(l, r, k);
		if (r <= a || b <= l) return;
		if (a <= l && r <= b) {
			lazy[k] += x;
			lazy_e(l, r, k);
		}
		else {
			update(a, b, 2 * k + 1, l, (l + r) / 2, x);
			update(a, b, 2 * k + 2, (l + r) / 2, r, x);
			node[k] = merge(node[2 * k + 1], node[2 * k + 2]);
		}
	}

	pll query(int a, int b) { return query(a, b, 0, 0, N); }
	pll query(int a, int b, int k, int l, int r) {
		lazy_e(l, r, k);
		if (r <= a || b <= l) return pll(-1e9, 1e9);
		if (a <= l && r <= b) {
			return node[k];
		}
		else {
			return merge(
				query(a, b, 2 * k + 1, l, (l + r) / 2),
				query(a, b, 2 * k + 2, (l + r) / 2, r)
			);
		}
	}
};

void solve() {
	ll N; cin >> N;
	vector<ll> kassa(N); for (auto& in : kassa) cin >> in;
	ll Q; cin >> Q;
	ll  S = N / 2;
	SegTree ST(S);
	for (int i = 0; i < S; i++) {

		ST.update(i, i + 1, kassa[i]);
	}
	for (int i = S; i < N; i++) {
		//	cout << N - i << endl;
		ST.update(N - i - 1, N - i, -kassa[i]);
	}

	//	cout << ST.query(0, S) << endl;
	//return;
	while (Q--) {
		ll l, r, x; cin >> l >> r >> x;
		l--; r--;
		if (r < S) {
			ST.update(l, r + 1, x);
		}
		else if (l >= S) {
			ST.update(N - r - 1, N - l, -x);
		}
		else {
			ST.update(l, S, x);
			ST.update(N - r - 1, S, -x);
		}
		//cout << string(10, '=') << endl;
		//	cout << ST.query(0,S) << endl;
		pll a = ST.query(0, S);
		if (a.first == a.second && a.first == 0) {
			cout << 1 << endl;
		}
		else {
			cout << 0 << endl;
		}
//		cout << (ST.query(0, S) == 0) << endl;
		//		cout << string(10, '-') << endl;
	}
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	solve();

	return 0;
}
accuracy: 1
time_ms: 310
memory_kb: 19376
final_rank: 10

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

struct Node {
    int n;
    using NP = Node *;
    NP L, R;
    ll mi, mx, lz;

    void initNode() { mi = 0, mx = 0, lz = 0; }
    void update() { mi = min(L->mi, R->mi), mx = max(L->mx, R->mx); }
    void push() { L->lazy(lz), R->lazy(lz), lz = 0; }
    void lazy(ll x) { mi += x, mx += x, lz += x; }
    void add(int l, int r, ll x) {
        if (r <= 0 or n <= l) return;
        if (l <= 0 and n <= r) {
            lazy(x);
            return;
        }
        push();
        L->add(l, r, x);
        R->add(l - n / 2, r - n / 2, x);
        update();
    }
    Node(int n) : n(n) {
        initNode();
        if (n == 1) return;
        L = new Node(n / 2);
        R = new Node(n - n / 2);
    }
};
// sst = new Node(sz);
Node *sst = nullptr;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sst = new Node(n);
    for (int i = 0; i < n; ++i) {
        sst->add(i, i + 1, a[i] - a[n - 1 - i]);
    }
    int q;
    cin >> q;
    while (q--) {
        int l, r, x;
        cin >> l >> r >> x;
        l -= 1;
        sst->add(l, r, x);
        sst->add(n - r, n - l, -x);
        if (sst->mi == 0 and sst->mx == 0) cout << 1 << "\n";
        else cout << 0 << "\n";
    }
}
accuracy: 1
time_ms: 260
memory_kb: 69580
final_rank: 18

code_snippet: #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll ILL=2167167167167167167;
const int INF=2100000000;
const ll mod=998244353;
#define rep(i,a) for (ll i=0;i<a;i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}
template<class T> void vec_out(vector<T> &p){for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}
template<class T> T min(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;}
template<class T> T max(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;}

void solve();
// oddloop
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t=1;
	//cin>>t;
	rep(i,t) solve();
}

void solve(){
	int N;
	cin>>N;
	vector<int> S(N);
	rep(i,N) cin>>S[i];
	vector<int> p(N/2+2);
	vector<int> q(N/2+1);
	rep(i,N/2) p[i+1]=S[i]-S[N-i-1];
	rep(i,N/2+1) q[i]=p[i+1]-p[i];
	int ans=0;
	rep(i,N/2+1) if(q[i]!=0) ans++;
	int Q;
	cin>>Q;
	rep(i,Q){
		int l,r;
		ll x;
		cin>>l>>r>>x;
		if(N/2<l){
			l=N+1-l;
			r=N+1-r;
			swap(l,r);
			x=-x;
			r++;
		}else if(l<=N/2&&N/2<r){
			r=N+1-r;
			if(l>r) swap(l,r),x=-x;
			if(l==r) x=0;
		}else{
			r++;
		}
		if(q[l-1]!=0) ans--;
		q[l-1]+=x;
		if(q[l-1]!=0) ans++;
		if(q[r-1]!=0) ans--;
		q[r-1]-=x;
		if(q[r-1]!=0) ans++;
		//cout<<l<<" "<<r<<" "<<x<<"\n";
		if(ans==0) cout<<"1\n";
		else cout<<"0\n";
	}
}
accuracy: 1
time_ms: 40
memory_kb: 7016
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;

// 0-indexed
template <class T, class E>
struct SegmentTreeLaze {
  // a,b:T c,d:E e:E(unit)
  // g(f(a,b),c) = f(g(a,c),g(b,c))
  // g(g(a,c),d) = g(a,h(c,d))
  // g(a,e) = a
  typedef function<T(T, T)> F;
  typedef function<T(T, E)> G;
  typedef function<E(E, E)> H;
  int n, height;
  F f;
  G g;
  H h;
  T tunit;
  E eunit;
  vector<T> dat;
  vector<E> laz;
  SegmentTreeLaze(){};
  SegmentTreeLaze(int newn, F f, G g, H h, T nt, E ne)
      : f(f), g(g), h(h), tunit(nt), eunit(ne) {
    init(newn);
  }
  SegmentTreeLaze(const vector<T> &v, F f, G g, H h, T nt, E ne)
      : f(f), g(g), h(h), tunit(nt), eunit(ne) {
    int _n = v.size();
    init(v.size());
    for (int i = 0; i < _n; ++i) dat[n + i] = v[i];
    for (int i = n - 1; i; --i) dat[i] = f(dat[i << 1], dat[(i << 1) | 1]);
  }
  void init(int newn) {
    n = 1, height = 0;
    while (n < newn) n <<= 1, ++height;
    dat.assign(n << 1, tunit);
    laz.assign(n << 1, eunit);
  }

  inline T reflect(int k) {
    return laz[k] == eunit ? dat[k] : g(dat[k], laz[k]);
  }

  inline void eval(int k) {
    if (laz[k] == eunit) return;
    laz[k << 1] = h(laz[k << 1], laz[k]);
    laz[(k << 1) | 1] = h(laz[(k << 1) | 1], laz[k]);
    dat[k] = reflect(k);
    laz[k] = eunit;
  }

  inline void thrust(int k) {
    for (int i = height; i; --i) eval(k >> i);
    // reset query
    // dat[k] = reflect(k);
    // laz[k] = eunit;
  }

  void recalc(int k) {
    while (k >>= 1) dat[k] = f(reflect(k << 1), reflect((k << 1) | 1));
  }
  // [a,b)
  void update(int a, int b, E newdata) {
    thrust(a += n);
    thrust(b += n - 1);
    for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
      if (l & 1) laz[l] = h(laz[l], newdata), l++;
      if (r & 1) --r, laz[r] = h(laz[r], newdata);
    }
    recalc(a);
    recalc(b);
  }

  void set_val(int k, T newdata) {
    thrust(k += n);
    dat[k] = newdata;
    laz[k] = eunit;
    recalc(k);
  }

  // [a,b)
  T query(int a, int b) {
    thrust(a += n);
    thrust(b += n - 1);
    T vl = tunit, vr = tunit;
    for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
      if (l & 1) vl = f(vl, reflect(l++));
      if (r & 1) vr = f(reflect(--r), vr);
    }
    return f(vl, vr);
  }

  // require: func(unit) == false
  // min left: st <= res && func(seg.query(st,res + 1))
  template <typename C>
  int find_left(int st, C &func, T &acc, int k, int l, int r) {
    if (l + 1 == r) {
      acc = f(acc, reflect(k));
      return func(acc) ? l : -1;
    }
    eval(k);
    int mid = (l + r) >> 1;
    if (mid <= st) return find_left(st, func, acc, (k << 1) | 1, mid, r);
    if (st <= l && !func(f(acc, dat[k]))) {
      acc = f(acc, dat[k]);
      return -1;
    }
    int nres = find_left(st, func, acc, (k << 1), l, mid);
    if (~nres) return nres;
    return find_left(st, func, acc, (k << 1) | 1, mid, r);
  }
  template <typename C>
  int find_left(int st, C &func) {
    T acc = tunit;
    return find_left(st, func, acc, 1, 0, n);
  }

  // max right: res <= st && func(seg.query(res - 1,st))
  template <typename C>
  int find_right(int st, C &func, T &acc, int k, int l, int r) {
    if (l + 1 == r) {
      acc = f(reflect(k), acc);
      return func(acc) ? r : -1;
    }
    eval(k);
    int mid = (l + r) >> 1;
    if (st <= mid) return find_right(st, func, acc, k << 1, l, mid);
    if (r <= st && !func(f(dat[k], acc))) {
      acc = f(dat[k], acc);
      return -1;
    }
    int nres = find_right(st, func, acc, (k << 1) | 1, mid, r);
    if (~nres) return nres;
    return find_right(st, func, acc, k << 1, l, mid);
  }
  template <typename C>
  int find_right(int st, C &func) {
    T acc = tunit;
    return find_right(st, func, acc, 1, 0, n);
  }
};

int n, q;
SegmentTreeLaze<int, int> segmax, segmin;

int main() {
  cin >> n;
  {
    n >>= 1;
    vector<int> s(n);
    for (int i = 0; i < n; ++i) cin >> s[i];
    for (int i = n - 1; i >= 0; --i) {
      int p;
      cin >> p;
      s[i] -= p;
    }
    auto minf = [](int l, int r) { return min(l, r); };
    auto maxf = [](int l, int r) { return max(l, r); };
    auto gh = [](int l, int r) { return l + r; };
    segmin = SegmentTreeLaze<int, int>(s, minf, gh, gh, 0, 0);
    segmax = SegmentTreeLaze<int, int>(s, maxf, gh, gh, 0, 0);
  }
  cin >> q;
  while (q--) {
    int l, r, x;
    cin >> l >> r >> x;
    if (--l < n) {
      segmin.update(l, min(r, n), x);
      segmax.update(l, min(r, n), x);
    }
    if (r-- > n) {
      l = max(l, n);
      l -= n, r -= n;
      swap(l, r);
      l = n - 1 - l;
      r = n - r;
      segmin.update(l, r, -x);
      segmax.update(l, r, -x);
    }
    cout << (!segmin.query(0, n) && !segmax.query(0, n)) << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 350
memory_kb: 12372
final_rank: 9

code_snippet: #pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}
template <typename T,typename E>
struct lazysegtree{
  using F = function<T(T,T)>;
  using G = function<T(T,E)>;
  using H = function<E(E,E)>;
  int n,height;
  F f;
  G g;
  H h;
  T ti;
  E ei;
  vector<T> dat;
  vector<E> laz;
  lazysegtree(F f,G g,H h,T ti,E ei):
    f(f),g(g),h(h),ti(ti),ei(ei){}
  
  void init(int n_){
    n=1;height=0;
    while(n<n_) n<<=1,height++;
    dat.assign(2*n,ti);
    laz.assign(2*n,ei);
  }
  void build(const vector<T> &v){
    int n_=v.size();
    init(n_);
    for(int i=0;i<n_;i++) dat[n+i]=v[i];
    for(int i=n-1;i;i--)
      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
  }
  inline T reflect(int k){
    return laz[k]==ei?dat[k]:g(dat[k],laz[k]);
  }
  inline void eval(int k){
    if(laz[k]==ei) return;
    laz[(k<<1)|0]=h(laz[(k<<1)|0],laz[k]);
    laz[(k<<1)|1]=h(laz[(k<<1)|1],laz[k]);
    dat[k]=reflect(k);
    laz[k]=ei;
  }
  inline void thrust(int k){
    for(int i=height;i;i--) eval(k>>i);
  }
  inline void recalc(int k){    
    while(k>>=1)
      dat[k]=f(reflect((k<<1)|0),reflect((k<<1)|1));
  }
  void update(int a,int b,E x){
    thrust(a+=n);
    thrust(b+=n-1);
    for(int l=a,r=b+1;l<r;l>>=1,r>>=1){
      if(l&1) laz[l]=h(laz[l],x),l++;
      if(r&1) --r,laz[r]=h(laz[r],x);
    }
    recalc(a);
    recalc(b);
  }
  void set_val(int a,T x){
    thrust(a+=n);
    dat[a]=x;laz[a]=ei;
    recalc(a);
  }
  T query(int a,int b){
    thrust(a+=n);
    thrust(b+=n-1);
    T vl=ti,vr=ti;
    for(int l=a,r=b+1;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,reflect(l++));
      if(r&1) vr=f(reflect(--r),vr);
    }
    return f(vl,vr);
  }
};
int main(){
    auto f1=[&](ll a,ll b){
           if(a>b)return a;
           return b;
    };
    auto f2=[&](ll a,ll b){
           if(a<b)return a;
           return b;

    };
    auto g=[&](ll a,ll b){
           return a+b;
    };
    ll n;
    cin>>n;
    V<ll> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    V<ll> d(n/2);
    for(int i=0;i<n/2;i++){
            d[i]=a[i]-a[n-i-1];
    }
  lazysegtree<ll,ll> dpa(f1,g,g,-inf,0ll),dpb(f2,g,g,inf,0);
    dpa.build(d);
    dpb.build(d);
   // print(d);
    int q;
    cin>>q;
    while(q--){
         ll l,r,x;
         cin>>l>>r>>x;
         l--;
         ll L=min(l,n/2),R=min(n/2,r);
         if(L!=R){
             dpa.update(L,R,x);
             dpb.update(L,R,x);
         }
        // L=max(n/2,l)-n/2,R=max(n/2,r)-n/2;
         L=n/2-(max(n/2,r)-n/2); R=n/2-(max(n/2,l)-n/2);
         if(L!=R){
             dpa.update(L,R,-x);
             dpb.update(L,R,-x);
         }

        cout<<(dpa.query(0,n/2)==0&&dpb.query(0,n/2)==0)<<"\n";
        // for(int i=0;i<n/2;i++)cout<<dpa.query(i,i+1)<<" ";
        // cout<<"\n";
        // for(int i=0;i<n/2;i++)cout<<dpb.query(i,i+1)<<" ";
        // cout<<"\n";
        // cout<<dpa.query(0,n/2)<<" "<<dpb.query(0,n/2)<<"\n";
        // cout<<"\n";
    }
}
accuracy: 1
time_ms: 210
memory_kb: 25460
final_rank: 7

code_snippet: #include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
using namespace std;
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define flc(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define vec vector<lint>
#define nep(x) next_permutation(all(x))
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=3e5+5;
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//vector<int> bucket[MAX_N/1000];
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
/*#include<atcoder/all>
using namespace atcoder;
typedef __int128_t llint;*/

// Segment Tree Beats
// - l<=i<r について、 A_i の値を min(A_i, x) に更新
// - l<=i<r について、 A_i の値を max(A_i, x) に更新
// - l<=i<r の中の A_i の最大値を求める
// - l<=i<r の中の A_i の最小値を求める
// - l<=i<r の A_i の和を求める
// - l<=i<r について、 A_i の値に x を加える
// - l<=i<r について、 A_i の値を x に更新

class SegmentTreeBeats{
    static const lint inf = 1e18;
    struct Node{
        Node *left, *right;
        lint max_v, smax_v, max_c;
        lint min_v, smin_v, min_c;
        lint sum;
        lint len, ladd, lval;

        Node() : left(0), right(0), ladd(0), lval(inf) {}

        void init(lint x){
            max_v = min_v = sum = x;
            smax_v = -inf;
            smin_v = inf;
            max_c = min_c = 1;
        }

        void init_empty(){
            max_v = smax_v = -inf;
            min_v = smin_v = inf;
            max_c = min_c = 0;
        }

        void update_max(lint x){
            sum += (x - max_v) * max_c;

            if (max_v == min_v){
                max_v = min_v = x;
            }
            else if (max_v == smin_v){
                max_v = smin_v = x;
            }
            else{
                max_v = x;
            }

            if (lval != inf && x < lval){
                lval = x;
            }
        }

        void update_min(lint x){
            sum += (x - min_v) * min_c;

            if (max_v == min_v){
                max_v = min_v = x;
            }
            else if (max_v == smin_v){
                min_v = smax_v = x;
            }
            else{
                min_v = x;
            }

            if (lval != inf && lval < x){
                lval = x;
            }
        }

        void addalint(lint x)
        {
            max_v += x;
            if (smax_v != -inf) smax_v += x;
            min_v += x;
            if (smin_v != inf) smin_v += x;
            sum += len * x;
            if (lval != inf){
                lval += x;
            }
            else{
                ladd += x;
            }
        }

        void updatealint(lint x){
            max_v = min_v = x;
            smax_v = -inf;
            smin_v = inf;
            max_c = min_c = len;

            sum = len * x;
            lval = x;
            ladd = 0;
        }

        void push(){

            if (lval != inf){
                left->updatealint(lval);
                right->updatealint(lval);
                lval = inf;
                return;
            }

            if (ladd != 0){
                left->addalint(ladd);
                right->addalint(ladd);
                ladd = 0;
            }

            if (max_v < left->max_v){
                left->update_max(max_v);
            }
            if (left->min_v < min_v){
                left->update_min(min_v);
            }

            if (max_v < right->max_v){
                right->update_max(max_v);
            }
            if (right->min_v < min_v){
                right->update_min(min_v);
            }
        }

        void update(){
            sum = left->sum + right->sum;

            if (left->max_v < right->max_v){
                max_v = right->max_v;
                max_c = right->max_c;
                smax_v = max(left->max_v, right->smax_v);
            }
            else if (left->max_v > right->max_v){
                max_v = left->max_v;
                max_c = left->max_c;
                smax_v = max(left->smax_v, right->max_v);
            }
            else{
                max_v = left->max_v;
                max_c = left->max_c + right->max_c;
                smax_v = max(left->smax_v, right->smax_v);
            }

            if (left->min_v < right->min_v){
                min_v = left->min_v;
                min_c = left->min_c;
                smin_v = min(left->smin_v, right->min_v);
            }
            else if (left->min_v > right->min_v){
                min_v = right->min_v;
                min_c = right->min_c;
                smin_v = min(left->min_v, right->smin_v);
            }
            else{
                min_v = left->min_v;
                min_c = left->min_c + right->min_c;
                smin_v = min(left->smin_v, right->smin_v);
            }
        }
    };

    int n, n0;
    Node *root;

    void _update_min(lint x, int a, int b, Node *nd, int l, int r){
        if (b <= l || r <= a || nd->max_v <= x){
            return;
        }
        if (a <= l && r <= b && nd->smax_v < x){
            nd->update_max(x);
            return;
        }

        nd->push();
        _update_min(x, a, b, nd->left, l, (l + r) / 2);
        _update_min(x, a, b, nd->right, (l + r) / 2, r);
        nd->update();
    }

    void _update_max(lint x, int a, int b, Node *nd, int l, int r){
        if (b <= l || r <= a || x <= nd->min_v){
            return;
        }
        if (a <= l && r <= b && x < nd->smin_v){
            nd->update_min(x);
            return;
        }

        nd->push();
        _update_max(x, a, b, nd->left, l, (l + r) / 2);
        _update_max(x, a, b, nd->right, (l + r) / 2, r);
        nd->update();
    }

    void _add_val(lint x, int a, int b, Node *nd, int l, int r){
        if (b <= l || r <= a){
            return;
        }
        if (a <= l && r <= b){
            nd->addalint(x);
            return;
        }

        nd->push();
        _add_val(x, a, b, nd->left, l, (l + r) / 2);
        _add_val(x, a, b, nd->right, (l + r) / 2, r);
        nd->update();
    }

    void _update_val(lint x, int a, int b, Node *nd, int l, int r){
        if (b <= l || r <= a){
            return;
        }
        if (a <= l && r <= b){
            nd->updatealint(x);
            return;
        }

        nd->push();
        _update_val(x, a, b, nd->left, l, (l + r) / 2);
        _update_val(x, a, b, nd->right, (l + r) / 2, r);
        nd->update();
    }

    lint _query_max(int a, int b, Node *nd, int l, int r){
        if (b <= l || r <= a){
            return -inf;
        }
        if (a <= l && r <= b){
            return nd->max_v;
        }
        nd->push();
        lint lv = _query_max(a, b, nd->left, l, (l + r) / 2);
        lint rv = _query_max(a, b, nd->right, (l + r) / 2, r);
        return max(lv, rv);
    }

    lint _query_min(int a, int b, Node *nd, int l, int r){
        if (b <= l || r <= a){
            return inf;
        }
        if (a <= l && r <= b){
            return nd->min_v;
        }
        nd->push();
        lint lv = _query_min(a, b, nd->left, l, (l + r) / 2);
        lint rv = _query_min(a, b, nd->right, (l + r) / 2, r);
        return min(lv, rv);
    }

    lint _query_sum(int a, int b, Node *nd, int l, int r){
        if (b <= l || r <= a){
            return 0;
        }
        if (a <= l && r <= b){
            return nd->sum;
        }
        nd->push();
        lint lv = _query_sum(a, b, nd->left, l, (l + r) / 2);
        lint rv = _query_sum(a, b, nd->right, (l + r) / 2, r);
        return lv + rv;
    }

public:
    SegmentTreeBeats(int n, vector<lint> a) : n(n){
        n0 = 1;
        while (n0 < n) n0 <<= 1;

        Node *nds = new Node[2 * n0];
        root = nds;

        nds[0].len = n0;
        for (int i = 0; i < n0 - 1; ++i){
            nds[i].left = &nds[2 * i + 1];
            nds[i].right = &nds[2 * i + 2];
            nds[2 * i + 1].len = nds[2 * i + 2].len = (nds[i].len >> 1);
        }

        for (int i = 0; i < n; ++i) nds[n0 - 1 + i].init(a[i]);
        for (int i = n; i < n0; ++i) nds[n0 - 1 + i].init_empty();
        for (int i = n0 - 2; i >= 0; i--) nds[i].update();
    }
    SegmentTreeBeats(int n) : n(n){
        n0 = 1;
        while (n0 < n) n0 <<= 1;

        Node *nds = new Node[2 * n0];
        root = nds;

        nds[0].len = n0;
        for (int i = 0; i < n0 - 1; ++i){
            nds[i].left = &nds[2 * i + 1];
            nds[i].right = &nds[2 * i + 2];
            nds[2 * i + 1].len = nds[2 * i + 2].len = (nds[i].len >> 1);
        }

        for (int i = 0; i < n; ++i) nds[n0 - 1 + i].init(0);
        for (int i = n; i < n0; ++i) nds[n0 - 1 + i].init_empty();
        for (int i = n0 - 2; i >= 0; i--) nds[i].update();
    }

    void update_min(int a, int b, lint x){
        _update_min(x, a, b, root, 0, n0);
    }

    void update_max(int a, int b, lint x){
        _update_max(x, a, b, root, 0, n0);
    }

    void add_val(int a, int b, lint x){
        _add_val(x, a, b, root, 0, n0);
    }

    void update_val(int a, int b, lint x){
        _update_val(x, a, b, root, 0, n0);
    }

    lint query_max(int a, int b){
        return _query_max(a, b, root, 0, n0);
    }

    lint query_min(int a, int b){
        return _query_min(a, b, root, 0, n0);
    }

    lint query_sum(int a, int b){
        return _query_sum(a, b, root, 0, n0);
    }
};


int main(void){
    int N;
    cin >> N;
    int A[N];
    rep(i,N) cin >> A[i];
    int n=N/2;
    SegmentTreeBeats seg(n);
    rep(i,n) seg.update_val(i,i+1,A[i]);
    for(int i=n;i<N;i++) seg.add_val(n-1+(n-i),n+(n-i),-A[i]);
    int Q;
    cin >> Q;
    rep(i,Q){
        int l,r,x;
        cin >> l >> r >> x;
        l--,r--;
        if(l<n){
            seg.add_val(l,min(n,r+1),x);
        }
        if(r>=n){
            int R=(N-1-l);
            if(l<n) R=n-1;
            int L=(N-1-r);
            seg.add_val(L,R+1,-x);
        }
        bool chk=true;
        if(seg.query_min(0,n)!=0) chk=false;
        if(seg.query_max(0,n)!=0) chk=false;
        if(chk) cout << 1 << endl;
        else cout << 0 << endl;
    }
}
accuracy: 1
time_ms: 270
memory_kb: 54604
final_rank: 16

code_snippet: #include <bits/stdc++.h>
using namespace std;


int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int& x : a) cin >> x;
    for(int i = 0; i < n / 2; i++){
        a[i] -= a.rbegin()[i];
        a.rbegin()[i] = -a[i];
    }
    a.push_back(0);
    adjacent_difference(a.begin(), a.end(), a.begin());
    int zero = 0;
    for(int x : a) zero += !x;
    int q;
    cin >> q;
    while(q--){
        int l, r, x;
        cin >> l >> r >> x;
        l--;
        {
            zero -= !a[l];
            a[l] += x;
            zero += !a[l];
            zero -= !a[r];
            a[r] -= x;
            zero += !a[r];
        }
        tie(l, r) = pair{n - r, n - l};
        x = -x;
        {
            zero -= !a[l];
            a[l] += x;
            zero += !a[l];
            zero -= !a[r];
            a[r] -= x;
            zero += !a[r];
        }
        cout << (zero == n + 1) << '\n';
    }
}
accuracy: 1
time_ms: 200
memory_kb: 8608
final_rank: 5

code_snippet: #include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define LLINF 100000000000000

struct StarrySkyTree {
  int segn2;
  vector<ll> data, s_data;

  StarrySkyTree(int n) {
    for (segn2 = 1; segn2 < n; segn2 *= 2)
      ;
    data.assign(segn2 * 2, 0);
    s_data.assign(segn2 * 2, 0);
  }

  ll query(int a, int b, int l = 0, int r = -1, int k = 0) {
    if (r == -1) r = segn2;
    if (r <= a || b <= l) return LLINF;
    if (a <= l && r <= b) return data[k] + s_data[k];
    return min(query(a, b, l, (l + r) / 2, k * 2 + 1), query(a, b, (l + r) / 2, r, k * 2 + 2));
  }

  ll add(int a, int b, ll x, int l = 0, int r = -1, int k = 0) {
    if (r == -1) r = segn2;
    if (a <= l && r <= b)
      s_data[k] += x;
    else if (a < r && l < b)
      data[k] = min(add(a, b, x, l, (l + r) / 2, k * 2 + 1), add(a, b, x, (l + r) / 2, r, k * 2 + 2));

    return data[k] + s_data[k];
  }
};

int main() {
  int N;

  scanf("%d", &N);

  StarrySkyTree seg1(N / 2), seg2(N / 2);

  auto add = [&](int l, int r, ll x) {
    if (l < N / 2) {
      seg1.add(l, min(r, N / 2), x);
      seg2.add(l, min(r, N / 2), -x);
    }
    r = N - r;
    l = N - l;
    swap(l, r);
    if (l < N / 2) {
      seg1.add(l, min(r, N / 2), -x);
      seg2.add(l, min(r, N / 2), x);
    }
  };

  for (int i = 0; i < N; i++) {
    int S;
    scanf("%d", &S);
    add(i, i + 1, S);
  }

  int Q;

  scanf("%d", &Q);

  for (int i = 0; i < Q; i++) {
    int l, r, x;
    scanf("%d%d%d", &l, &r, &x);
    l--;
    add(l, r, x);

    int a = seg1.query(0, N / 2);
    int b = seg2.query(0, N / 2);

    puts(a == 0 && b == 0 ? "1" : "0");
  }

  return 0;
}
accuracy: 1
time_ms: 320
memory_kb: 19216
final_rank: 12

code_snippet: #include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

// quoted from beet-aizu
template <typename T,typename E, typename F, typename G, typename H>
struct LazySegmentTree{
    //using F = function<T(T,T)>;
    //using G = function<T(T,E)>;
    //using H = function<E(E,E)>;
    int n,height;
    F f;
    G g;
    H h;
    T ti;
    E ei;
    vector<T> dat;
    vector<E> laz;
    LazySegmentTree(F f,G g,H h,T ti,E ei):
        f(f),g(g),h(h),ti(ti),ei(ei){}

    void init(int n_){
        n=1;height=0;
        while(n<n_) n<<=1,height++;
        dat.assign(2*n,ti);
        laz.assign(2*n,ei);
    }
    void build(const vector<T> &v){
        int n_=v.size();
        init(n_);
        for(int i=0;i<n_;i++) dat[n+i]=v[i];
        for(int i=n-1;i;i--)
            dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
    }
    inline T reflect(int k){
        return laz[k]==ei?dat[k]:g(dat[k],laz[k]);
    }
    inline void eval(int k){
        if(laz[k]==ei) return;
        laz[(k<<1)|0]=h(laz[(k<<1)|0],laz[k]);
        laz[(k<<1)|1]=h(laz[(k<<1)|1],laz[k]);
        dat[k]=reflect(k);
        laz[k]=ei;
    }
    inline void thrust(int k){
        for(int i=height;i;i--) eval(k>>i);
    }
    inline void recalc(int k){    
        while(k>>=1)
            dat[k]=f(reflect((k<<1)|0),reflect((k<<1)|1));
    }
    void update(int a,int b,E x){
        thrust(a+=n);
        thrust(b+=n-1);
        for(int l=a,r=b+1;l<r;l>>=1,r>>=1){
            if(l&1) laz[l]=h(laz[l],x),l++;
            if(r&1) --r,laz[r]=h(laz[r],x);
        }
        recalc(a);
        recalc(b);
    }
    void set_val(int a,T x){
        thrust(a+=n);
        dat[a]=x;laz[a]=ei;
        recalc(a);
    }
    T query(int a,int b){
        thrust(a+=n);
        thrust(b+=n-1);
        T vl=ti,vr=ti;
        for(int l=a,r=b+1;l<r;l>>=1,r>>=1) {
            if(l&1) vl=f(vl,reflect(l++));
            if(r&1) vr=f(reflect(--r),vr);
        }
        return f(vl,vr);
    }
};

/* 
 *    [考えるべきこと]
 *    区間をマージしてから作用素を作用させても、作用素を作用させてから区間をマージするのと結果が同じ
 *    複数の作用素をマージして一度に作用させられること
 *    作用素を伝搬し終わっているのかの判定に必要（まあこれは満たされていなくても最悪どうにかなる）
 *    O(N) とかだと困る（setのマージとか）
 *    区間の長さに比例して作用が変わるときは，practice/RSRA や Library-Checher の RangeAffineRangeSum を参照する
 * 
 */

/**  テンプレ
int main(){
  using T = ***;  // type T
  using E = ***;  // type E
  auto f = [](T a, T b){ // return type T value
    return ***;
  };
  auto g = [](T a, E b){ // return type T value
    return ***;
  };
  auto h = [](E a, E b){ // return type E value
    return ***;
  };
  T ti = ***;  // identity element
  E ei = ***;  // identity element
  LazySegmentTree<T, E, decltype(f), decltype(g), decltype(h)> sg(f, g, h, ti, ei);  // don't change
  sg.build(***);
}
**/


#define int long long


signed main() {
  
  int n; cin >> n;
  vector<lint> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }

  vector<lint> dat(n / 2);
  for (int i = 0; i < n / 2; i++) {
    dat[i] = s[i] - s[n - i - 1];
  }

  auto f1 = [](int a, int b){ return min(a, b); };
  auto g1 = [](int a, int b){ return a + b; };
  auto h1 = [](int a, int b){ return a + b; };
  LazySegmentTree<int, int, decltype(f1), decltype(g1), decltype(h1)> sgmin(f1, g1, h1, INT_MAX, 0);
  sgmin.build(dat);

  auto f2 = [](int a, int b){ return max(a, b); };
  auto g2 = [](int a, int b){ return a + b; };
  auto h2 = [](int a, int b){ return a + b; };
  LazySegmentTree<int, int, decltype(f2), decltype(g2), decltype(h2)> sgmax(f2, g2, h2, -INT_MAX, 0);
  sgmax.build(dat);
  
  /*cerr << "min" << endl;
  for (int i = 0; i < n / 2; i++) {
    cerr << sgmin.query(i, i + 1) << " ";
  }
  cerr << endl;
  cerr << "max" << endl;
  for (int i = 0; i < n / 2; i++) {
    cerr << sgmax.query(i, i + 1) << " ";
  }
  cerr << endl;
  */

  int q; cin >> q;
  for (int i = 0; i < q; i++) {
    int l, r, x; cin >> l >> r >> x;
    l--;
    r--;
    
    // [0, n / 2)
    // [n / 2, n)
    if (r < n / 2) {
      sgmin.update(l, r + 1, x);
      sgmax.update(l, r + 1, x);
    } else if (l >= n / 2) {
      int ll = n - r - 1;
      int rr = n - l - 1;

      sgmin.update(ll, rr + 1, -x);
      sgmax.update(ll, rr + 1, -x);
    } else {
      // cerr << l << " " << n / 2 << " " << x << endl;
      sgmin.update(l, n / 2, x);
      sgmax.update(l, n / 2, x);
      
      int ll = n - r - 1;
      // cerr << ll << " " << n / 2 << " " << -x << endl;
      sgmin.update(ll, n / 2, -x);
      sgmax.update(ll, n / 2, -x);
    }

    // cerr << "min" << endl;
    /*
    for (int i = 0; i < n / 2; i++) {
      cerr << sgmin.query(i, i + 1) << " ";
    }
    cerr << endl;
    cerr << "max" << endl;
    for (int i = 0; i < n / 2; i++) {
      cerr << sgmax.query(i, i + 1) << " ";
    }
    cerr << endl;


    // 左 - 右をしているので
    cerr << sgmin.query(0, n / 2) << " " << sgmax.query(0, n / 2) << endl;

    */
    cout << (sgmin.query(0, n / 2) == 0 and sgmax.query(0, n / 2) == 0) << endl;
  }

  return 0;
}
accuracy: 1
time_ms: 420
memory_kb: 25028
final_rank: 15

code_snippet: #include <iostream>
#include <vector>
#include <functional>
using namespace std;

template <typename T, typename E>
struct LazySegmentTree{
private:
  using F = function<T(T,T)>;
  using G = function<T(T,E)>;
  using H = function<E(E,E)>;
  int n, height;
  F f;
  G g;
  H h;
  T ti;
  E ei;
  vector<T> dat;
  vector<E> laz;
  T reflect(int k){
    return laz[k] == ei ? dat[k] : g(dat[k],laz[k]);
  }
  void propagate(int k){
    if(laz[k] == ei) return;
    if(k >= n){
      dat[k] = reflect(k);
      laz[k] = ei;
      return;
    }
    laz[k<<1|0] = h(laz[k<<1|0],laz[k]);
    laz[k<<1|1] = h(laz[k<<1|1],laz[k]);
    dat[k] = reflect(k);
    laz[k] = ei;
  }
  void thrust(int k){
    for(int i = height; i >= 0; --i)
      propagate(k>>i);
  }
  void recalc(int k){
    while(k >>= 1){
      dat[k] = f(reflect(k<<1|0),reflect(k<<1|1));
    }
  }
public:
  LazySegmentTree(F f,G g, H h, T ti, E ei) :
    f(f), g(g), h(h), ti(ti), ei(ei) {}
  void build(int n_){
    n = n_;
    height = 2;
    while(n_ >>= 1) ++height;
    dat.assign(2*n,ti);
    laz.assign(2*n,ei);
  }
  void build(const vector<T> &v){
    int n_ = v.size();
    build(n_);
    for(int i = 0; i < n; ++i) dat[n+i]=v[i];
    for(int i = n-1; i >= 0; --i)
      dat[i]=f(dat[i<<1|0],dat[i<<1|1]);
  }
  void update(int l_, int r_, E x){
    if(l_ >= r_) return;
    l_ += n, r_ += n;
    thrust(l_);
    thrust(r_-1);
    for(int l = l_, r = r_;l < r; l >>= 1, r >>= 1){
      if(l&1) laz[l] = h(laz[l],x), ++l;
      if(r&1) --r, laz[r] = h(laz[r],x);
    }
    recalc(l_);
    recalc(r_-1);
  }
  void set_val(int a, T x){
    thrust(a+=n);
    dat[a] = x;
    laz[a] = ei;
    recalc(a);
  }
  T query(int l, int r){
    if(l >= r) return ti;
    l += n;
    r += n;
    thrust(l);
    thrust(r-1);
    T vl = ti, vr = ti;
    for(; l < r; l >>= 1, r >>= 1){
      if(l&1) vl = f(vl,reflect(l++));
      if(r&1) vr = f(reflect(--r),vr);
    }
    return f(vl,vr);
  }
};

int main(){
  using ll = long long;
  using T = pair<ll,ll>;
  using E = ll;
  function<T(T,T)> f = [](T a, T b) -> T {
                         return {max(a.first,b.first),min(a.second,b.second)};
                       };
  function<T(T,E)> g = [](T a, E b) -> T {
                         return {a.first+b,a.second+b};
                       };
  function<E(E,E)> h = [](E a, E b){
                         return a+b;
                       };
  const ll INF = 1e9;
  T ti = {-INF,INF};
  E ei = 0;
  LazySegmentTree<T,E> st(f,g,h,ti,ei);

  int N;
  cin >> N;
  vector<int> S(N);
  for(int i = 0; i < N; ++i){
    cin >> S[i];
  }
  int n = N/2;
  vector<T> A(n);
  for(int i = 0; i < n; ++i){
    A[i] = {S[i]-S[N-1-i], S[i]-S[N-1-i]};
  }

  int Q;
  cin >> Q;
  st.build(A);
  while(Q--){
    int l, r, x;
    cin >> l >> r >> x;
    --l, --r;
    if(l >= n){
      l = n - 1 - (l-n);
      r = n - 1 - (r-n);
      // cerr << l << " " << r << endl;
      st.update(r,l+1,-x);
    }else if(r < n){
      st.update(l,r+1,x);
    }else{
      st.update(l,n,x);
      r = n - 1 - (r-n);
      // cerr << r << endl;
      st.update(r,n,-x);
    }
    // for(int i = 0; i < n; ++i){
    //   cerr << "(" << st.query(i,i+1).first << ", " << st.query(i,i+1).second << ")  ";
    // }
    // cerr << endl;
    cout << (st.query(0,n) == make_pair(0LL,0LL)) << "\n";
  }
}
accuracy: 1
time_ms: 380
memory_kb: 20492
final_rank: 13

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;

// Segment Tree
template<class Monoid, class Action> struct SegTree {
    using FuncMonoid = function< Monoid(Monoid, Monoid) >;
    using FuncAction = function< void(Monoid&, Action) >;
    using FuncLazy = function< void(Action&, Action) >;
    FuncMonoid FM;
    FuncAction FA;
    FuncLazy FL;
    Monoid UNITY_MONOID;
    Action UNITY_LAZY;
    int SIZE, HEIGHT;
    vector<Monoid> dat;
    vector<Action> lazy;

    SegTree() { }
    SegTree(int n, const FuncMonoid fm, const FuncAction fa, const FuncLazy fl,
            const Monoid &unity_monoid, const Action &unity_lazy)
    : FM(fm), FA(fa), FL(fl), UNITY_MONOID(unity_monoid), UNITY_LAZY(unity_lazy) {
        SIZE = 1; HEIGHT = 0;
        while (SIZE < n) SIZE <<= 1, ++HEIGHT;
        dat.assign(SIZE * 2, UNITY_MONOID);
        lazy.assign(SIZE * 2, UNITY_LAZY);
    }
    void init(int n, const FuncMonoid fm, const FuncAction fa, const FuncLazy fl,
            const Monoid &unity_monoid, const Action &unity_lazy) {
        FM = fm; FA = fa; FL = fl;
        UNITY_MONOID = unity_monoid; UNITY_LAZY = unity_lazy;
        SIZE = 1; HEIGHT = 0;
        while (SIZE < n) SIZE <<= 1, ++HEIGHT;
        dat.assign(SIZE * 2, UNITY_MONOID);
        lazy.assign(SIZE * 2, UNITY_LAZY);
    }

    /* set, a is 0-indexed */
    void set(int a, const Monoid &v) { dat[a + SIZE] = v; }
    void build() {
        for (int k = SIZE - 1; k > 0; --k)
            dat[k] = FM(dat[k*2], dat[k*2+1]);
    }

    /* update [a, b) */
    inline void evaluate(int k) {
        if (lazy[k] == UNITY_LAZY) return;
        if (k < SIZE) FL(lazy[k*2], lazy[k]), FL(lazy[k*2+1], lazy[k]);
        FA(dat[k], lazy[k]);
        lazy[k] = UNITY_LAZY;
    }
    inline void update(int a, int b, const Action &v, int k, int l, int r) {
        evaluate(k);
        if (a <= l && r <= b)  FL(lazy[k], v), evaluate(k);
        else if (a < r && l < b) {
            update(a, b, v, k*2, l, (l+r)>>1), update(a, b, v, k*2+1, (l+r)>>1, r);
            dat[k] = FM(dat[k*2], dat[k*2+1]);
        }
    }
    inline void update(int a, int b, const Action &v) { update(a, b, v, 1, 0, SIZE); }

    /* get [a, b) */
    inline Monoid get(int a, int b, int k, int l, int r) {
        evaluate(k);
        if (a <= l && r <= b)
            return dat[k];
        else if (a < r && l < b)
            return FM(get(a, b, k*2, l, (l+r)>>1), get(a, b, k*2+1, (l+r)>>1, r));
        else
            return UNITY_MONOID;
    }
    inline Monoid get(int a, int b) { return get(a, b, 1, 0, SIZE); }
    inline Monoid operator [] (int a) { return get(a, a+1); }
    /* debug */
    void print() {
        for (int i = 0; i < SIZE; ++i) { cout << (*this)[i]; if (i != SIZE) cout << ","; }
        cout << endl;
    }
};

signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    cout << fixed << setprecision(20);

    ll m;
    cin>>m;
    ll a[m];
    for(int i=0;i<m;i++){
        cin>>a[i];
    }
    ll n = m/2;
    ll INF = 1e10;
    auto fm = [](long long a, long long b) { return max(a,b);};
    auto fm2 = [](ll a,ll b){ return min(a,b);};
    auto fa = [](long long &a, long long d) { a = a + d; };
    auto fl = [](long long &d, long long e) { d = d + e; };
    SegTree<long long, long long> seg(n+1, fm, fa, fl, 0, 0);
    SegTree<ll,ll> seg2(n+1,fm2,fa,fl,0,0);

    for(int i=0;i<n;i++){
        seg.update(i,i+1,a[i]-a[m-1-i]);
        seg2.update(i,i+1,a[i]-a[m-1-i]);
    }
    int q;
    cin>>q;
    while(q--){
        ll a,b,x;
        cin>>a>>b>>x;
        a--,b--;
        seg.update(min(a,n),min(b+1,n),x);
        seg2.update(min(a,n),min(b+1,n),x);
        seg.update(min(m-1-b,n),min(m-a,n),-x);
        seg2.update(min(m-1-b,n),min(n,m-a),-x);

        // cerr << "d1 "<<min(a,n) << " " << min(b+1,n) <<endl;
        // cerr << "d2 "<<min(n,m-b) << " " << min(m-a,n) << endl;
        // cerr<< seg.get(0,n) << " " << seg2.get(0,n) << " ";
        if(seg.get(0,n) == 0 && seg2.get(0,n)==0){
            cout << 1 << "\n";
        }
        else cout <<0 << "\n";
    }
}
accuracy: 1
time_ms: 380
memory_kb: 23168
final_rank: 14

code_snippet: #include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

class Segment_Tree {
	vector<long long int>v;
	vector<long long int>add;
	vector<long long int>modi;
	vector<int>l;
	vector<int>r;
	int num;
	long long int ret;
	bool is_min;
	void Left(int place) {
		if (place >= v.size() / 2) {
			l[place] = place - v.size() / 2;
			return;
		}
		Left(place * 2);
		Left(place * 2 + 1);
		l[place] = l[place * 2];
		return;
	}
	void Right(int place) {
		if (place >= v.size() / 2) {
			r[place] = place - v.size() / 2;
			return;
		}
		Right(place * 2);
		Right(place * 2 + 1);
		r[place] = r[place * 2 + 1];
		return;
	}
	long long int Update(int place) {
		if (place >= v.size() / 2) {
			return v[place];
		}
		if (is_min) {
			v[place] = min(Update(place * 2), Update(place * 2 + 1));
			return v[place];
		}
		v[place] = max(Update(place * 2), Update(place * 2 + 1));
		return v[place];
	}
	void Modify(int a, int b, long long int num, int place) {
		if (l[place] >= a && r[place] <= b) {
			modi[place] = num;
			v[place] = num;
			add[place] = 0;
			return;
		}
		if (l[place] > b || r[place] < a)return;
		if (modi[place] != LLONG_MAX) {
			modi[place * 2] = modi[place * 2 + 1] = modi[place];
			v[place * 2] = v[place * 2 + 1] = modi[place];
			add[place * 2] = add[place * 2 + 1] = 0;
			modi[place] = LLONG_MAX;
		}
		add[place * 2] += add[place];
		add[place * 2 + 1] += add[place];
		add[place] = 0;
		Modify(a, b, num, place * 2);
		Modify(a, b, num, place * 2 + 1);
		if (is_min)v[place] = min(v[place * 2] + add[place * 2], v[place * 2 + 1] + add[place * 2 + 1]);
		else v[place] = max(v[place * 2] + add[place * 2], v[place * 2 + 1] + add[place * 2 + 1]);
		return;
	}
	void Add(int a, int b, long long int num, int place) {
		if (l[place] >= a && r[place] <= b) {
			if (modi[place] != LLONG_MAX) {
				if (place * 2 < v.size()) {
					modi[place * 2] = modi[place * 2 + 1] = modi[place];
					v[place * 2] = v[place * 2 + 1] = modi[place];
					add[place * 2] = add[place * 2 + 1] = 0;
				}
				modi[place] = LLONG_MAX;
			}
			add[place] += num;
			return;
		}
		if (l[place] > b || r[place] < a)return;
		if (modi[place] != LLONG_MAX) {
			modi[place * 2] = modi[place * 2 + 1] = modi[place];
			v[place * 2] = v[place * 2 + 1] = modi[place];
			add[place * 2] = add[place * 2 + 1] = 0;
			modi[place] = LLONG_MAX;
		}
		add[place * 2] += add[place];
		add[place * 2 + 1] += add[place];
		add[place] = 0;
		Add(a, b, num, place * 2);
		Add(a, b, num, place * 2 + 1);
		if (is_min)v[place] = min(v[place * 2] + add[place * 2], v[place * 2 + 1] + add[place * 2 + 1]);
		else v[place] = max(v[place * 2] + add[place * 2], v[place * 2 + 1] + add[place * 2 + 1]);
		return;
	}
	void RMQ(int a, int b, int place) {
		if (l[place] >= a && r[place] <= b) {
			if (modi[place] != LLONG_MAX) {
				if (place * 2 < v.size()) {
					modi[place * 2] = modi[place * 2 + 1] = modi[place];
					v[place * 2] = v[place * 2 + 1] = modi[place];
					add[place * 2] = add[place * 2 + 1] = 0;
				}
				modi[place] = LLONG_MAX;
			}
			if (is_min)ret = min(ret, v[place] + add[place]);
			else ret = max(ret, v[place] + add[place]);
			return;
		}
		if (l[place]>b || r[place]<a) return;
		if (modi[place] != LLONG_MAX) {
			modi[place * 2] = modi[place * 2 + 1] = modi[place];
			v[place * 2] = v[place * 2 + 1] = modi[place];
			add[place * 2] = add[place * 2 + 1] = 0;
			modi[place] = LLONG_MAX;
		}
		add[place * 2] += add[place];
		add[place * 2 + 1] += add[place];
		add[place] = 0;
		RMQ(a, b, place * 2);
		RMQ(a, b, place * 2 + 1);
		if (is_min)v[place] = min(v[place * 2] + add[place * 2], v[place * 2 + 1] + add[place * 2 + 1]);
		else v[place] = max(v[place * 2] + add[place * 2], v[place * 2 + 1] + add[place * 2 + 1]);
		return;
	}
public:
	Segment_Tree(int n, bool min) {
		n++;
		num = 1;
		while (num < n * 2) {
			num *= 2;
		}
		l.resize(num);
		r.resize(num);
		is_min = min;
		if (min) {
			v.resize(num, MOD*MOD);
		}
		else v.resize(num, -MOD * MOD);
		add.resize(num, 0);
		modi.resize(num, MOD*MOD);
		Left(1);
		Right(1);
	}
	void Insert(int place, long long int num, bool update) {
		place += v.size() / 2;
		v[place] = num;
		if (!update)return;
		place /= 2;
		while (place) {
			if (is_min)v[place] = min(v[place * 2], v[place * 2 + 1]);
			else v[place] = max(v[place * 2], v[place * 2 + 1]);
			place /= 2;
		}
	}
	void Modify(int a, int b, long long int num) {
		Modify(a, b, num, 1);
	}
	void Add(int a, int b, long long int num) {
		Add(a, b, num, 1);
	}
	void Init() {
		Update(1);
	}
	long long int RMQ(int a, int b) {
		if (is_min)ret = LLONG_MAX;
		else ret = LLONG_MIN;
		RMQ(a, b, 1);
		return ret;
	}
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	long long int sum = 0;
	cin >> N;
	Segment_Tree sg(N/2, true);
	vector<int>v(N);
	for (auto &i : v)cin >> i;
	vector<long long int>w(N / 2);
	for (int i = 0; i < N / 2; i++) {
		w[i] = v[i] - v[N - 1 - i];
		sum += w[i];
		sg.Modify(i, i, w[i]);
	}
	cin >> K;
	while (K--) {
		cin >> L >> R >> M;
		L--, R--;
		if (R < N / 2) {
			sum += M * (R - L + 1);
			sg.Add(L, R, M);
		}
		else if (L >= N - N / 2) {
			sum -= M * (R - L + 1);
			sg.Add(N - 1 - R, N - 1 - L, -M);
		}
		else {
			sum += M * (N / 2 - L);
			sg.Add(L, N / 2, M);
			sum -= M * (R + 1 - (N - (N / 2)));
			sg.Add(N - 1 - R, N / 2, -M);
		}
		if (sg.RMQ(0, N/2) == 0 && !sum)cout << 1 << endl;
		else cout << 0 << endl;
	}
}
accuracy: 1
time_ms: 270
memory_kb: 23188
final_rank: 8

code_snippet: // #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

template <typename MonoidType, typename OperatorType>
struct LazySegmentTree {
    using MMtoM = function< MonoidType(MonoidType, MonoidType) >;
    using OOtoO = function< OperatorType(OperatorType, OperatorType) >;
    using MOtoM = function< MonoidType(MonoidType, OperatorType) >;
    using OItoO = function< OperatorType(OperatorType, int) >;

    // node, lazy, update flag (for lazy), identity element
    int n;
    vector<MonoidType> node;
    vector<OperatorType> lazy;
    vector<bool> need_update;
    MonoidType E0;
    OperatorType E1;

    // update / combine / lazy / accumulate function
    MOtoM upd_f;
    MMtoM cmb_f;
    OOtoO lzy_f;
    OItoO acc_f;

    void build(int m, vector<MonoidType> v = vector<MonoidType>()) {
        if(v != vector<MonoidType>()) m = v.size();
        n = 1; while(n < m) n *= 2;

        node = vector<MonoidType>(2*n-1, E0);
        lazy = vector<OperatorType>(2*n-1, E1);
        need_update = vector<bool>(2*n-1, false);
        if(v != vector<MonoidType>()) {
            for(int i=0; i<m; i++) {
                node[n-1+i] = v[i];
            }
            for(int i=n-2; i>=0; i--) {
                node[i] = cmb_f(node[2*i+1], node[2*i+2]);
            }
        }
    }

    // initialize
    LazySegmentTree() {}
    LazySegmentTree(int n_, MonoidType E0_, OperatorType E1_,
                    MOtoM upd_f_, MMtoM cmb_f_, OOtoO lzy_f_, OItoO acc_f_,
                    vector<MonoidType> v = vector<MonoidType>()) :
        E0(E0_), E1(E1_),
        upd_f(upd_f_), cmb_f(cmb_f_), lzy_f(lzy_f_), acc_f(acc_f_) {
        build(n_, v);
    }

    void eval(int k, int l, int r) {
        if(!need_update[k]) return;
        node[k] = upd_f(node[k], acc_f(lazy[k], r - l));
        if(r - l > 1) {
            lazy[2*k+1] = lzy_f(lazy[2*k+1], lazy[k]);
            lazy[2*k+2] = lzy_f(lazy[2*k+2], lazy[k]);
            need_update[2*k+1] = need_update[2*k+2] = true;
        }
        lazy[k] = E1;
        need_update[k] = false;
    }

    void update(int a, int b, OperatorType x, int l, int r, int k) {
        eval(k, l, r);
        if(b <= l or  r <= a) return;
        if(a <= l and r <= b) {
            lazy[k] = lzy_f(lazy[k], x);
            need_update[k] = true;
            eval(k, l, r);
        }
        else {
            int mid = (l + r) / 2;
            update(a, b, x, l, mid, 2*k+1);
            update(a, b, x, mid, r, 2*k+2);
            node[k] = cmb_f(node[2*k+1], node[2*k+2]);
        }
    }

    MonoidType query(int a, int b, int l, int r, int k) {
        if(b <= l or  r <= a) return E0;
        eval(k, l, r);
        if(a <= l and r <= b) return node[k];
        int mid = (l + r) / 2;
        MonoidType vl = query(a, b, l, mid, 2*k+1);
        MonoidType vr = query(a, b, mid, r, 2*k+2);
        return cmb_f(vl, vr);
    }

    // update [a, b)-th element (applied value, x)
    void update(int a, int b, OperatorType x) {
        update(a, b, x, 0, n, 0);
    }

    // range query for [a, b)
    MonoidType query(int a, int b) {
        return query(a, b, 0, n, 0);
    }

    void dump() {
        fprintf(stderr, "[lazy]\n");
        for(int i=0; i<2*n-1; i++) {
            if(i == n-1) fprintf(stderr, "xxx ");
            if(lazy[i] == E1) fprintf(stderr, "  E ");
            else fprintf(stderr, "%3d ", lazy[i]);
        }
        fprintf(stderr, "\n");

        fprintf(stderr, "[node]\n");
        for(int i=0; i<2*n-1; i++) {
            if(i == n-1) fprintf(stderr, "xxx ");
            if(node[i] == E0) fprintf(stderr, "  E ");
            else fprintf(stderr, "%3d ", node[i]);
        }
        fprintf(stderr, "\n");
    }
};

int main() {
    int N; cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];

    // 差分: 左 - 右
    vector<int> B(N);
    int H = N / 2;
    for(int i=0; i<H; i++) {
        B[i] = A[i] - A[N-1-i];
    }

    using PI = pair<ll, ll>;

    const PI E0(LONGINF, -LONGINF);
    const ll E1 = 0;
    LazySegmentTree<PI, ll> seg(H, E0, E1,
                                [](PI a, ll b) {
                                    a.first += b;
                                    a.second += b;
                                    return a;
                                },
                                [](PI a, PI b) {
                                    ll x = min(a.first, b.first);
                                    ll y = max(a.second, b.second);
                                    return make_pair(x, y);
                                },
                                [](ll a, ll b) {
                                    return a + b;
                                },
                                [](ll a, int x) {
                                    return a;
                                },
                                vector<PI>(H, make_pair(0, 0)));
    for(int i=0; i<H; i++) seg.update(i, i+1, B[i]);

    int Q; cin >> Q;
    for(int i=0; i<Q; i++) {
        int l, r, x; cin >> l >> r >> x; l--;

        int dl = max(H - l, 0);
        int dr = max(r - H, 0);

        int d = min(dl, dr);
        // fprintf(stderr, "### query %d: d = %d\n", i, d);
        if(d > 0) {
            int ql = l, qr = H - d;
            // fprintf(stderr, "? 1: l = %d, r = %d\n", ql, qr);
            if(ql < qr) {
                // fprintf(stderr, "q1: l = %d, r = %d\n", ql, qr);
                seg.update(ql, qr, x);
            }
        }
        if(d > 0) {
            int ql = N - r, qr = H - d;
            // fprintf(stderr, "? 2: l = %d, r = %d\n", ql, qr);
            if(ql < qr) {
                // fprintf(stderr, "q2: l = %d, r = %d\n", ql, qr);
                seg.update(ql, qr, -x);
            }
        }
        if(d == 0) {
            int ql = l, qr = r;
            if(ql >= H) {
                swap(ql, qr);
                ql = N - ql, qr = N - qr, x = -x;
            }
            // fprintf(stderr, "q3: l = %d, r = %d\n", ql, qr);
            seg.update(ql, qr, x);
        }

        auto res = seg.query(0, H);
        if(res.first == 0 and res.second == 0) cout << 1 << endl;
        else cout << 0 << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 480
memory_kb: 26868
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ull=unsigned long long;
using uint=unsigned int;
using pcc=pair<char,char>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using pdd=pair<double,double>;
using tuplis=pair<ll,pll>;
using tuplis2=pair<pll,ll>;
template<class T> using pq=priority_queue<T,vector<T>,greater<T>>;
const ll LINF=0x1fffffffffffffff;
const ll MINF=0x7fffffffffff;
const int INF=0x3fffffff;
const ll MOD=1000000007;
const ll MODD=998244353;
const ld DINF=numeric_limits<ld>::infinity();
const ld EPS=1e-9;
const ld PI=3.141592653589793238462643383279;
const vector<ll>four{0,1,0,-1,0};
#define _overload4(_1,_2,_3,_4,name,...) name
#define _overload3(_1,_2,_3,name,...) name
#define _rep1(n) for(ll i=0;i<n;++i)
#define _rep2(i,n) for(ll i=0;i<n;++i)
#define _rep3(i,a,b) for(ll i=a;i<b;++i)
#define _rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) _overload4(__VA_ARGS__,_rep4,_rep3,_rep2,_rep1)(__VA_ARGS__)
#define _rrep1(n) for(ll i=(n)-1;i>=0;i--)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=a;i--)
#define _rrep4(i,a,b,c) for(ll i=a+(b-a-1)/c*c;i>=a;i-=c)
#define rrep(...) _overload4(__VA_ARGS__,_rrep4,_rrep3,_rrep2,_rrep1)(__VA_ARGS__)
#define each(i,a) for(auto &i:a)
#define sum(...) accumulate(range(__VA_ARGS__),0LL)
#define dsum(...) accumulate(range(__VA_ARGS__),double(0))
#define _range(i) (i).begin(),(i).end()
#define _range2(i,k) (i).begin(),(i).begin()+k
#define _range3(i,a,b) (i).begin()+a,(i).begin()+b
#define range(...) _overload3(__VA_ARGS__,_range3,_range2,_range)(__VA_ARGS__)
#define _rrange(i) (i).rbegin(),(i).rend()
#define _rrange2(i,k) (i).rbegin(),(i).rbegin()+k
#define _rrange3(i,a,b) (i).rbegin()+a,(i).rbegin()+b
#define rrange(...) _overload3(__VA_ARGS__,_rrange3,_rrange2,_rrange)(__VA_ARGS__)
#define elif else if
#define unless(a) if(!(a))
#define mp make_pair
#define mt make_tuple
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__));in(name)
#define vvv(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
template<class T> inline constexpr T min(vector<T> &v){return *min_element(range(v));}
inline char min(string &v){return *min_element(range(v));}
template<class T> inline constexpr T max(vector<T> &v){return *max_element(range(v));}
inline char max(string &v){return *max_element(range(v));}
inline constexpr ll intpow(ll a,ll b){ll ans=1;for(ll i=1;b;i*=2){if(b&i){b^=i;ans*=a;}a*=a;}return ans;}
template<typename T>
inline constexpr bool chmin(T &mn,const T &cnt){if(mn>cnt){mn=cnt;return 1;}else return 0;}
template<typename T>
inline constexpr bool chmax(T &mx,const T &cnt){if(mx<cnt){mx=cnt;return 1;}else return 0;}
template<class T> unordered_map<T,ll> press(vector<T> &a){ auto b = a; sort(range(b)); b.erase(unique(range(b)), b.end()); unordered_map<T,ll> ans; rep(b.size()) ans[b[i]] = i; each(i, a) i = ans[i]; return ans; }
template<class T> map<T,ll> press_map(vector<T> &a){ auto b = a; sort(range(b)); b.erase(unique(range(b)), b.end()); map<T,ll> ans; rep(b.size()) ans[b[i]] = i; each(i, a) i = ans[i]; return ans; }
inline int scan(){ return getchar(); }
inline void scan(int &a){ scanf("%d", &a); }
inline void scan(unsigned &a){ scanf("%u", &a); }
inline void scan(long &a){ scanf("%ld", &a); }
inline void scan(long long &a){ scanf("%lld", &a); }
inline void scan(unsigned long long &a){ scanf("%llu", &a); }
inline void scan(char &a){ cin >> a; }
inline void scan(float &a){ scanf("%f", &a); }
inline void scan(double &a){ scanf("%lf", &a); }
inline void scan(long double &a){ scanf("%Lf", &a); }
inline void scan(vector<bool> &vec){ for(unsigned i = 0; i < vec.size(); i++) { int a; scan(a); vec[i] = a; } }
inline void scan(string &a){ cin >> a; }
template<class T> inline void scan(vector<T> &vec);
template<class T, size_t size> inline void scan(array<T, size> &vec);
template<class T, class L> inline void scan(pair<T, L> &p);
template<class T, size_t size> inline void scan(T (&vec)[size]);
template<class T> inline void scan(vector<T> &vec){ for(auto &i : vec) scan(i); }
template<class T, size_t size> inline void scan(array<T, size> &vec){ for(auto &i : vec) scan(i); }
template<class T, class L> inline void scan(pair<T, L> &p){ scan(p.first); scan(p.second); }
template<class T, size_t size> inline void scan(T (&vec)[size]){ for(auto &i : vec) scan(i); }
template<class T> inline void scan(T &a){ cin>>a; }
inline void in(){}
template <class Head, class... Tail> inline void in(Head &head, Tail&... tail){ scan(head); in(tail...); }
inline void print(){ putchar(' '); }
inline void print(const bool &a){ printf("%d", a); }
inline void print(const int &a){ printf("%d", a); }
inline void print(const unsigned &a){ printf("%u", a); }
inline void print(const long &a){ printf("%ld", a); }
inline void print(const long long &a){ printf("%lld", a); }
inline void print(const unsigned long long &a){ printf("%llu", a); }
inline void print(const char &a){ printf("%c", a); }
inline void print(const char a[]){ printf("%s", a); }
inline void print(const float &a){ printf("%.15f", a); }
inline void print(const double &a){ printf("%.15f", a); }
inline void print(const long double &a){ printf("%.15Lf", a); }
template<class T> void print(const vector<T> &vec);
template<class T, size_t size> void print(const array<T, size> &vec);
template<class T, class L> void print(const pair<T, L> &p);
template<class T, size_t size> inline void print(const T (&vec)[size]);
template<class T> void print(const vector<T> &vec){ if(vec.empty()) return; print(vec[0]); for(auto i = vec.begin(); ++i != vec.end(); ){ putchar(' '); print(*i); } }
template<class T, size_t size> void print(const array<T, size> &vec){ print(vec[0]); for(auto i = vec.begin(); ++i != vec.end(); ){ putchar(' '); print(*i); } }
template<class T, class L> void print(const pair<T, L> &p){ print(p.first); putchar(' '); print(p.second); }
template<class T, size_t size> inline void print(const T (&vec)[size]){ print(vec[0]); for(auto i = vec; ++i != end(vec); ){ putchar(' '); print(*i); } }
template<class T> inline void print(const T &a){ cout << a; }
inline int out(){ putchar('\n'); return 0; }
template<class T> inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class Head, class... Tail> inline int out(const Head &head, const Tail&... tail){ print(head); putchar(' '); out(tail...); return 0; }
template <class T> inline void err(T t){cerr<<t<<'\n';}
inline void err(){cerr<<'\n';}
inline int first(const bool &i){return out(i?"first":"second");}
inline int yes(const bool &i){return out(i?"yes":"no");}
inline int Yes(const bool &i){return out(i?"Yes":"No");}
inline int YES(const bool &i){return out(i?"YES":"NO");}
inline int Yay(const bool &i){return out(i?"Yay!":":(");}
inline int Possible(const bool &i){return out(i?"Possible":"Impossible");}
inline int POSSIBLE(const bool &i){return out(i?"POSSIBLE":"IMPOSSIBLE");}
inline void Case(ll i){printf("Case #%lld: ",i);}



template<class T>
struct SegmentTree{
    using F = function<T(T, T)>;
    ll size = 1;
    vector<T> data;
    const F f;
    const T def_value;
    SegmentTree(ll n, const T& def_value, const F& f): f(f), def_value(def_value){
        while(size < n) size *= 2;
        data.assign(size * 2, def_value);
    }
    SegmentTree(const vector<T>& v, const T& def_value, const F& f): f(f), def_value(def_value){
        while(size < v.size()) size *= 2;
        data.assign(size * 2, def_value);
        for(ll i = 0; i < v.size(); i++) data[size + i] = v[i];
        for(ll i = size; --i;) data[i] = f(data[i * 2], data[i * 2 + 1]);
    }
    T operator[](ll at) const {
        return data[size + at];
    }
    void update(ll at){
        while(at /= 2) data[at] = f(data[at * 2], data[at * 2 + 1]);
    }
    void set(ll at, const T& val){
        at += size;
        data[at] = val;
        update(at);
    }
    void add(ll at, const T& val){
        at += size;
        data[at] += val;
        update(at);
    }
    T get(ll l, ll r) const {
        T L = def_value, R = def_value;
        l += size; r += size;
        for(; l < r; l /= 2, r /= 2){
            if(l & 1) L = f(L, data[l++]);
            if(r & 1) R = f(data[--r], R);
        }
        return f(L, R);
    }
    void clear(){
        for(auto& i : data) i = def_value;
    }
};
template<class T>
struct SegmentTreeMin : SegmentTree<T>{
    SegmentTreeMin(ll n, const T& def_value) : SegmentTree<T>(n, def_value, [](T a, T b){return min(a, b);}){}
    SegmentTreeMin(const vector<T>& v, const T& def_value) : SegmentTree<T>(v, def_value, [](T a, T b){return min(a, b);}){}
};
template<class T>
struct SegmentTreeMax : SegmentTree<T>{
    SegmentTreeMax(ll n, const T& def_value) : SegmentTree<T>(n, def_value, [](T a, T b){return max(a, b);}){}
    SegmentTreeMax(const vector<T>& v, const T& def_value) : SegmentTree<T>(v, def_value, [](T a, T b){return max(a, b);}){}
};
template<class T>
struct SegmentTreeSum : SegmentTree<T>{
    SegmentTreeSum(ll n, const T& def_value = T()) : SegmentTree<T>(n, def_value, [](T a, T b){return a + b;}){}
    SegmentTreeSum(const vector<T>& v, const T& def_value = T()) : SegmentTree<T>(v, def_value, [](T a, T b){return a + b;}){}
};
signed main(){
    LL(n);
    VEC(ll,a,n);
    rep(n/2)a[i]-=a[n-1-i];
    a.resize(n/=2);
    vec(ll,b,n+1);
    b[0]=a[0];
    rep(n-1)b[i+1]=a[i+1]-a[i];
    b[n]=-sum(b);
    SegmentTreeMax<ll>seg(b,0);
    LL(q);
    rep(_,q){
        LL(l,r,x);
        if(r<=n){
            seg.add(l-1,x);
            seg.add(r,-x);
        }
        elif(l>n){
            l=2*n-l;
            r=2*n-r;
            seg.add(r,-x);
            seg.add(l+1,x);
        }
        else{
            seg.add(l-1,x);
            r=2*n-r;
            seg.add(r,-x);
        }
        out(!seg.data[1]);
    }
}
accuracy: 1
time_ms: 70
memory_kb: 12844
final_rank: 2

code_snippet: /*  -*- coding: utf-8 -*-
 *
 * 2777.cc: Kitsuchiri
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 500000;
const int MAX_M = MAX_N / 2; // = 250000
const int MAX_E2 = 1 << 19;  // = 524288
const int INF = 1 << 30;

/* typedef */

template <typename T, const int MAX_E2>
struct SegTreeSumMinMax {
  int n, e2, inf;
  T sums[MAX_E2], mins[MAX_E2], maxs[MAX_E2], ds[MAX_E2];
  SegTreeSumMinMax() {}

  void init(int _n, int _inf) {
    n = _n, inf = _inf;
    for (e2 = 1; e2 < n; e2 <<= 1);
    fill(sums, sums + MAX_E2, 0);
    fill(mins, mins + MAX_E2, inf);
    fill(maxs, maxs + MAX_E2, -inf);
    fill(ds, ds + MAX_E2, 0);
  }

  void set(int i, T v) { sums[e2 - 1 + i] = v; }
  
  void setall() {
    for (int i = e2 * 2 - 2; i >= e2 - 1; i--)
      mins[i] = maxs[i] = sums[i];
    for (int i = e2 - 2; i >= 0; i--) {
      int i0 = i * 2 + 1, i1 = i0 + 1;
      sums[i] = sums[i0] + sums[i1];
      mins[i] = min(mins[i0], mins[i1]);
      maxs[i] = max(maxs[i0], maxs[i1]);
    }
  }
  
  void add_range(int r0, int r1, T v, int k, int i0, int i1) {
    if (r1 <= i0 || i1 <= r0) return;
    if (r0 <= i0 && i1 <= r1) {
      sums[k] += v, mins[k] += v, maxs[k] += v, ds[k] += v;
      return;
    }

    int im = (i0 + i1) / 2, k0 = k * 2 + 1, k1 = k0 + 1;
    if (ds[k] != 0) {
      sums[k0] += ds[k], mins[k0] += ds[k], maxs[k0] += ds[k], ds[k0] += ds[k];
      sums[k1] += ds[k], mins[k1] += ds[k], maxs[k1] += ds[k], ds[k1] += ds[k];
      ds[k] = 0;
    }

    add_range(r0, r1, v, k0, i0, im);
    add_range(r0, r1, v, k1, im, i1);

    sums[k] = sums[k0] + sums[k1];
    mins[k] = min(mins[k0], mins[k1]);
    maxs[k] = max(maxs[k0], maxs[k1]);
  }
  void add_range(int r0, int r1, T v) { add_range(r0, r1, v, 0, 0, e2); }
};

/* global variables */

int as[MAX_N];
SegTreeSumMinMax<int,MAX_E2> st;

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", as + i);

  int m = n / 2;

  st.init(m, INF);
  for (int i = 0; i < m; i++) st.set(i, as[i] - as[n - 1 - i]);
  st.setall();

  int q;
  scanf("%d", &q);
  while (q--) {
    int l, r, x;
    scanf("%d%d%d", &l, &r, &x);
    l--;

    if (r <= m) st.add_range(l, r, x);
    else if (m <= l) st.add_range(n - r, n - l, -x);
    else {
      int l0 = m - l, r0 = r - m;
      if (l0 > r0) st.add_range(l, n - r, x);
      else if (l0 < r0) st.add_range(n - r, l, -x);
    }

    printf("%d\n", (st.mins[0] == 0 && st.maxs[0] == 0) ? 1 : 0);
  }
  return 0;
}
accuracy: 1
time_ms: 120
memory_kb: 13348
final_rank: 3

code_snippet: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/* [0..N-1] */
const ll INIT = 0; // 問題に合わせる
struct SegTree {
    int N;
    ll init_v;
    vector<pll> node;
    vector<ll> lazy;
    
    SegTree(int _N):init_v(INIT) {
        N = 1;
        while (N < _N) N *= 2;
        node.resize(2 * N - 1, {init_v,init_v});
        lazy.resize(2 * N - 1, init_v);
    }
    pll merge(pll a, pll b) {
        pll ret = pll(-1e9, 1e9);
        ret.first = max(a.first, b.first);
        ret.second = min(a.second, b.second);
        return ret;
    }
    void lazy_evaluate(int l, int r,int k){
        node[k].first += lazy[k];
        node[k].second += lazy[k];
        if(r - l > 1){
            lazy[2 * k + 1] += lazy[k];
            lazy[2 * k + 2] += lazy[k];
        }
        lazy[k] = 0;
    }
    
    /* [a,b) 引数の範囲に注意!! s~tまでを更新→update(s,t+1,~) */
    void update(int a, int b, ll x) { update(a, b, 0, 0, N, x); }
    void update(int a, int b, int k, int l, int r, ll x) {
        lazy_evaluate(l,r,k);
        if (r <= a || b <= l) return;
        if (a <= l && r <= b) {
            lazy[k] += x;
            lazy_evaluate(l,r,k);
        }
        else {
            update(a, b, 2 * k + 1, l, (l + r) / 2, x);
            update(a, b, 2 * k + 2, (l + r) / 2, r, x);
            node[k] = merge(node[2 * k + 1],node[2 * k + 2]);
        }
    }
    
    /* [a,b) 引数の範囲に注意!! */
    pll query(int a, int b) { return query(a, b, 0, 0, N); }
    pll query(int a, int b, int k, int l, int r) {
        lazy_evaluate(l, r, k);
        if (r <= a || b <= l) return {-INF,INF}; // min : LLONG_MAX , max : LLONG_MIN
        if (a <= l && r <= b) {
            return node[k];
        }
        else {
            pll vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
            pll vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
            return merge(vl, vr);
        }
    }
};

void solve() {
    int N; cin >> N;
    vector<ll> kassa(N); for (auto& in : kassa) cin >> in;
    int Q; cin >> Q;
    int  S = N / 2;
    SegTree ST(S);
    for (int i = 0; i < S; i++) {
        ST.update(i, i + 1, kassa[i]);
    }
    for (int i = S; i < N; i++) {
        ST.update(N - i - 1, N - i, -kassa[i]);
    }
    while (Q--) {
        int l, r, x; cin >> l >> r >> x;
        l--; r--;
        if (r < S) {
            ST.update(l, r + 1, x);
        }
        else if (l >= S) {
            ST.update(N - r - 1, N - l, -x);
        }
        else {
            ST.update(l, S, x);
            ST.update(N - r - 1, S, -x);
        }
        pll a = ST.query(0, S);
        if (a.first == a.second && a.first == 0) {
            cout << 1 << endl;
        } else {
            cout << 0 << endl;
        }
    }
}

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve();
    return 0;
}
accuracy: 1
time_ms: 320
memory_kb: 18948
final_rank: 11

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int *min_data,*max_data,*add_data;
int first_table[500000];
int N = 1;

void init(ll first_N){
	while(N < first_N)N *= 2;
}

void add(int left,int right,int value,int node_id,int node_left,int node_right){

	if(right < node_left || left > node_right){
		return;
	}
	else if(left <= node_left && right >= node_right){

		add_data[node_id] += value;

		while(node_id != 0){

			node_id = (node_id-1)/2;
			min_data[node_id] = min(min_data[2*node_id+1]+add_data[2*node_id+1],min_data[2*node_id+2]+add_data[2*node_id+2]);
			max_data[node_id] = max(max_data[2*node_id+1]+add_data[2*node_id+1],max_data[2*node_id+2]+add_data[2*node_id+2]);
		}
	}else{

		add(left,right,value,2*node_id+1,node_left,(node_left+node_right)/2);
		add(left,right,value,2*node_id+2,(node_left+node_right)/2+1,node_right);
	}
}

int getMin(int left,int right,int node_id,int node_left,int node_right){
	if(right < node_left || left > node_right)return BIG_NUM;
	else if(left <= node_left && right >= node_right){
		return min_data[node_id]+add_data[node_id];

	}else{

		int  left_min  = getMin(left,right,2*node_id+1,node_left,(node_left+node_right)/2);
		int  right_min = getMin(left,right,2*node_id+2,(node_left+node_right)/2+1,node_right);
		return min(left_min,right_min)+add_data[node_id];
	}
}

int getMax(int left,int right,int node_id,int node_left,int node_right){
	if(right < node_left || left > node_right)return -BIG_NUM;
	else if(left <= node_left && right >= node_right){
		return max_data[node_id]+add_data[node_id];

	}else{

		int  left_max  = getMax(left,right,2*node_id+1,node_left,(node_left+node_right)/2);
		int right_max = getMax(left,right,2*node_id+2,(node_left+node_right)/2+1,node_right);
		return max(left_max,right_max)+add_data[node_id];
	}
}

int main(){

	int first_N;
	scanf("%d",&first_N);

	for(int i = 0; i < first_N; i++)scanf("%lld",&first_table[i]);

	for(int i = 0; i < first_N/2; i++){
		first_table[i] -= first_table[(first_N-1)-i];
	}

	first_N /= 2;
	init(first_N);

	min_data = new int[2*N-1];
	max_data = new int[2*N-1];
	add_data = new int[2*N-1];

	for(ll i = 0; i <= 2*N-2; i++){
		min_data[i] = 0;
		max_data[i] = 0;
		add_data[i] = 0;
	}

	for(int i = 0; i < first_N; i++){
		add(i,i,first_table[i],0,0,N-1);
	}

	int Q;
	scanf("%d",&Q);

	int left,right,tmp,calc_left;
	int add_value;

	for(int i = 0; i < Q; i++){
		scanf("%d %d %d",&left,&right,&add_value);
		left--;
		right--;

		if(left >= first_N){

			tmp = right;
			right = (2*first_N-1)-left;
			left = (2*first_N-1)-tmp;

			add(left,right,-add_value,0,0,N-1);

		}else{ // left < first_N

			if(right < first_N){
				add(left,right,add_value,0,0,N-1);

			}else{ //right > first_N

				if(left+right == 2*first_N-1){
					//Do nothing
				}else{

					calc_left = (2*first_N-1)-right;

					if(calc_left < left){

						right = left-1;
						left = calc_left;
						add(left,right,-add_value,0,0,N-1);

					}else{

						right = calc_left-1;
						add(left,right,add_value,0,0,N-1);
					}
				}
			}
		}

		if(getMin(0,first_N-1,0,0,N-1) == 0 && getMax(0,first_N-1,0,0,N-1) == 0){
			printf("1\n");
		}else{
			printf("0\n");
		}
	}

	return 0;
}
accuracy: 1
time_ms: 180
memory_kb: 11252
final_rank: 4

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


ll *min_data,*max_data,*add_data;
ll first_table[500000];
int N = 1;

void init(ll first_N){
	while(N < first_N)N *= 2;
}

void add(int left,int right,ll value,int node_id,int node_left,int node_right){

	if(right < node_left || left > node_right){
		return;
	}
	else if(left <= node_left && right >= node_right){

		add_data[node_id] += value;

		while(node_id != 0){

			node_id = (node_id-1)/2;
			min_data[node_id] = min(min_data[2*node_id+1]+add_data[2*node_id+1],min_data[2*node_id+2]+add_data[2*node_id+2]);
			max_data[node_id] = max(max_data[2*node_id+1]+add_data[2*node_id+1],max_data[2*node_id+2]+add_data[2*node_id+2]);
		}
	}else{

		add(left,right,value,2*node_id+1,node_left,(node_left+node_right)/2);
		add(left,right,value,2*node_id+2,(node_left+node_right)/2+1,node_right);
	}
}

ll getMin(int left,int right,int node_id,int node_left,int node_right){
	if(right < node_left || left > node_right)return BIG_NUM;
	else if(left <= node_left && right >= node_right){
		return min_data[node_id]+add_data[node_id];

	}else{

		ll  left_min  = getMin(left,right,2*node_id+1,node_left,(node_left+node_right)/2);
		ll  right_min = getMin(left,right,2*node_id+2,(node_left+node_right)/2+1,node_right);
		return min(left_min,right_min)+add_data[node_id];
	}
}

ll getMax(int left,int right,int node_id,int node_left,int node_right){
	if(right < node_left || left > node_right)return -BIG_NUM;
	else if(left <= node_left && right >= node_right){
		return max_data[node_id]+add_data[node_id];

	}else{

		ll  left_max  = getMax(left,right,2*node_id+1,node_left,(node_left+node_right)/2);
		ll  right_max = getMax(left,right,2*node_id+2,(node_left+node_right)/2+1,node_right);
		return max(left_max,right_max)+add_data[node_id];
	}
}

int main(){

	int first_N;
	scanf("%d",&first_N);

	for(int i = 0; i < first_N; i++)scanf("%lld",&first_table[i]);

	for(int i = 0; i < first_N/2; i++){
		first_table[i] -= first_table[(first_N-1)-i];
	}

	first_N /= 2;
	init(first_N);

	min_data = new ll[2*N-1];
	max_data = new ll[2*N-1];
	add_data = new ll[2*N-1];

	for(ll i = 0; i <= 2*N-2; i++){
		min_data[i] = 0;
		max_data[i] = 0;
		add_data[i] = 0;
	}

	for(int i = 0; i < first_N; i++){
		add(i,i,first_table[i],0,0,N-1);
	}

	int Q;
	scanf("%d",&Q);

	int left,right,tmp,calc_left,pre = -1;
	ll add_value;

	for(int i = 0; i < Q; i++){
		scanf("%d %d %lld",&left,&right,&add_value);
		left--;
		right--;

		if(left >= first_N){

			tmp = right;
			right = (2*first_N-1)-left;
			left = (2*first_N-1)-tmp;

			add(left,right,-add_value,0,0,N-1);

			if(pre == 1){
				printf("0\n");
				pre = 0;
				continue;
			}

		}else{ // left < first_N

			if(right < first_N){
				add(left,right,add_value,0,0,N-1);

				if(pre == 1){
					printf("0\n");
					pre = 0;
					continue;
				}

			}else{

				if(left+right == 2*first_N-1){
					if(pre != -1){
						printf("%d\n",pre);
						continue;
					}
				}else{

					calc_left = (2*first_N-1)-right;

					if(calc_left < left){

						right = left-1;
						left = calc_left;
						add(left,right,-add_value,0,0,N-1);

						if(pre == 1){
							printf("0\n");
							pre = 0;
							continue;
						}

					}else{

						right = calc_left-1;
						add(left,right,add_value,0,0,N-1);

						if(pre == 1){
							printf("0\n");
							pre = 0;
							continue;
						}
					}
				}
			}
		}

		if(getMin(0,first_N-1,0,0,N-1) == 0 && getMax(0,first_N-1,0,0,N-1) == 0){
			printf("1\n");
			pre = 1;
		}else{
			printf("0\n");
			pre = 0;
		}
	}

	return 0;
}
accuracy: 0.6753246753246753
time_ms: 190
memory_kb: 19352
final_rank: 19

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


ll *min_data,*max_data,*add_data;
ll first_table[500000];
int N = 1;

void init(ll first_N){
	while(N < first_N)N *= 2;
}

void add(int left,int right,ll value,int node_id,int node_left,int node_right){

	if(right < node_left || left > node_right){
		return;
	}
	else if(left <= node_left && right >= node_right){

		add_data[node_id] += value;

		while(node_id != 0){

			node_id = (node_id-1)/2;
			min_data[node_id] = min(min_data[2*node_id+1]+add_data[2*node_id+1],min_data[2*node_id+2]+add_data[2*node_id+2]);
			max_data[node_id] = max(max_data[2*node_id+1]+add_data[2*node_id+1],max_data[2*node_id+2]+add_data[2*node_id+2]);
		}
	}else{

		add(left,right,value,2*node_id+1,node_left,(node_left+node_right)/2);
		add(left,right,value,2*node_id+2,(node_left+node_right)/2+1,node_right);
	}
}

ll getMin(int left,int right,int node_id,int node_left,int node_right){
	if(right < node_left || left > node_right)return BIG_NUM;
	else if(left <= node_left && right >= node_right){
		return min_data[node_id]+add_data[node_id];

	}else{

		ll  left_min  = getMin(left,right,2*node_id+1,node_left,(node_left+node_right)/2);
		ll  right_min = getMin(left,right,2*node_id+2,(node_left+node_right)/2+1,node_right);
		return min(left_min,right_min)+add_data[node_id];
	}
}

ll getMax(int left,int right,int node_id,int node_left,int node_right){
	if(right < node_left || left > node_right)return -BIG_NUM;
	else if(left <= node_left && right >= node_right){
		return max_data[node_id]+add_data[node_id];

	}else{

		ll  left_max  = getMax(left,right,2*node_id+1,node_left,(node_left+node_right)/2);
		ll  right_max = getMax(left,right,2*node_id+2,(node_left+node_right)/2+1,node_right);
		return max(left_max,right_max)+add_data[node_id];
	}
}

int main(){

	int first_N;
	scanf("%d",&first_N);

	for(int i = 0; i < first_N; i++)scanf("%lld",&first_table[i]);

	for(int i = 0; i < first_N/2; i++){
		first_table[i] -= first_table[(first_N-1)-i];
	}

	first_N /= 2;
	init(first_N);

	min_data = new ll[2*N-1];
	max_data = new ll[2*N-1];
	add_data = new ll[2*N-1];

	for(ll i = 0; i <= 2*N-2; i++){
		min_data[i] = 0;
		max_data[i] = 0;
		add_data[i] = 0;
	}

	for(int i = 0; i < first_N; i++){
		add(i,i,first_table[i],0,0,N-1);
	}

	int Q;
	scanf("%d",&Q);

	int left,right,tmp,calc_left;
	ll add_value;

	for(int i = 0; i < Q; i++){
		scanf("%d %d %lld",&left,&right,&add_value);
		left--;
		right--;

		if(left >= first_N){

			tmp = right;
			right = (2*first_N-1)-left;
			left = (2*first_N-1)-tmp;

			add(left,right,-add_value,0,0,N-1);

		}else{ // left < first_N

			if(right < first_N){
				add(left,right,add_value,0,0,N-1);

			}else{ //right > first_N

				if(left+right == 2*first_N-1){
					//Do nothing
				}else{

					calc_left = (2*first_N-1)-right;

					if(calc_left < left){

						right = left-1;
						left = calc_left;
						add(left,right,-add_value,0,0,N-1);

					}else{

						right = calc_left-1;
						add(left,right,add_value,0,0,N-1);
					}
				}
			}
		}

		if(getMin(0,first_N-1,0,0,N-1) == 0 && getMax(0,first_N-1,0,0,N-1) == 0){
			printf("1\n");
		}else{
			printf("0\n");
		}
	}

	return 0;
}
accuracy: 1
time_ms: 190
memory_kb: 19364
final_rank: 6

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


ll *min_data,*max_data,*add_data;
ll first_table[500000];
int N = 1;

void init(ll first_N){
	while(N < first_N)N *= 2;
}

void add(int left,int right,ll value,int node_id,int node_left,int node_right){

	if(right < node_left || left > node_right){
		return;
	}
	else if(left <= node_left && right >= node_right){

		add_data[node_id] += value;

		while(node_id != 0){

			node_id = (node_id-1)/2;
			min_data[node_id] = min(min_data[2*node_id+1]+add_data[2*node_id+1],min_data[2*node_id+2]+add_data[2*node_id+2]);
			max_data[node_id] = max(max_data[2*node_id+1]+add_data[2*node_id+1],max_data[2*node_id+2]+add_data[2*node_id+2]);
		}
	}else{

		add(left,right,value,2*node_id+1,node_left,(node_left+node_right)/2);
		add(left,right,value,2*node_id+2,(node_left+node_right)/2+1,node_right);
	}
}

ll getMin(int left,int right,int node_id,int node_left,int node_right){
	if(right < node_left || left > node_right)return BIG_NUM;
	else if(left <= node_left && right >= node_right){
		return min_data[node_id]+add_data[node_id];

	}else{

		ll  left_min  = getMin(left,right,2*node_id+1,node_left,(node_left+node_right)/2);
		ll  right_min = getMin(left,right,2*node_id+2,(node_left+node_right)/2+1,node_right);
		return min(left_min,right_min)+add_data[node_id];
	}
}

ll getMax(int left,int right,int node_id,int node_left,int node_right){
	if(right < node_left || left > node_right)return -BIG_NUM;
	else if(left <= node_left && right >= node_right){
		return max_data[node_id]+add_data[node_id];

	}else{

		ll  left_max  = getMax(left,right,2*node_id+1,node_left,(node_left+node_right)/2);
		ll  right_max = getMax(left,right,2*node_id+2,(node_left+node_right)/2+1,node_right);
		return max(left_max,right_max)+add_data[node_id];
	}
}

int main(){

	int first_N;
	scanf("%d",&first_N);

	for(int i = 0; i < first_N; i++)scanf("%lld",&first_table[i]);

	for(int i = 0; i < first_N/2; i++){
		first_table[i] -= first_table[(first_N-1)-i];
	}

	first_N /= 2;
	init(first_N);

	min_data = new ll[2*N-1];
	max_data = new ll[2*N-1];
	add_data = new ll[2*N-1];

	for(ll i = 0; i <= 2*N-2; i++){
		min_data[i] = 0;
		max_data[i] = 0;
		add_data[i] = 0;
	}

	for(int i = 0; i < first_N; i++){
		add(i,i,first_table[i],0,0,N-1);
	}

	int Q;
	scanf("%d",&Q);

	int left,right,tmp,calc_left,pre = -1;
	ll add_value;

	for(int i = 0; i < Q; i++){
		scanf("%d %d %lld",&left,&right,&add_value);
		left--;
		right--;

		if(left >= first_N){

			tmp = right;
			right = (2*first_N-1)-left;
			left = (2*first_N-1)-tmp;

			add(left,right,-add_value,0,0,N-1);

			if(pre == 1){
				printf("0\n");
				pre = 0;
				continue;
			}

		}else{ // left < first_N

			if(right < first_N){
				add(left,right,add_value,0,0,N-1);

				if(pre == 1){
					printf("0\n");
					pre = 0;
					continue;
				}

			}else{ //right > first_N

				if(left+right == 2*first_N-1){
					printf("%d\n",pre);
					continue;
				}else{

					calc_left = (2*first_N-1)-right;

					if(calc_left < left){

						right = left-1;
						left = calc_left;
						add(left,right,-add_value,0,0,N-1);

						if(pre == 1){
							printf("0\n");
							pre = 0;
							continue;
						}

					}else{

						right = calc_left-1;
						add(left,right,add_value,0,0,N-1);

						if(pre == 1){
							printf("0\n");
							pre = 0;
							continue;
						}
					}
				}
			}
		}

		if(getMin(0,first_N-1,0,0,N-1) == 0 && getMax(0,first_N-1,0,0,N-1) == 0){
			printf("1\n");
			pre = 1;
		}else{
			printf("0\n");
			pre = 0;
		}
	}

	return 0;
}
accuracy: 0.6753246753246753
time_ms: 190
memory_kb: 19388
final_rank: 20