Problem:
断層(Geologic Fault)
遠い昔，IOI 文明という高度な文明が栄えていた．しかし，火山の噴火により，この高度な文明はついに滅んでしまった．IOI 文明は直線状の河川に沿って繁栄しており，IOI 文明が滅んだとき，その地表面は平らであった．IOI 文明の跡地は座標平面のx 軸と見なすことができる．y 軸は高さ方向を表す．すなわち，座標平面において，直線 $y = 0$ は地表を，領域 $y > 0$ は地上を，領域 $y < 0$ は地下を表す．また，IOI 文明が滅んだとき，$a$ 年前$(a \geq 0)$ の地層は，直線 $y = -a$ の位置にあった．
IOI 文明が滅んだ後，IOI 文明の跡地では $Q$ 回の地殻変動が起きた．$i$ 回目$(1 \leq i \leq Q)$ の地殻変動は，位置 $X_i$，方向 $D_i$，変動の量 $L_i$ で表される．$D_i$ は 1 または 2 である．$i$ 回目の地殻変動は以下のように起きる．
地層の移動が次のように起きる．
$D_i = 1$ のとき，断層が点$(X_i, 0)$ を通る傾き $1$ の直線に沿って造られ，この直線より上の領域にある地層が，直線に沿って高さ $L_i$ だけ移動する．すなわち，この直線より上の点 $(x, y)$ は，点$(x + L_i, y + L_i)$ に移動する．
$D_i = 2$ のとき，断層が点$(X_i, 0)$ を通る傾き $-1$ の直線に沿って造られ，この直線より上の領域にある地層が，直線に沿って高さ $L_i$ だけ移動する．すなわち，この直線より上の点$(x, y)$ は，点$(x - L_i, y + L_i)$ に移動する．
そのすぐ後に，領域 $y > 0$ の地層が風化によってすべて消える．
時は変わり現代，考古学者のJOI 博士はIOI 文明の遺跡を発掘することにした．JOI 博士はどの位置の地表の地層が，IOI 文明が滅ぶ何年前の地層であるかを知りたい．どのような地殻変動が起きたかは分かっている．あなたの仕事は，JOI 博士にかわって，$1 \leq i \leq N$ を満たす各整数 $i$ について，点$(i-1, 0)$ と点$(i, 0)$の間の地表の地層がIOI 文明が滅ぶ何年前の地層であるかを求めることである．
課題
IOI 文明の跡地に起きたの情報が与えられたとき，すべての整数 $i$ $(1 \leq i \leq N)$ に対し，点$(i - 1, 0)$ と点$(i, 0)$ の間の地表の地層がIOI 文明が滅ぶ何年前の地層であるかを出力せよ．
入力
標準入力から以下の入力を読み込め．
1 行目には， 2 個の整数 $N, Q$ が空白を区切りとして書かれている．これは，答えを求める地点の数が $N$，地殻変動の回数が $Q$ であることを表す．
続く $Q$ 行のうちの $i$ 行目$(1 \leq i \leq Q)$ には，3 個の整数 $X_i, D_i, L_i$ が空白を区切りとして書かれている．これは，$i$ 回目の地殻変動の位置が $X_i$，方向が $D_i$，変動の量が $L_i$ であることを表す．
出力
出力は $N$ 行からなる．標準出力の $i$ 行目$(1 \leq i \leq N)$ には，点$(i - 1, 0)$ と点$(i, 0)$ の間の地表の地層がIOI文明が滅ぶ何年前の地層であるかを表す整数を出力せよ．
制限
すべての入力データは以下の条件を満たす．
$1 \leq N \leq 200 000$
$1 \leq Q \leq 200 000$
$ -1 000 000 000 \leq X_i \leq 1 000 000 000$ $(1 \leq i \leq Q)$
$1 \leq D_i \leq 2$ $(1 \leq i \leq Q)$
$1 \leq L_i \leq 1 000 000 000$ $(1 \leq i \leq Q)$
入出力例
入力例1
10 2
12 1 3
2 2 2
出力例1
3
3
5
5
5
5
5
5
2
2
この入力例は，以下の図に対応する．
入力例2
10 6
14 1 1
17 1 1
-6 2 1
3 2 1
4 1 1
0 2 1
出力例2
5
5
4
5
5
5
5
5
4
4
入力例3
15 10
28 1 7
-24 2 1
1 1 1
8 1 1
6 2 1
20 1 3
12 2 2
-10 1 3
7 2 1
5 1 2
出力例3
15
14
14
14
14
12
12
12
12
12
12
12
15
15
12
第15回 日本情報オリンピック本選 課題   2016 年 2 月 14 日

Submitted solutions:

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

// Binary Indexed Treeの構造体
struct BinaryIndexedTree {
    vector<int64> data;
    int curr;

    BinaryIndexedTree(int sz) {
        data.assign(++sz, 0);  // データ配列を0で初期化
        curr = 1;
        while (curr < data.size()) curr <<= 1;
        for (int i = 0; i < data.size(); i++) data[i] = i & -i;
    }

    // 1からkまでの和を計算
    inline int64 sum(int k) {
        int64 ret = 0;
        for (++k; k > 0; k -= k & -k) ret += data[k];
        return ret;
    }

    // w以下の最大のインデックスを探す
    inline int upper_bound(int64 w) {
        int i = 0;
        for (int k = curr; k > 0; k >>= 1) {
            if (i + k < data.size() && data[i + k] <= w) {
                w -= data[i + k];
                i += k;
            }
        }
        return i;
    }

    // k番目の要素にxを加算
    inline void add(int k, int64 x) {
        for (++k; k < data.size(); k += k & -k) data[k] += x;
    }
};

int N, Q;
int X[200000], D[200000], L[200000];

int main() {
    // 入力の読み込み
    scanf("%d %d", &N, &Q);
    for (int i = 0; i < Q; i++) {
        scanf("%d %d %d", &X[i], &D[i], &L[i]);
    }

    // Binary Indexed Treeを2つ使用
    BinaryIndexedTree xpy(N), xmy(N);

    // クエリを逆順に処理
    for (int i = Q - 1; i >= 0; i--) {
        if (D[i] == 1) {
            xmy.add(0, -L[i] * 2);
            xmy.add(xpy.upper_bound(X[i]), L[i] * 2);
        } else {
            xpy.add(xmy.upper_bound(X[i]), L[i] * 2);
        }
    }

    // 結果の出力
    for (int i = 0; i < N; i++) {
        printf("%lld\n", (xpy.sum(i) - xmy.sum(i)) / 2);
    }

    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 8684
final_rank: 4

code_snippet: #include<bits/stdc++.h>
#define int long long
#define ls(x) ((x)<<1)
#define rs(x) ((x)<<1|1)
using namespace std;
int const N=2333333,INF=0x3f3f3f3f3f3f3f3fll;
int n,q,x[N],d[N],l[N],val[N][2],lt[N][2],ans[N][2];
inline void update(int x,int op){
	val[x][op]=min(val[ls(x)][op],val[rs(x)][op]);
}
inline void download(int x,int op){
	if(!lt[x][op])return;
	int t=lt[x][op];lt[x][op]=0;
	val[ls(x)][op]+=t,val[rs(x)][op]+=t;
	lt[ls(x)][op]+=t,lt[rs(x)][op]+=t;
}
inline void build(int x,int l,int r){
	if(l==r){
		val[x][0]=val[x][1]=l;return;
	}
	int mid=(l+r)>>1;
	build(ls(x),l,mid);
	build(rs(x),mid+1,r);
	update(x,0),update(x,1);
}
inline void modify(int x,int l,int r,int ql,int qr,int k,int op){
	if(ql<=l&&r<=qr){
		val[x][op]+=k,lt[x][op]+=k;return;
	}
	download(x,op);
	int mid=(l+r)>>1;
	if(ql<=mid)
		modify(ls(x),l,mid,ql,qr,k,op);
	if(qr>mid)
		modify(rs(x),mid+1,r,ql,qr,k,op);
	update(x,op);
}
inline void queryx(int x,int l,int r,int k,int&res){
	if(l==r){
		if(val[x][0]<=k)res=max(res,l);
		return;
	}
	download(x,0);
	int mid=(l+r)>>1;
	if(val[rs(x)][0]>k)
		queryx(ls(x),l,mid,k,res);
	else
		queryx(rs(x),mid+1,r,k,res);
}
inline void queryy(int x,int l,int r,int k,int&res){
	if(l==r){
		if(val[x][1]>k)res=min(res,l);
		return;
	}
	download(x,1);
	int mid=(l+r)>>1;
	if(val[rs(x)][1]>k){
		res=min(res,mid+1);
		queryy(ls(x),l,mid,k,res);
	}else
		queryy(rs(x),mid+1,r,k,res);
}
inline void dfs(int x,int l,int r){
	if(l==r){
		ans[l][0]=val[x][0],ans[l][1]=val[x][1];
		return;
	}
	download(x,0),download(x,1);
	int mid=(l+r)>>1;
	dfs(ls(x),l,mid),dfs(rs(x),mid+1,r);
}
signed main(){
	ios::sync_with_stdio(0);
	cin>>n>>q;
	build(1,1,n);
	for(int i=1;i<=q;i++)
		cin>>x[i]>>d[i]>>l[i];
	for(int i=q;i>=1;i--){
		if(d[i]==1){
			int p=-INF;
			queryx(1,1,n,x[i],p);
			if(p!=-INF)
				modify(1,1,n,1,p,-2*l[i],1);
		}else{
			int p=INF;
			queryy(1,1,n,x[i],p);
			if(p!=INF)
				modify(1,1,n,p,n,2*l[i],0);
		}
	}
	dfs(1,1,n);
	for(int i=1;i<=n;i++)
		cout<<(ans[i][0]-ans[i][1]>>1)<<"\n";
}
//42231892
accuracy: 1
time_ms: 70
memory_kb: 38256
final_rank: 16

code_snippet: #include <bits/stdc++.h>
using namespace std;
using lint = long long;
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define rep2(i, l, n) for(int i = int(l); i < int(n); i++)
#define repr(i, n) for(int i = int(n) - 1; i >= 0; i--)
#define repr2(i, l, n) for(int i = int(n) - 1; i >= int(l); i--)

template<class T>
struct DualSegmentTree{
    using F = function<T(T, T)>;
    
    int sz, height;
    vector<T> data;
    vector<bool> is_data;
    
    F f;
    T id;
    
    DualSegmentTree() = default;
    DualSegmentTree(int n, F f): f(f) {
        sz = 1;
        height = 0;
        while(sz < n) sz *= 2, height++;
        data.resize(sz * 2, id);
        is_data.resize(sz * 2, false);
    }
    
    void set(int k, T x){
        k += sz;
        data[k] = x;
        is_data[k] = true;
    }
    
    void eval(int at){
        if(is_data[at]){
            data[at * 2] = is_data[at * 2] ? f(data[at * 2], data[at]) : data[at];
            data[at * 2 + 1] = is_data[at * 2 + 1] ? f(data[at * 2 + 1], data[at]) : data[at];
            is_data[at * 2] = true;
            is_data[at * 2 + 1] = true;
            
            is_data[at] = false;
        }
    }
    
    void update(int a, int b, T x, int l, int r, int at){
        if(r <= a || b <= l) return;
        if(a <= l && r <= b){
            data[at] = (is_data[at] ? f(data[at], x) : x);
            is_data[at] = true;
            return;
        }
        
        eval(at);
        int mid = (l + r) / 2;
        update(a, b, x, l, mid, at * 2);
        update(a, b, x, mid, r, at * 2 + 1);
    }
    
    void update(int a, int b, T x){
        update(a, b, x, 0, sz, 1);
    }
    
    T operator [](int k){
        k += sz;
        repr(i, height){
            eval(k >> (i + 1));
        }
        return data[k];
    }
};

int main(){
    int n, q;
    cin >> n >> q;
    auto f = [](lint a, lint b){ return a + b; };
    DualSegmentTree<lint> x_seg(n, f), y_seg(n, f);
    rep(i, n){
        x_seg.set(i, i);
        y_seg.set(i, -i);
    }
    
    lint X[q], L[q];
    int D[q];
    rep(i, q) cin >> X[i] >> D[i] >> L[i];
    
    repr(c, q){
        lint pos = X[c], l = L[c];
        int d = D[c];
        if(d == 1){
            int ok = -1, ng = n + 1;
            while(abs(ok - ng) > 1){
                int mid = (ok + ng) / 2;
                
                if(x_seg[mid] < pos) ok = mid;
                else ng = mid;
            }
            
//            cout << 0 << " " << ok << endl;
            y_seg.update(0, ok + 1, l * 2);
        }else{
            int ng = -1, ok = n + 1;
            while(abs(ok - ng) > 1){
                int mid = (ok + ng) / 2;
                
                if(y_seg[mid] <= -pos) ok = mid;
                else ng = mid;
            }
            
//            cout << ok << " " << n << endl;
            x_seg.update(ok, n, l * 2);
        }
        
    }
    
    rep(i, n){
        cout << (x_seg[i] + y_seg[i]) / 2 << endl;
    }
}
accuracy: 1
time_ms: 470
memory_kb: 15328
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;
using lint = long long;
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define rep2(i, l, n) for(int i = int(l); i < int(n); i++)
#define repr(i, n) for(int i = int(n) - 1; i >= 0; i--)
#define repr2(i, l, n) for(int i = int(n) - 1; i >= int(l); i--)

const lint inf = 1e18;

struct segtree{
    int sz;
    vector<lint> data;
    
    segtree(int n){
        sz = 1;
        while(sz < n) sz *= 2;
        
        data.resize(sz * 2, 0);
    }
    
    void update(int a, int b, lint x, int l, int r, int at){
        if(r <= a || b <= l) return;
        if(a <= l && r <= b){
            data[at] += x;
            return;
        }
        
        int mid = (l + r) / 2;
        update(a, b, x, l, mid, at * 2);
        update(a, b, x, mid, r, at * 2 + 1);
    }
    
    void update(int a, int b, lint x){
        update(a, b, x, 0, sz, 1);
    }
    
    lint operator [](int k){
        k += sz;
        lint ans = 0;
        while(k >= 1){
            ans += data[k];
            k /= 2;
        }
        
        return ans;
    }
};

int main(){
    int n, q;
    cin >> n >> q;
    segtree x_seg(n), y_seg(n);
    rep(i, n){
        x_seg.update(i, i + 1, i);
        y_seg.update(i, i + 1, -i);
    }
    
    lint X[q], L[q];
    int D[q];
    rep(i, q) cin >> X[i] >> D[i] >> L[i];
    
    repr(c, q){
        lint pos = X[c], l = L[c];
        int d = D[c];
        if(d == 1){
            int ok = -1, ng = n + 1;
            while(abs(ok - ng) > 1){
                int mid = (ok + ng) / 2;
                
                if(x_seg[mid] < pos) ok = mid;
                else ng = mid;
            }
            
//            cout << 0 << " " << ok << endl;
            y_seg.update(0, ok + 1, l * 2);
        }else{
            int ng = -1, ok = n + 1;
            while(abs(ok - ng) > 1){
                int mid = (ok + ng) / 2;
                
                if(y_seg[mid] <= -pos) ok = mid;
                else ng = mid;
            }
            
//            cout << ok << " " << n << endl;
            x_seg.update(ok, n, l * 2);
        }
        
    }
    
    rep(i, n){
        cout << (x_seg[i] + y_seg[i]) / 2 << endl;
    }
}
accuracy: 1
time_ms: 310
memory_kb: 15316
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;
using lint = long long;
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define rep2(i, l, n) for(int i = int(l); i < int(n); i++)
#define repr(i, n) for(int i = int(n) - 1; i >= 0; i--)
#define repr2(i, l, n) for(int i = int(n) - 1; i >= int(l); i--)

const lint inf = 1e18;

struct segtree{
    int sz;
    vector<lint> data, lazy;
    
    segtree(int n){
        sz = 1;
        while(sz < n) sz *= 2;
        
        data.resize(sz * 2, 0);
        lazy.resize(sz * 2, 0);
    }
    
    void eval(int l, int r, int at){
        data[at] += lazy[at];
        if(r - l > 1){
            lazy[at * 2] += lazy[at];
            lazy[at * 2 + 1] += lazy[at];
        }
        lazy[at] = 0;
    }
    
    void update(int a, int b, lint x, int l, int r, int at){
        if(r <= a || b <= l) return;
        if(a <= l && r <= b){
            lazy[at] += x;
            return;
        }
        eval(l, r, at);
        int mid = (l + r) / 2;
        update(a, b, x, l, mid, at * 2);
        update(a, b, x, mid, r, at * 2 + 1);
        data[at] = data[at * 2] + data[at * 2 + 1];
    }
    
    void update(int a, int b, lint x){
        update(a, b, x, 0, sz, 1);
    }
    
    lint query(int a, int b, int l, int r, int at){
        if(r <= a || b <= l) return 0;
        if(a <= l && r <= b){
            eval(l, r, at);
            return data[at];
        }
        eval(l, r, at);
        int mid = (l + r) / 2;
        return query(a, b, l, mid, at * 2) + query(a, b, mid, r, at * 2 + 1);
    }
    
    lint query(int a, int b){
        return query(a, b, 0, sz, 1);
    }
    
    lint operator [](int k){
        return query(k, k + 1);
    }
};

int main(){
    int n, q;
    cin >> n >> q;
    segtree x_seg(n), y_seg(n);
    rep(i, n){
        x_seg.update(i, i + 1, i);
        y_seg.update(i, i + 1, -i);
    }
    
    lint X[q], L[q];
    int D[q];
    rep(i, q) cin >> X[i] >> D[i] >> L[i];
    
    repr(c, q){
        lint pos = X[c], l = L[c];
        int d = D[c];
        if(d == 1){
            int ok = -1, ng = n + 1;
            while(abs(ok - ng) > 1){
                int mid = (ok + ng) / 2;
                
                if(x_seg[mid] < pos) ok = mid;
                else ng = mid;
            }
            
//            cout << 0 << " " << ok << endl;
            y_seg.update(0, ok + 1, l * 2);
        }else{
            int ng = -1, ok = n + 1;
            while(abs(ok - ng) > 1){
                int mid = (ok + ng) / 2;
                
                if(y_seg[mid] <= -pos) ok = mid;
                else ng = mid;
            }
            
//            cout << ok << " " << n << endl;
            x_seg.update(ok, n, l * 2);
        }
        
    }
    
    rep(i, n){
        cout << (x_seg[i] + y_seg[i]) / 2 << endl;
    }
}
accuracy: 1
time_ms: 690
memory_kb: 23452
final_rank: 18

code_snippet: #pragma GCC optimize ("Ofast")
#pragma GCC target ("avx")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<complex>
#include<time.h>
#include<cassert>
#include<functional>
#include<numeric>
#include<tuple>

using namespace std;
using ll = long long;
using ld = long double;
#define int long long
#define all(a) (a).begin(),(a).end()
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define H pair<int, int>
#define P pair<int, pair<int, int>>
#define Q(i,j,k) mkp(i,mkp(j,k))
#define R pair<pair<int, int>, pair<int, int>>
#define S(i,j,k,l) mkp(mkp(i,j),mkp(k,l))
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define rng(i,s,n) for(int (i) = (s) ; (i) < (n) ; (i)++)
#define req(n,i) for(int (i) = (n) - 1 ; (i) >= 0 ; (i)--)
#define range(i,v) for(auto& (i) : v)
#define mkp make_pair
#define mem(x,k) memset(x,k,sizeof(x))
#define vec vector
#define pb emplace_back
#define lb lower_bound
#define ub upper_bound
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
#define getidx(b,i) lower_bound(all(b),(i))-b.begin()
#define ssp(i,n) (i==n-1?"\n":" ")
#define ctoi(c) (int)(c-'0')
#define itoc(c) (char)(c+'0')
#define itn int
#define pri_que priority_queue
#define pp(x,y) pb(H{x,y})
#define ppp(x,y,z) pb(Q(x,y,z))
#define pppp(x,y,z,w) pb(S(x,y,z,w))
#define cyes cout<<"Yes\n"
#define cno cout<<"No\n"
#define endl "\n"
constexpr int mod = 1e9 + 7;
constexpr int Mod = 998244353;
constexpr int MXN = 500000 + 100;
constexpr ll inf = 3 * 1e18;
constexpr int Inf = 15 * 1e8;
const vec<int>dx{ -1,1,0,0 }, dy{ 0,0,-1,1 };
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; }
ll read() { ll u, k = scanf("%lld", &u); return u; }
string reads() { string s; cin >> s; return s; }
H readh(bool g = 0) { H u; ll k = scanf("%lld %lld", &u.fs, &u.sc); if (g) u.fs--, u.sc--; return u; }
void printh(H t) { printf("%lld %lld\n", t.fs, t.sc); }
bool inarea(H t, int h, int w) { return 0 <= t.fs && t.fs < h && 0 <= t.sc && t.sc < w; }
ll gcd(ll i, ll j) { return j ? gcd(j, i % j) : i; }
ll mod_pow(ll x, ll n, ll p = mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
ll bitcount(ll x) {
	int sum = 0; for (int i = 0; i < 60; i++)if ((1ll << i) & x) sum++;
	return sum;
}
/*constexpr int fn_ = 1000005;
ll fact_[fn_], comp_[fn_];
ll comb(ll x, ll y, ll Mod = mod) {
	if (!fact_[0]) {
		fact_[0] = 1; comp_[0] = 1;
		for (int i = 1; i < fn_; i++)
			fact_[i] = fact_[i - 1] * i % Mod;
		comp_[fn_ - 1] = mod_pow(fact_[fn_ - 1], Mod - 2, Mod);
		for (int i = fn_ - 2; i > 0; i--)
			comp_[i] = comp_[i + 1] * (i + 1) % Mod;
	}
	if (x < y) return 0;
	return fact_[x] * comp_[x - y] % Mod * comp_[y] % Mod;
}*/
//--------------------------------------------------------------
class BIT {
	int size;
	int dat[500000];
public:
	BIT() {}
	void init(int n) {
		size = n;
		for (int i = 1; i <= n; i++) dat[i] = 0;
	}
	void add(int i, int x = 1) {
		i++;
		while (i <= size) {
			dat[i] += x;
			i += i & -i;
		}
	}//0-indexed
	int query(int i) {
		i++;
		int sum = 0;
		while (i > 0) {
			sum += dat[i];
			i -= i & -i;
		}
		return sum;
	}//0-indexed
	int operator[](const int& i) {
		return query(i) - query(i - 1);
	}
};//size, 0-indexed
int n, q;
vec<P>a;
BIT x, y;
signed main() {
	cin >> n >> q;
	x.init(n); y.init(n);
	rep(i, n) { 
		x.add(i, i); x.add(i + 1, -i);
		y.add(i, n - 1 - i); y.add(i + 1, -n + 1 + i);
	}
	rep(i, q) {
		int t, u, v;
		cin >> u >> t >> v;
		u--;
		if (t == 2) u = n - 1 - u;
		a.ppp(t, u, v);
		//クエリTの時、u以下のものをv動かす。
	}
	reverse(all(a));
	range(g, a) {
		if (g.xx == 1) {
			//x座標がX以下の頂点についてyを加算する
			//二分探索でx座標がX以下の最後の頂点を求める
			int ok = -1, ng = n, mid;
			while (abs(ok - ng) > 1) {
				mid = (ok + ng) / 2;
				if (x.query(mid) <= g.yy) ok = mid;
				else ng = mid;
			}
			if (ok >= 0) {
				y.add(0, g.zz * 2); y.add(ok + 1, -g.zz * 2);
			}
		}
		else {
			//y座標がX以下の最初の頂点を求める
			int ok = n, ng = -1, mid;
			while (abs(ok - ng) > 1) {
				mid = (ok + ng) / 2;
				if (y.query(mid) <= g.yy) ok = mid;
				else ng = mid;
			}
			if (ok < n - 1) {
				if (y.query(ok) == g.yy) x.add(ok + 1, g.zz * 2);
				else x.add(ok, g.zz * 2);
			}
		}
	}
	rep(i, n) {
		cout << (x.query(i) + y.query(i) - n + 1) / 2 << endl;
	}
}
accuracy: 1
time_ms: 190
memory_kb: 12304
final_rank: 8

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

using namespace std;
using int64 = long long;
const int mod = 1e9 + 7;
// const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

/**
 * @brief Binary-Indexed-Tree(BIT)
 * @docs docs/binary-indexed-tree.md
 */
template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree() = default;

  explicit BinaryIndexedTree(size_t sz) : data(sz + 1, 0) {}

  void add(int k, const T &x) {
    for(++k; k < (int) data.size(); k += k & -k) data[k] += x;
  }

  T query(int k) const {
    T ret = T();
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return ret;
  }

  int lower_bound(T x) const {
    int i = 0;
    for(int k = 1 << (__lg(data.size() - 1) + 1); k > 0; k >>= 1) {
      if(i + k < data.size() && data[i + k] < x) {
        x -= data[i + k];
        i += k;
      }
    }
    return i;
  }

  int upper_bound(T x) const {
    int i = 0;
    for(int k = 1 << (__lg(data.size() - 1) + 1); k > 0; k >>= 1) {
      if(i + k < data.size() && data[i + k] <= x) {
        x -= data[i + k];
        i += k;
      }
    }
    return i;
  }
};

int main() {
  int N, Q;
  cin >> N >> Q;
  vector< int > X(Q), D(Q), L(Q);
  for(int i = 0; i < Q; i++) {
    cin >> X[i] >> D[i] >> L[i];
  }
  BinaryIndexedTree< int64 > xpy(N), xmy(N);
  for(int i = 0; i <= N; i++) xpy.data[i] = i & -i;
  for(int i = 0; i <= N; i++) xmy.data[i] = i & -i;
  for(int i = Q - 1; i >= 0; i--) {
    if(D[i] == 1) {
      xmy.add(0, -L[i] * 2);
      xmy.add(xpy.upper_bound(X[i]), L[i] * 2);
    } else {
      xpy.add(xmy.upper_bound(X[i]), L[i] * 2);
    }
  }
  for(int i = 0; i < N; i++) {
    cout << (xpy.query(i) - xmy.query(i)) / 2 << "\n";
  }
}
accuracy: 1
time_ms: 60
memory_kb: 8384
final_rank: 2

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

using namespace std;
using int64 = long long;
const int mod = 1e9 + 7;
// const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

/**
 * @brief Binary-Indexed-Tree(BIT)
 * @docs docs/binary-indexed-tree.md
 */
template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree() = default;

  explicit BinaryIndexedTree(size_t sz) : data(sz + 1, 0) {
    for(int i = 0; i < data.size(); i++) data[i] = i & -i;
  }

  void add(int k, const T &x) {
    for(++k; k < (int) data.size(); k += k & -k) data[k] += x;
  }

  T query(int k) const {
    T ret = T();
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return ret;
  }

  int lower_bound(T x) const {
    int i = 0;
    for(int k = 1 << (__lg(data.size() - 1) + 1); k > 0; k >>= 1) {
      if(i + k < data.size() && data[i + k] < x) {
        x -= data[i + k];
        i += k;
      }
    }
    return i;
  }

  int upper_bound(T x) const {
    int i = 0;
    for(int k = 1 << (__lg(data.size() - 1) + 1); k > 0; k >>= 1) {
      if(i + k < data.size() && data[i + k] <= x) {
        x -= data[i + k];
        i += k;
      }
    }
    return i;
  }
};

int main() {
  int N, Q;
  cin >> N >> Q;
  vector< int > X(Q), D(Q), L(Q);
  for(int i = 0; i < Q; i++) {
    cin >> X[i] >> D[i] >> L[i];
  }
  BinaryIndexedTree< int64 > xpy(N), xmy(N);
  for(int i = Q - 1; i >= 0; i--) {
    if(D[i] == 1) {
      xmy.add(0, -L[i] * 2);
      xmy.add(xpy.upper_bound(X[i]), L[i] * 2);
    } else {
      xpy.add(xmy.upper_bound(X[i]), L[i] * 2);
    }
  }
  for(int i = 0; i < N; i++) {
    cout << (xpy.query(i) - xmy.query(i)) / 2 << "\n";
  }
}
accuracy: 1
time_ms: 60
memory_kb: 8388
final_rank: 3

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

using namespace std;
using int64 = long long;
const int mod = 1e9 + 7;
// const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;


struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

/**
 * @brief Binary-Indexed-Tree(BIT)
 * @docs docs/binary-indexed-tree.md
 */
template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree() = default;

  explicit BinaryIndexedTree(size_t sz) : data(sz + 1, 0) {
    for(int i = 0; i < data.size(); i++) data[i] = i & -i;
  }

  void add(int k, const T &x) {
    for(++k; k < (int) data.size(); k += k & -k) data[k] += x;
  }

  T query(int k) const {
    T ret = T();
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return ret;
  }

  int lower_bound(T x) const {
    if(x <= 0) return 0;
    int i = 0;

    int curr = 1;
    while(curr < data.size()) curr <<= 1;

    for(int k = curr; k > 0; k >>= 1) {
      if(i + k < data.size() && data[i + k] < x) {
        x -= data[i + k];
        i += k;
      }
    }
    return i;
  }

  int upper_bound(T x) const {
    int i = 0;


    int curr = 1;
    while(curr < data.size()) curr <<= 1;

    for(int k = curr; k > 0; k >>= 1) {
      if(i + k < data.size() && data[i + k] <= x) {
        x -= data[i + k];
        i += k;
      }
    }
    return i;
  }
};


int N, Q;
int X[200000], D[200000], L[200000];
char buff[32];

int main() {
  scanf("%d %d", &N, &Q);
  for(int i = 0; i < Q; i++) {
    scanf("%d %d %d", &X[i], &D[i], &L[i]);
  }
  BinaryIndexedTree< int64 > xpy(N), xmy(N);
  for(int i = Q - 1; i >= 0; i--) {
    if(D[i] == 1) {
      xmy.add(0, -L[i] * 2);
      xmy.add(xpy.upper_bound(X[i]), L[i] * 2);
    } else {
      xpy.add(xmy.upper_bound(X[i]), L[i] * 2);
    }
  }
  for(int i = 0; i < N; i++) {
    printf("%lld\n", (xpy.query(i) - xmy.query(i)) / 2);
  }
}
accuracy: 1
time_ms: 70
memory_kb: 8388
final_rank: 6

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

using namespace std;
typedef long long int64;

struct BinaryIndexedTree {
  vector< int64 > data;
  int curr;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
    curr = 1;
    while(curr < data.size()) curr <<= 1;
    for(int i = 0; i < data.size(); i++) data[i] = i & -i;
  }

  inline int64 sum(int k) {
    int64 ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  inline int upper_bound(int64 w) {
    int i = 0;
    for(int k = curr; k > 0; k >>= 1) {
      if(i + k < data.size() && data[i + k] <= w) {
        w -= data[i + k];
        i += k;
      }
    }
    return (i);
  }

  inline void add(int k, int64 x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};

int N, Q;
int X[200000], D[200000], L[200000];
char buff[32];

int main() {
  scanf("%d %d", &N, &Q);
  for(int i = 0; i < Q; i++) {
    scanf("%d %d %d", &X[i], &D[i], &L[i]);
  }
  BinaryIndexedTree xpy(N), xmy(N);
  for(int i = Q - 1; i >= 0; i--) {
    if(D[i] == 1) {
      xmy.add(0, -L[i] * 2);
      xmy.add(xpy.upper_bound(X[i]), L[i] * 2);
    } else {
      xpy.add(xmy.upper_bound(X[i]), L[i] * 2);
    }
  }
  for(int i = 0; i < N; i++) {
    printf("%lld\n", (xpy.sum(i) - xmy.sum(i)) / 2);
  }
}
accuracy: 1
time_ms: 70
memory_kb: 8384
final_rank: 5

code_snippet: #include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
template <typename T> using lim = numeric_limits<T>;
const int N = 500;
int g[2*N+1][2*N+1];
void debug() {
    for(int i = 0; i <= 2*N; i++) {
        for(int j = 0; j <= i; j++) {
            if((i + j) % 2 == 0) {
                cout << setw(2) << g[i][j];
            } else {
                cout << "..";
            }
        }
        cout << endl;
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    for(int level = 0; level <= N; level++) {
        for(int r = 2 * level, c = 0; r <= 2 * N and c <= 2 * N; r++, c++) {
            g[r][c] = level;
        }
    }
    int n, q;
    cin >> n >> q;
    while(q--) {
        int x, d, l;
        cin >> x >> d >> l;
        x += N;
        if(d == 1) {
            for(int level = 0; level <= N; level++) {
                for(int r = 2 * level, c = 0; r < x and c <= 2 * N; r++, c++) {
                    g[r][c] = c - 2 * l >= 0 ? g[r][c - 2 * l] : 0;
                }
            }
        } else {
            for(int level = 0; level <= N; level++) {
                vector<pair<int, int>> rc;
                for(int r = 2 * N, c = 2 * N - 2 * level; r >= 0 and c >= x; r--, c--) {
                    g[r][c] = r + 2 * l <= 2 * N ? g[r + 2 * l][c] : 0;
                }
            }
        }
    }
    for(int i = 0; i < n; i++) {
        cout << g[i + N][i + N] << endl;
    }
    return 0;
}
accuracy: 0.225
time_ms: 10
memory_kb: 7112
final_rank: 20

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 200005

enum Type{
	X,
	Y,
};

struct Info{
	int loc,command;
	ll diff;
};

int N = 1;
ll uniformity[8*NUM][2],partial[8*NUM][2];
Info info[NUM];


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

void add_and_updateNodes(int left,int right,ll value,int node_id,int node_left,int node_right,Type type){

	if(right < node_left || left > node_right)return;
	else if(left <= node_left && right >= node_right){
		uniformity[node_id][type] += value;
	}else{
		partial[node_id][type] += (min(right,node_right)-max(left,node_left)+1)*value;
		add_and_updateNodes(left,right,value,2*node_id+1,node_left,(node_left+node_right)/2,type);
		add_and_updateNodes(left,right,value,2*node_id+2,(node_left+node_right)/2+1,node_right,type);
	}
}

ll getSum(int left,int right,int node_id,int node_left,int node_right,Type type){
	if(right < node_left || left > node_right)return 0;
	else if(left <= node_left && right >= node_right){
		return (node_right-node_left+1)*uniformity[node_id][type]+partial[node_id][type];

	}else{
		ll sum = (min(right,node_right)-max(left,node_left)+1)*uniformity[node_id][type];
		sum += getSum(left,right,2*node_id+1,node_left,(node_left+node_right)/2,type);
		sum += getSum(left,right,2*node_id+2,(node_left+node_right)/2+1,node_right,type);
		return sum;
	}
}

int main(){

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

	init(first_N);

	for(int i = 0; i <= 2*N-2; i++){

		uniformity[i][X] = 0;
		uniformity[i][Y] = 0;

		partial[i][X] = 0;
		partial[i][Y] = 0;
	}

	for(int i = 0; i < Q; i++){

		scanf("%d %d %lld",&info[i].loc,&info[i].command,&info[i].diff);
	}

	ll L,R,mid,limit;

	for(int i = Q-1; i >= 0; i--){

		if(info[i].command == 1){

			L = 0, R = first_N-1, mid = (L+R)/2;
			limit = N;

			while(L <=R){

				if(mid+getSum(mid,mid,0,0,N-1,X) >= info[i].loc){

					limit = mid;
					R = mid-1;

				}else{

					L = mid+1;
				}
				mid = (L+R)/2;
			}

			add_and_updateNodes(0,limit-1,-2*info[i].diff,0,0,N-1,Y);

		}else{

			L = 0, R = first_N-1, mid = (L+R)/2;
			limit = -1;

			while(L <=R){

				if(mid+getSum(mid,mid,0,0,N-1,Y) < info[i].loc){

					limit = mid;
					L = mid+1;

				}else{

					R = mid-1;
				}
				mid = (L+R)/2;
			}

			add_and_updateNodes(limit+1,N-1,2*info[i].diff,0,0,N-1,X);

		}
	}

	for(int i = 0; i < first_N; i++){

		printf("%lld\n",(getSum(i,i,0,0,N-1,X)-getSum(i,i,0,0,N-1,Y))/2);
	}

	return 0;
}
accuracy: 1
time_ms: 490
memory_kb: 22732
final_rank: 17

code_snippet: //0:48
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
#define N (1<<18)
class RAQ{
private:
    ll dat[2*N];
    void dfs(int l,int r,int a,int b,int k,ll x){
	if(l<=a&&b<=r){dat[k]+=x;return;}
	if(b<=l||r<=a)return;
	dfs(l,r,a,(a+b)/2,k*2+1,x);
	dfs(l,r,(a+b)/2,b,k*2+2,x);
    }
public:
    void Init(int k){
	lol(i,2*N)dat[i]=0;
	lol(i,N)dat[i+N-1]=(i+1)*k;
    }
    void Add(int l,int r,ll x){
	if(l>r)return;
	dfs(l,r+1,0,N,0,x);
    }
    ll Sum(int i){
	i+=N-1;
	ll res=dat[i];
	while(i>0){
	    i=(i-1)/2;
	    res+=dat[i];
	}
	return res;
    }
};
ll n,q,a[N],b[N],c[N];
int main(){
    cin>>n>>q;
    //lol(i,q)cin>>a[i]>>b[i]>>c[i];
    lol(i,q)scanf("%lld%lld%lld",&a[i],&b[i],&c[i]);
    RAQ X,Y;X.Init(1);Y.Init(-1);
    for(int k=q-1;k>=0;k--){
	if(b[k]==1){
	    int l=-1,r=n,m;
	    while(l<r-1){
		m=(l+r)/2;
		if(X.Sum(m)<=a[k])l=m;
		else r=m;
	    }
	    Y.Add(0,l,c[k]*2);
	}
	if(b[k]==2){
	    int l=-1,r=n,m;
	    while(l<r-1){
		m=(l+r)/2;
		if(Y.Sum(m)<-a[k])r=m;
		else l=m;
	    }
	    X.Add(r,n-1,c[k]*2);
	}
    }
    //lol(i,n)cout<<(X.Sum(i)+Y.Sum(i))/2<<endl;
    lol(i,n){
	ll ans=(X.Sum(i)+Y.Sum(i))/2;
	printf("%lld\n",ans);
    }
    return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 16120
final_rank: 9

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

struct segtree{
    static const int SEG=1<<18;
    vint put;
    segtree():put(SEG*2){}
    void add(int a,int b,int x,int k=0,int l=0,int r=SEG){
        if(r<=a||b<=l)return;
        if(a<=l&&r<=b){
            put[k]+=x;
            return;
        }
        add(a,b,x,k*2+1,l,(l+r)/2);
        add(a,b,x,k*2+2,(l+r)/2,r);
    }
    int query(int k){
        k+=SEG-1;
        int ret=0;
        while(true){
            ret+=put[k];
            if(k==0)break;
            k=(k-1)/2;
        }
        return ret;
    }
};

signed main(){
    int N,Q;
    scanf("%lld%lld",&N,&Q);

    segtree segX,segY;
    rep(i,N)segX.add(i,i+1,2*i+1);


    vector<tuple<int,int,int>>qs;
    rep(i,Q){
        int x,d,l;
        scanf("%lld%lld%lld",&x,&d,&l);
        x*=2;
        qs.pb(make_tuple(x,d,l));
    }
    for(int i=Q-1;i>=0;i--){
        int x,d,l;
        tie(x,d,l)=qs[i];
        if(d==1){
            int lb=-1,ub=N;
            while(ub-lb>1){
                int mid=(ub+lb)/2;
                int xx=segX.query(mid);

                int yy=segY.query(mid);
                if(-(x-xx)<yy*2)lb=mid;
                else ub=mid;
            }
            segX.add(0,ub,-2*l);
            segY.add(0,ub,-l);
        }
        else{
            int lb=-1,ub=N;
            while(ub-lb>1){
                int mid=(ub+lb)/2;

                int xx=segX.query(mid);
                int yy=segY.query(mid);
                if(-(xx-x)<yy*2)ub=mid;
                else lb=mid;
            }
            segX.add(ub,N,2*l);
            segY.add(ub,N,-l);
        }
    }

    rep(i,N){
        int y=segY.query(i);
        printf("%lld\n",-y);
    }
    return 0;
}
accuracy: 1
time_ms: 260
memory_kb: 17316
final_rank: 11

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

int n;

class BIT{
	vector<int> bit;
public:
	BIT() : bit(n + 2){}
	void add(int i,int x){
		while(i < bit.size()){
			bit[i] += x;
			i += i & -i;
		}
	}
	int get(int i){
		int s = 0;
		while(i){
			s += bit[i];
			i -= i & -i;
		}
		return s;
	}
};

signed main(){
	int q,x[200000],d[200000],l[200000];
	cin >> n >> q;
	vector<BIT> ps(2);
	ps[1].add(1,n - 1);
	for(int i = 1;i < n;i++){
		ps[0].add(i + 1,1);
		ps[1].add(i + 1,-1);
	}
	for(int i = 0;i < q;i++) cin >> x[i] >> d[i] >> l[i];
	for(int i = q - 1;i >= 0;i--){
		int low = -1,up = n;
		while(up - low > 1){
			int mid = (up + low) / 2;
			if(d[i] == 1){
				if(ps[0].get(mid + 1) < x[i]) low = mid;
				else up = mid;
			}else{
				if(ps[1].get(mid + 1) < n - x[i]) up = mid;
				else low = mid;
			}
		}
		if(d[i] == 1){
			ps[1].add(1,l[i] * 2);
			ps[1].add(up + 1,-l[i] * 2);
		}
		else ps[0].add(up + 1,l[i] * 2);
	}
	for(int i = 0;i < n;i++) cout << (ps[0].get(i + 1) + ps[1].get(i + 1) - n + 1) / 2 << endl;
	return 0;
}
accuracy: 1
time_ms: 360
memory_kb: 10640
final_rank: 10

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

int seg = 1;

class RAQ{
	vector<int> dat;
public:
	RAQ() : dat(seg * 2 - 1){}
	void add(int a,int b,int x,int k = 0,int l = 0,int r = seg){
		if(b <= l || r <= a) return;
		if(a <= l && r <= b){
			dat[k] += x;
			return;
		}
		add(a,b,x,k * 2 + 1,l,(l + r) / 2);
		add(a,b,x,k * 2 + 2,(l + r) / 2,r);
	}
	int get(int i){
		int s = 0;
		i += seg - 1;
		s += dat[i];
		while(i){
			i = (i - 1) / 2;
			s += dat[i];
		}
		return s;
	}
};

signed main(){
	int n,q,x[200000],d[200000],l[200000];
	cin >> n >> q;
	while(seg < n) seg *= 2;
	vector<RAQ> ps(2);
	for(int i = 0;i < n;i++){
		ps[0].add(i,i + 1,i);
		ps[1].add(i,i + 1,n - i - 1);
	}
	for(int i = 0;i < q;i++) cin >> x[i] >> d[i] >> l[i];
	for(int i = q - 1;i >= 0;i--){
		int low = -1,up = n;
		while(up - low > 1){
			int mid = (up + low) / 2;
			if(d[i] == 1){
				if(ps[0].get(mid) < x[i]) low = mid;
				else up = mid;
			}else{
				if(ps[1].get(mid) < n - x[i]) up = mid;
				else low = mid;
			}
		}
		if(d[i] == 1) ps[1].add(0,up,l[i] * 2);
		else ps[0].add(up,seg,l[i] * 2);
	}
	for(int i = 0;i < n;i++) cout << (ps[0].get(i) + ps[1].get(i) - n + 1) / 2 << endl;
	return 0;
}
accuracy: 1
time_ms: 420
memory_kb: 15712
final_rank: 14

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

int seg = 1;

class RAQ{
	vector<int> dat;
public:
	RAQ() : dat(seg * 2 - 1){}
	void add(int a,int b,int x,int k = 0,int l = 0,int r = seg){
		if(b <= l || r <= a) return;
		if(a <= l && r <= b){
			dat[k] += x;
			return;
		}
		add(a,b,x,k * 2 + 1,l,(l + r) / 2);
		add(a,b,x,k * 2 + 2,(l + r) / 2,r);
	}
	int get(int i){
		int s = 0;
		i += seg - 1;
		s += dat[i];
		while(i){
			i = (i - 1) / 2;
			s += dat[i];
		}
		return s;
	}
};

signed main(){
	int n,q,x[100000],d[100000],l[100000];
	cin >> n >> q;
	while(seg < n) seg *= 2;
	vector<RAQ> ps(2);
	for(int i = 0;i < n;i++){
		ps[0].add(i,i + 1,i);
		ps[1].add(i,i + 1,n - i - 1);
	}
	for(int i = 0;i < q;i++) cin >> x[i] >> d[i] >> l[i];
	for(int i = q - 1;i >= 0;i--){
		int low = -1,up = n;
		while(up - low > 1){
			int mid = (up + low) / 2;
			if(d[i] == 1){
				if(ps[0].get(mid) < x[i]) low = mid;
				else up = mid;
			}else{
				if(ps[1].get(mid) < n - x[i]) up = mid;
				else low = mid;
			}
		}
		if(d[i] == 1) ps[1].add(0,up,l[i] * 2);
		else ps[0].add(up,seg,l[i] * 2);
	}
	for(int i = 0;i < n;i++) cout << (ps[0].get(i) + ps[1].get(i) - n + 1) / 2 << endl;
	return 0;
}
accuracy: 0.6
time_ms: 70
memory_kb: 15196
final_rank: 19

code_snippet: #include <cstdio>
#pragma warning(disable : 4996)
int N, Q, X[200009], D[200009], L[200009]; long long bit[2][262156];
void add(int t, int p, int x) {
	for (int i = p + 1; i <= 262144; i += i & (-i)) {
		bit[t][i] += x;
	}
}
long long sum(int t, int p) {
	long long ret = 0;
	for (int i = p; i >= 1; i -= i & (-i)) {
		ret += bit[t][i];
	}
	return ret;
}
int bs(int t, long long x) {
	if (x <= 0) return 0;
	int cur = 0;
	for (int i = 17; i >= 0; i--) {
		if (bit[t][cur + (1 << i)] < x) {
			cur += 1 << i;
			x -= bit[t][cur];
		}
	}
	return cur + 1;
}
int main() {
	scanf("%d %d", &N, &Q);
	for (int i = 0; i < Q; i++) scanf("%d %d %d", &X[i], &D[i], &L[i]);
	for (int i = 1; i < N; i++) add(0, i, 1), add(1, i, 1);
	long long cs = 0, ct = 0;
	for (int i = Q - 1; i >= 0; i--) {
		if (D[i] == 1) {
			int pr = bs(0, X[i] + ct) - 1;
			if(pr != -1) add(1, pr, 2 * L[i]);
			else cs -= 2 * L[i];
			cs += 2 * L[i];
		}
		else {
			int pr = bs(1, X[i] + cs) - 1;
			if(pr != -1) add(0, pr, 2 * L[i]);
			else ct -= 2 * L[i];
		}
	}
	for (int i = 0; i < N; i++) {
		long long px = sum(0, i + 1), py = sum(1, i + 1);
		printf("%lld\n", (px - py + cs - ct) / 2);
	}
	return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 8252
final_rank: 1

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

class RangeAddQuery {
public:
	vector<long long>bit; int size__;

	void initialize(int size_) {
		size__ = size_;
		bit.resize(size_ + 4, 0);
	}
	int size() {
		return size__;
	}
	void Add(int p, int x) {
		p++;
		while (p < size__ + 4) { bit[p] += x; p += (p&-p); }
	}
	long long Sum(int p) {
		long long s = 0; p++;
		while (p >= 1) { s += bit[p]; p -= (p&-p); }
		return s;
	}
	void add(int l, int r, int x) {
		// Add x in range [l, r)
		Add(l, x); Add(r, -x);
	}
	long long get(int pos) {
		return Sum(pos);
	}
};

long long N, Q, a[200009], b[200009], c[200009];
int main() {
	cin >> N >> Q;
	RangeAddQuery R1, R2; R1.initialize(N + 1); R2.initialize(N + 1);
	for (int i = 1; i <= N; i++) { R1.add(i, i + 1, i); R2.add(i, i + 1, i); }
	for (int i = 1; i <= Q; i++) { cin >> a[i] >> b[i] >> c[i]; }
	for (int i = Q; i >= 1; i--) {
		if (b[i] == 1) {
			int L = 1, R = N + 1, M, maxn = -1;
			for (int j = 0; j < 20; j++) {
				M = (L + R) / 2;
				if (R1.get(M) <= a[i]) { maxn = max(maxn, M); L = M; }
				else { R = M; }
			}
			R2.add(1, maxn + 1, -c[i] * 2);
		}
		else {
			int L = 1, R = N + 1, M, maxn = 999999;
			for (int j = 0; j < 20; j++) {
				M = (L + R) / 2;
				if (R2.get(M) > a[i]) { maxn = min(maxn, M); R = M; }
				else { L = M; }
			}
			R1.add(maxn, N + 1, c[i] * 2);
		}
		//for (int i = 1; i <= N; i++)cout << (R1.get(i) - R2.get(i)) / 2 << " "; cout << endl;
	}
	for (int i = 1; i <= N; i++)cout << (R1.get(i) - R2.get(i)) / 2 << endl;
	return 0;
}
accuracy: 1
time_ms: 410
memory_kb: 10760
final_rank: 13

code_snippet: #include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>

#define INF 1000000000
#define LINF 1e18
#define MOD 1000000007
#define ll long long
#define rep(i,a,b) for(int32 i = (a); i < (b); ++i)
#define rrep(i,a,b) for(int32 i = (b) - 1; i >= (a); --i)
#define bitget(a,b) (((a) >> (b)) & 1)
#define vint vector<int>
#define ALL(x) (x).begin(),(x).end()
#define C(x) cout << #x << " : " << x << endl
#define scanf scanf_s

using int32 = int_fast32_t;
using int64 = int_fast64_t;
using uint32 = uint_fast32_t;
using uint64 = uint_fast64_t;

using namespace std;

template<typename Monoid>
class BIT {
public:
	size_t len, size;
	Monoid* arr;
	Monoid* tree;
	uint32 i;
	//?????????????????????
	BIT(const size_t &length) {
		len = length;
		size = length;
		if (size & 0xffff0000) { size = size & 0xffff0000; }
		if (size & 0xff00ff00) { size = size & 0xff00ff00; }
		if (size & 0xf0f0f0f0) { size = size & 0xf0f0f0f0; }
		if (size & 0xcccccccc) { size = size & 0xcccccccc; }
		if (size & 0xaaaaaaaa) { size = size & 0xaaaaaaaa; }
		size <<= 1;
		tree = (Monoid *)calloc(size, sizeof(Monoid));
	}
	//0?????????
	void set() {
		for (i = 0; i < size; ++i) tree[i] = 0;
	}
	//array??§?????????
	void set(Monoid* array) {
		--array;
		for (i = 1; i <= len; ++i) {
			tree[i] = array[i] + range(i);
		}
		++array;
	}
	//[0,a)???????????????
	Monoid range(size_t a) {
		Monoid ret = tree[a];
		a &= a - 1;
		while (a) {
			ret += tree[a];
			a &= a - 1;
		}
		return ret;
	}
	//index:a???data?????????
	void update(const size_t &a, const Monoid &data) {
		int32 b = int32(a);
		++b;
		while (b < size) {
			tree[b] += data;
			b += b&(-b);
		}
	}
	//
	size_t up_b(Monoid data) {
		size_t s = size >> 1;
		size_t t = size;
		size_t ret = 0;
		while (t>>=1) {
			if (tree[s] <= data) {
				data -= tree[s];
				s += t >> 1;
				ret += t;
			}
			else {
				s -= t >> 1;
			}
		}
		return ret;
	}
};

struct IN {
	int32 x, d, l;
};

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	size_t n, q;
	cin >> n >> q;
	vector<int64> ans(n+1, 0);
	vector<IN> t(q);
	rep(i, 0, q)
		cin >> t[i].x >> t[i].d >> t[i].l;
	BIT<int64> R(n), L(n);
	R.set();L.set();
	rep(i, 0, n) {
		R.update(i, 1);
		L.update(i, 1);
	}
	R.update(n, LINF);
	L.update(n, LINF);
	size_t temp;
	for (int32 i = q - 1;~i;--i) {
		if (t[i].d == 1) {
			temp = L.up_b(t[i].x);
			ans[0] += t[i].l;
			ans[temp] -= t[i].l;
			R.update(n - temp, t[i].l << 1);
		}
		else {
			temp = n - R.up_b(n - t[i].x);
			ans[temp] += t[i].l;
			ans[n] -= t[i].l;
			L.update(temp, t[i].l << 1);
		}
	}
	rep(i, 0, n)
		ans[i + 1] += ans[i];
	rep(i, 0, n)
		printf("%lld\n", ans[i]);
	return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 13112
final_rank: 7