Problem:
Conveyor Belt
Awesome Conveyor Machine
(ACM) is the most important equipment of a factory of
Industrial Conveyor Product Corporation
(ICPC). ACM has a long conveyor belt to deliver their products from some points to other points. You are a programmer hired to make efficient schedule plan for product delivery.
ACM's conveyor belt goes through $N$ points at equal intervals. The conveyor has plates on each of which at most one product can be put. Initially, there are no plates at any points. The conveyor belt moves by exactly one plate length per unit time; after one second, a plate is at position 1 while there are no plates at the other positions. After further 1 seconds, the plate at position 1 is moved to position 2 and a new plate comes at position 1, and so on. Note that the conveyor has the unlimited number of plates: after $N$ seconds or later, each of the $N$ positions has exactly one plate.
A delivery task is represented by positions $a$ and $b$; delivery is accomplished by putting a product on a plate on the belt at $a$, and retrieving it at $b$ after $b - a$ seconds ($a < b$). (Of course, it is necessary that an empty plate exists at the position at the putting time.) In addition, putting and retrieving products must bedone in the following manner:
When putting and retrieving a product, a plate must be located just at the position. That is, products must be put and retrieved at integer seconds.
Putting and retrieving at the same position
cannot
be done at the same time. On the other hand, putting and retrieving at the different positions can be done at the same time.
If there are several tasks, the time to finish all the tasks may be reduced by changing schedule when each product is put on the belt. Your job is to write a program minimizing the time to complete all the tasks... wait, wait. When have you started misunderstanding that you can know all the tasks initially? New delivery requests are coming moment by moment, like plates on the conveyor! So you should update your optimal schedule per every new request.
A request consists of a start point $a$, a goal point $b$, and the number $p$ of products to deliver from $a$ to $b$. Delivery requests will be added $Q$ times. Your (true) job is to write a program such that for each $1 \leq i \leq Q$, minimizing the entire time to complete delivery tasks in requests 1 to $i$.
Input
The input consists of a single test case formatted as follows.
$N$ $Q$
$a_1$ $b_1$ $p_1$
:
$a_Q$ $b_Q$ $p_Q$
A first line includes two integers $N$ and $Q$ ($2 \leq N \leq 10^5, 1 \leq Q \leq 10^5$): $N$ is the number of positions the conveyor belt goes through and $Q$ is the number of requests will come. The $i$-th line of the following $Q$ lines consists of three integers $a_i, b_i,$ and $p_i$ ($1 \leq a_i < b_i \leq N, 1 \leq p_i \leq 10^9$), which mean that the $i$-th request requires $p_i$ products to be delivered from position $a_i$ to position $b_i$.
Output
In the $i$-th line, print the minimum time to complet
...(truncated)

Submitted solutions:

code_snippet: #include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#define re register
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define MAXN 4000007
#define ll long long
#define mo 19930726
#define ls rt<<1
#define rs rt<<1|1
using namespace std;
typedef unsigned long long ull;
ll mx[200001<<2],tag[200001<<2];
ll n,m,rr,t,q;
inline int read()
{
    int x=0,c=1;
    char ch=' ';
    while((ch>'9'||ch<'0')&&ch!='-')ch=getchar();
    while(ch=='-')c*=-1,ch=getchar();
    while(ch<='9'&&ch>='0')x=x*10+ch-'0',ch=getchar();
    return x*c;
}
void change(int L,int R,int k,int l,int r,int rt)
{
	if(L<=l&&r<=R){
		mx[rt]+=k;tag[rt]+=k;
		return;
	}
	int mid=l+r>>1;
	if(L<=mid) change(L,R,k,l,mid,ls);
	if(mid<R) change(L,R,k,mid+1,r,rs);
	mx[rt]=max(mx[ls],mx[rs])+tag[rt];
}
int main()
{
	n=read();q=read();
	int rr=1;
	for(re int i=1;i<=q;i++){
		int x=read(),y=read(),k=read();
		while(rr<y) change(++rr,n,1,1,n,1);
		change(x,y,k,1,n,1);
		printf("%ld\n",(mx[1]));
	}
}
accuracy: 1
time_ms: 30
memory_kb: 11744
final_rank: 9

code_snippet: #include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#define re register
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define MAXN 4000007
#define ll long long
#define mo 19930726
#define ls rt<<1
#define rs rt<<1|1
using namespace std;
typedef unsigned long long ull;
priority_queue<ll,vector<ll>,greater<ll> > pl,pr;
int mx[200001<<2],tag[200001<<2];
int n,m,rr,t,q;
inline int read()
{
    int x=0,c=1;
    char ch=' ';
    while((ch>'9'||ch<'0')&&ch!='-')ch=getchar();
    while(ch=='-')c*=-1,ch=getchar();
    while(ch<='9'&&ch>='0')x=x*10+ch-'0',ch=getchar();
    return x*c;
}
void change(int L,int R,int k,int l,int r,int rt)
{
	if(L<=l&&r<=R){
		mx[rt]+=k;tag[rt]+=k;
		return;
	}
	int mid=l+r>>1;
	if(L<=mid) change(L,R,k,l,mid,ls);
	if(mid<R) change(L,R,k,mid+1,r,rs);
	mx[rt]=max(mx[ls],mx[rs])+tag[rt];
}
int main()
{
	n=read();q=read();
	int rr=1;
	for(re int i=1;i<=q;i++){
		int x=read(),y=read(),k=read();
		while(rr<y) change(++rr,n,1,1,n,1);
		change(x,y,k,1,n,1);
		printf("%ld\n",(mx[1]));
	}
}
accuracy: 0.2545454545454545
time_ms: 30
memory_kb: 8236
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005;
const ll INF=15LL<<58;

// BIT セグ木 遅延セグ木 のみ

// from: https://gist.github.com/yosupo06/ddd51afb727600fd95d9d8ad6c3c80c9
// (based on AtCoder STL)

#include <algorithm>
#include <array>
#ifdef _MSC_VER
#include <intrin.h>
#endif
namespace atcoder {
    namespace internal {
        int ceil_pow2(int n) {
            int x = 0;
            while ((1U << x) < (unsigned int)(n)) x++;
            return x;
        }
        int bsf(unsigned int n) {
#ifdef _MSC_VER
            unsigned long index;
            _BitScanForward(&index, n);
            return index;
#else
            return __builtin_ctz(n);
#endif
        }
    }  // namespace internal
    
}  // namespace atcoder

#include <cassert>
#include <numeric>
#include <type_traits>

namespace atcoder {
    
    namespace internal {
        
#ifndef _MSC_VER
        template <class T>
        using is_signed_int128 =
        typename std::conditional<std::is_same<T, __int128_t>::value ||
        std::is_same<T, __int128>::value,
        std::true_type,
        std::false_type>::type;
        
        template <class T>
        using is_unsigned_int128 =
        typename std::conditional<std::is_same<T, __uint128_t>::value ||
        std::is_same<T, unsigned __int128>::value,
        std::true_type,
        std::false_type>::type;
        
        template <class T>
        using make_unsigned_int128 =
        typename std::conditional<std::is_same<T, __int128_t>::value,
        __uint128_t,
        unsigned __int128>;
        
        template <class T>
        using is_integral = typename std::conditional<std::is_integral<T>::value ||
        is_signed_int128<T>::value ||
        is_unsigned_int128<T>::value,
        std::true_type,
        std::false_type>::type;
        
        template <class T>
        using is_signed_int = typename std::conditional<(is_integral<T>::value &&
                                                         std::is_signed<T>::value) ||
        is_signed_int128<T>::value,
        std::true_type,
        std::false_type>::type;
        
        template <class T>
        using is_unsigned_int =
        typename std::conditional<(is_integral<T>::value &&
                                   std::is_unsigned<T>::value) ||
        is_unsigned_int128<T>::value,
        std::true_type,
        std::false_type>::type;
        
        template <class T>
        using to_unsigned = typename std::conditional<
        is_signed_int128<T>::value,
        make_unsigned_int128<T>,
        typename std::conditional<std::is_signed<T>::value,
        std::make_unsigned<T>,
        std::common_type<T>>::type>::type;
        
#else
        
        template <class T> using is_integral = typename std::is_integral<T>;
        
        template <class T>
        using is_signed_int =
        typename std::conditional<is_integral<T>::value && std::is_signed<T>::value,
        std::true_type,
        std::false_type>::type;
        
        template <class T>
        using is_unsigned_int =
        typename std::conditional<is_integral<T>::value &&
        std::is_unsigned<T>::value,
        std::true_type,
        std::false_type>::type;
        
        template <class T>
        using to_unsigned = typename std::conditional<is_signed_int<T>::value,
        std::make_unsigned<T>,
        std::common_type<T>>::type;
        
#endif
        
        template <class T>
        using is_signed_int_t = std::enable_if_t<is_signed_int<T>::value>;
        
        template <class T>
        using is_unsigned_int_t = std::enable_if_t<is_unsigned_int<T>::value>;
        
        template <class T> using to_unsigned_t = typename to_unsigned<T>::type;
        
    }  // namespace internal
    
}  // namespace atcoder

#include <cassert>
#include <vector>

namespace atcoder {
    
    template <class T> struct fenwick_tree {
        using U = internal::to_unsigned_t<T>;
        
    public:
        fenwick_tree() : _n(0) {}
        fenwick_tree(int n) : _n(n), data(n) {}
        
        void add(int p, T x) {
            assert(0 <= p && p < _n);
            p++;
            while (p <= _n) {
                data[p - 1] += U(x);
                p += p & -p;
            }
        }
        
        T sum(int l, int r) {
            assert(0 <= l && l <= r && r <= _n);
            return sum(r) - sum(l);
        }
        
    private:
        int _n;
        std::vector<U> data;
        
        U sum(int r) {
            U s = 0;
            while (r > 0) {
                s += data[r - 1];
                r -= r & -r;
            }
            return s;
        }
    };
    
}  // namespace atcoder


#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
namespace atcoder {
    
    template <class S,
    S (*op)(S, S),
    S (*e)(),
    class F,
    S (*mapping)(F, S),
    F (*composition)(F, F),
    F (*id)()>
    struct lazy_segtree {
    public:
        lazy_segtree() : lazy_segtree(0) {}
        lazy_segtree(int n) : lazy_segtree(std::vector<S>(n, e())) {}
        lazy_segtree(const std::vector<S>& v) : _n(int(v.size())) {
            log = internal::ceil_pow2(_n);
            size = 1 << log;
            d = std::vector<S>(2 * size, e());
            lz = std::vector<F>(size, id());
            for (int i = 0; i < _n; i++) d[size + i] = v[i];
            for (int i = size - 1; i >= 1; i--) {
                update(i);
            }
        }
        
        void set(int p, S x) {
            assert(0 <= p && p < _n);
            p += size;
            for (int i = log; i >= 1; i--) push(p >> i);
            d[p] = x;
            for (int i = 1; i <= log; i++) update(p >> i);
        }
        
        S get(int p) {
            assert(0 <= p && p < _n);
            p += size;
            for (int i = log; i >= 1; i--) push(p >> i);
            return d[p];
        }
        
        S prod(int l, int r) {
            assert(0 <= l && l <= r && r <= _n);
            if (l == r) return e();
            
            l += size;
            r += size;
            
            for (int i = log; i >= 1; i--) {
                if (((l >> i) << i) != l) push(l >> i);
                if (((r >> i) << i) != r) push(r >> i);
            }
            
            S sml = e(), smr = e();
            while (l < r) {
                if (l & 1) sml = op(sml, d[l++]);
                if (r & 1) smr = op(d[--r], smr);
                l >>= 1;
                r >>= 1;
            }
            
            return op(sml, smr);
        }
        
        S all_prod() { return d[1]; }
        
        void apply(int p, F f) {
            assert(0 <= p && p < _n);
            p += size;
            for (int i = log; i >= 1; i--) push(p >> i);
            d[p] = mapping(f, d[p]);
            for (int i = 1; i <= log; i++) update(p >> i);
        }
        void apply(int l, int r, F f) {
            assert(0 <= l && l <= r && r <= _n);
            if (l == r) return;
            
            l += size;
            r += size;
            
            for (int i = log; i >= 1; i--) {
                if (((l >> i) << i) != l) push(l >> i);
                if (((r >> i) << i) != r) push((r - 1) >> i);
            }
            
            {
                int l2 = l, r2 = r;
                while (l < r) {
                    if (l & 1) all_apply(l++, f);
                    if (r & 1) all_apply(--r, f);
                    l >>= 1;
                    r >>= 1;
                }
                l = l2;
                r = r2;
            }
            
            for (int i = 1; i <= log; i++) {
                if (((l >> i) << i) != l) update(l >> i);
                if (((r >> i) << i) != r) update((r - 1) >> i);
            }
        }
        
        template <bool (*g)(S)> int max_right(int l) {
            return max_right(l, [](S x) { return g(x); });
        }
        template <class G> int max_right(int l, G g) {
            assert(0 <= l && l <= _n);
            assert(g(e()));
            if (l == _n) return _n;
            l += size;
            for (int i = log; i >= 1; i--) push(l >> i);
            S sm = e();
            do {
                while (l % 2 == 0) l >>= 1;
                if (!g(op(sm, d[l]))) {
                    while (l < size) {
                        push(l);
                        l = (2 * l);
                        if (g(op(sm, d[l]))) {
                            sm = op(sm, d[l]);
                            l++;
                        }
                    }
                    return l - size;
                }
                sm = op(sm, d[l]);
                l++;
            } while ((l & -l) != l);
            return _n;
        }
        
        template <bool (*g)(S)> int min_left(int r) {
            return min_left(r, [](S x) { return g(x); });
        }
        template <class G> int min_left(int r, G g) {
            assert(0 <= r && r <= _n);
            assert(g(e()));
            if (r == 0) return 0;
            r += size;
            for (int i = log; i >= 1; i--) push((r - 1) >> i);
            S sm = e();
            do {
                r--;
                while (r > 1 && (r % 2)) r >>= 1;
                if (!g(op(d[r], sm))) {
                    while (r < size) {
                        push(r);
                        r = (2 * r + 1);
                        if (g(op(d[r], sm))) {
                            sm = op(d[r], sm);
                            r--;
                        }
                    }
                    return r + 1 - size;
                }
                sm = op(d[r], sm);
            } while ((r & -r) != r);
            return 0;
        }
        
    private:
        int _n, size, log;
        std::vector<S> d;
        std::vector<F> lz;
        
        void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
        void all_apply(int k, F f) {
            d[k] = mapping(f, d[k]);
            if (k < size) lz[k] = composition(f, lz[k]);
        }
        void push(int k) {
            all_apply(2 * k, lz[k]);
            all_apply(2 * k + 1, lz[k]);
            lz[k] = id();
        }
    };
    
}  // namespace atcoder

#include <algorithm>
#include <cassert>
#include <vector>

namespace atcoder {
    
    template <class S, S (*op)(S, S), S (*e)()> struct segtree {
    public:
        segtree() : segtree(0) {}
        segtree(int n) : segtree(std::vector<S>(n, e())) {}
        segtree(const std::vector<S>& v) : _n(int(v.size())) {
            log = internal::ceil_pow2(_n);
            size = 1 << log;
            d = std::vector<S>(2 * size, e());
            for (int i = 0; i < _n; i++) d[size + i] = v[i];
            for (int i = size - 1; i >= 1; i--) {
                update(i);
            }
        }
        
        void set(int p, S x) {
            assert(0 <= p && p < _n);
            p += size;
            d[p] = x;
            for (int i = 1; i <= log; i++) update(p >> i);
        }
        
        S get(int p) {
            assert(0 <= p && p < _n);
            return d[p + size];
        }
        
        S prod(int l, int r) {
            assert(0 <= l && l <= r && r <= _n);
            S sml = e(), smr = e();
            l += size;
            r += size;
            
            while (l < r) {
                if (l & 1) sml = op(sml, d[l++]);
                if (r & 1) smr = op(d[--r], smr);
                l >>= 1;
                r >>= 1;
            }
            return op(sml, smr);
        }
        
        S all_prod() { return d[1]; }
        
        template <bool (*f)(S)> int max_right(int l) {
            return max_right(l, [](S x) { return f(x); });
        }
        template <class F> int max_right(int l, F f) {
            assert(0 <= l && l <= _n);
            assert(f(e()));
            if (l == _n) return _n;
            l += size;
            S sm = e();
            do {
                while (l % 2 == 0) l >>= 1;
                if (!f(op(sm, d[l]))) {
                    while (l < size) {
                        l = (2 * l);
                        if (f(op(sm, d[l]))) {
                            sm = op(sm, d[l]);
                            l++;
                        }
                    }
                    return l - size;
                }
                sm = op(sm, d[l]);
                l++;
            } while ((l & -l) != l);
            return _n;
        }
        
        template <bool (*f)(S)> int min_left(int r) {
            return min_left(r, [](S x) { return f(x); });
        }
        template <class F> int min_left(int r, F f) {
            assert(0 <= r && r <= _n);
            assert(f(e()));
            if (r == 0) return 0;
            r += size;
            S sm = e();
            do {
                r--;
                while (r > 1 && (r % 2)) r >>= 1;
                if (!f(op(d[r], sm))) {
                    while (r < size) {
                        r = (2 * r + 1);
                        if (f(op(d[r], sm))) {
                            sm = op(d[r], sm);
                            r--;
                        }
                    }
                    return r + 1 - size;
                }
                sm = op(d[r], sm);
            } while ((r & -r) != r);
            return 0;
        }
        
    private:
        int _n, size, log;
        std::vector<S> d;
        
        void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
    };
    
}  // namespace atcoder


using T=ll;
using E=ll;

T f(T a,T b){
    return max(a,b);
}

T g(E a,T b){
    return a+b;
}

E h(E a,E b){
    return a+b;
}

T ti(){
    return -INF;
}

E ei(){
    return 0;
}

//区間add,区間min
//ti=INFだが、defを使うなりで初期化を0にすること

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N,Q;cin>>N>>Q;
    vector<T> def(N+1);
    for(int i=1;i<=N;i++) def[i]=i-1;
    
    atcoder::lazy_segtree<T,f,ti,E,g,h,ei> seg(def);
    
    ll ma=0;
    
    while(Q--){
        ll a,b,x;cin>>a>>b>>x;
        chmax(ma,b);
        seg.apply(a,b+1,x);
        cout<<seg.prod(0,ma+1)<<"\n";
    }
}
accuracy: 1
time_ms: 50
memory_kb: 7036
final_rank: 2

code_snippet: // AOJ 2866 Conveyor Belt
// 2014.1.29

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

#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

template <typename T>
T in(T dumy) {
    T n = 0; int c = gc();
//  while (isspace(c)) c = gc();
    if (c == '-') {
        c = gc();
        do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
        return -n;
    }
    do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
    return n;
}

template <typename T>
void out(T n) {
    char b[30];
    if (!n) pc('0');
    else {
        if (n < 0) pc('-'), n = -n;
        int i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
        while (i--) pc(b[i]);
    }
    pc('\n');
}

template <typename T> inline T Max(const T a, const T b) { return a >= b? a: b; }
template <typename T> inline T Min(const T a, const T b) { return a <= b? a: b; }
template <typename T> inline void chmax(T &a, const T b) { if (a < b) a = b; }

int const MAX = (1<<17)+5;
ll maxa[2*MAX], adda[2*MAX];

inline void add(int x, ll num) { maxa[x] += num, adda[x] += num; }
inline void pd(int x) { add(x << 1, adda[x]), add((x << 1)|1, adda[x]), adda[x] = 0; }

void build(int x, int l, int r) {
    if (l == r) { maxa[x] = l - 1; return; }
    int mid = (l+r) >> 1;
    build(x << 1, l, mid), build((x << 1)|1, mid+1, r);
    maxa[x] = Max(maxa[x << 1], maxa[(x << 1)|1]);
}

void update(int x, int l, int r, int i, int j, ll num) {
    if (i <= l && r <= j) { add(x, num); return; }
    if (adda[x]) pd(x);
    int mid = (l+r) >> 1;
    if (i <= mid) update(x << 1, l, mid, i, j, num);
    if (j > mid) update((x << 1)|1, mid+1, r, i, j, num);
    maxa[x] = Max(maxa[x << 1], maxa[(x << 1)|1]);
}

ll getMax(int x, int l, int r, int i, int j) {
    if (i <= l && r <= j) return maxa[x];
    if (adda[x]) pd(x);
    ll ans = 0;
    int mid = (l+r) >> 1;
    if (i <= mid) chmax(ans, getMax(x << 1, l, mid, i, j));
    if (j > mid) chmax(ans, getMax((x << 1)|1, mid+1, r, i, j));
    return ans;
}

int N;
int main() {
    N = in(1);
    int Q = in(1);
    ll bma = 1;
    build(1, 1, N);
    while (Q--) {
        int a = in(1), b = in(1), p = in(1);
        chmax(bma, (ll)b);
        update(1, 1, N, a, b, p);
        out(getMax(1, 1, N, 1, bma));
    }
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 7528
final_rank: 1

code_snippet: // AOJ 2866 Conveyor Belt
// 2014.1.29

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

#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

template <typename T>
T in(T dumy) {
    T n = 0; int c = gc();
    while (isspace(c)) c = gc();
    if (c == '-') {
        c = gc();
        do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
        return -n;
    }
    do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
    return n;
}

template <typename T>
void out(T n) {
    char b[30];
    if (!n) pc('0');
    else {
        if (n < 0) pc('-'), n = -n;
        int i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
        while (i--) pc(b[i]);
    }
    pc('\n');
}

template <typename T> inline T Max(const T a, const T b) { return a >= b? a: b; }
template <typename T> inline T Min(const T a, const T b) { return a <= b? a: b; }
template <typename T> inline void chmax(T &a, const T b) { if (a < b) a = b; }

int const MAX = (1<<17)+5;
ll maxa[4*MAX], adda[4*MAX];

inline void add(int x, ll num) { maxa[x] += num, adda[x] += num; }
inline void pd(int x) { add(x << 1, adda[x]), add((x << 1)|1, adda[x]), adda[x] = 0; }

void build(int x, int l, int r) {
    if (l == r) { maxa[x] = l - 1; return; }
    int mid = (l+r) >> 1;
    build(x << 1, l, mid), build((x << 1)|1, mid+1, r);
    maxa[x] = Max(maxa[x << 1], maxa[(x << 1)|1]);
}

void update(int x, int l, int r, int i, int j, ll num) {
    if (i <= l && r <= j) { add(x, num); return; }
    if (adda[x]) pd(x);
    int mid = (l+r) >> 1;
    if (i <= mid) update(x << 1, l, mid, i, j, num);
    if (j > mid) update((x << 1)|1, mid+1, r, i, j, num);
    maxa[x] = Max(maxa[x << 1], maxa[(x << 1)|1]);
}

ll getMax(int x, int l, int r, int i, int j) {
    if (i <= l && r <= j) return maxa[x];
    if (adda[x]) pd(x);
    ll ans = 0;
    int mid = (l+r) >> 1;
    if (i <= mid) chmax(ans, getMax(x << 1, l, mid, i, j));
    if (j > mid) chmax(ans, getMax((x << 1)|1, mid+1, r, i, j));
    return ans;
}

int N;
int main() {
    N = in(1);
    int Q = in(1);
    ll bma = 1;
    build(1, 1, N);
    while (Q--) {
        int a = in(1), b = in(1), p = in(1);
        chmax(bma, (ll)b);
        update(1, 1, N, a, b, p);
        out(getMax(1, 1, N, 1, bma));
    }
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 11612
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;

#define foa(s, v) for(auto &s : v)
#define all(v)    v.begin(), v.end()
#define sz(v)     int(v.size())
#define rep(i, n) for(int i = 0; i < int(n); i++)

template <class T>
bool chmin(T &a, T b) { return a > b ? a = b, 1 : 0; }
template <class T>
bool chmax(T &a, T b) { return a < b ? a = b, 1 : 0; }

string strmax(string &a, string &b) {
	if(a[0] == '-') return b;
	if(b[0] == '-') return a;
	if(sz(a) < sz(b)) return b;
	if(sz(a) > sz(b)) return a;
	return max(a, b);
}

const ll mod = 1000000007;

ll modpow(ll b, ll e) {
	ll ans = 1;
	for(; e; b = b * b % mod, e /= 2)
		if(e & 1) ans = ans * b % mod;
	return ans;
}

int matInv(V<V<ll>> &A) {
	int n = sz(A);
	V<int> col(n);
	V<V<ll>> tmp(n, V<ll>(n));
	rep(i, n) tmp[i][i] = 1, col[i] = i;
	rep(i, n) {
		int r = i, c = i;
		for(int j = i; j < n; j++) {
			for(int k = i; k < n; k++) {
				if(A[j][k]) {
					r = j;
					c = k;
					goto found;
				}
			}
		}
		return i;
	found:
		A[i].swap(A[r]);
		tmp[i].swap(tmp[r]);
		rep(j, n) swap(A[j][i], A[j][c]), swap(tmp[j][i], tmp[j][c]);
		swap(col[i], col[c]);
		ll v = modpow(A[i][i], mod - 2);
		for(int j = i + 1; j < n; j++) {
			ll f = A[j][i] * v % mod;
			A[j][i] = 0;
			for(int k = i + 1; k < n; k++) A[j][k] = (A[j][k] - f * A[i][k]) % mod;
			rep(k, n) tmp[j][k] = (tmp[j][k] - f * tmp[i][k]) % mod;
		}
		for(int j = i + 1; j < n; j++) A[i][j] = A[i][j] * v % mod;
		rep(j, n) tmp[i][j] = tmp[i][j] * v % mod;
		A[i][i] = 1;
	}
	for(int i = n - 1; i > 0; --i) rep(j, i) {
			ll v = A[j][i];
			rep(k, n) tmp[j][k] = (tmp[j][k] - v * tmp[i][k]) % mod;
		}
	rep(i, n) rep(j, n)
	    A[col[i]][col[j]] = tmp[i][j] % mod + (tmp[i][j] < 0 ? mod : 0);
	return n;
}

vector<pair<int, int>> general_matching(int N, vector<pair<int, int>> &ed) {
	if(sz(ed) == 0) return {};
	V<V<ll>> mat(N, V<ll>(N)), A;
	for(pair<int, int> pa : ed) {
		int a = pa.first, b = pa.second, r = rand() % mod;
		mat[a][b] = r, mat[b][a] = (mod - r) % mod;
	}
	int r = matInv(A = mat), M = 2 * N - r, fi, fj;
	assert(r % 2 == 0);
	if(M != N) do {
			mat.resize(M, V<ll>(M));
			rep(i, N) {
				mat[i].resize(M);
				for(int j = N; j < M; j++) {
					int r = rand() % mod;
					mat[i][j] = r, mat[j][i] = (mod - r) % mod;
				}
			}
		} while(matInv(A = mat) != M);

	V<int> has(M, 1);
	V<pair<int, int>> ret;
	rep(it, M / 2) {
		rep(i, M) if(has[i]) for(int j = i + 1; j < M; j++) if(A[i][j] && mat[i][j]) {
			fi = i;
			fj = j;
			goto done;
		}
		assert(0);
	done:
		if(fj < N) ret.emplace_back(fi, fj);
		has[fi] = has[fj] = 0;
		rep(sw, 2) {
			ll a = modpow(A[fi][fj], mod - 2);
			rep(i, M) if(has[i] && A[i][fj]) {
				ll b = A[i][fj] * a % mod;
				rep(j, M) A[i][j] = (A[i][j] - A[fi][j] * b) % mod;
			}
			swap(fi, fj);
		}
	}
	return ret;
}


using S = ll;
using F = ll;
const S INF = 1ll << 60;
S e = -INF;
S op(S a, S b) { return max(a, b); }
const F id = 0ll;
F composition(F f, F g) { return f + g; }
F mapping(F f, S s) { return f + s; }
const S replaced = -INF - 100;


S power(S s, ll n) {
	return n == 0 ? e : s;
}

struct node {
	node *l = 0, *r = 0;
	ll lo, hi;
	S mset = replaced, val = e;
	F mapp = id;

	node(ll lo, ll hi) : lo(lo), hi(hi) {}

	~node() {
		if(l) {
			delete l;
			delete r;
		}
	}

	node(V<S> &v, ll lo, ll hi) : lo(lo), hi(hi) {
		if(lo + 1 < hi) {
			ll mid = lo + (hi - lo) / 2;
			l = new node(v, lo, mid);
			r = new node(v, mid, hi);
			val = op(l->val, r->val);
		} else
			val = v[lo];
	}

	S prod(ll L, ll R) {
		if(R <= lo || hi <= L) return e;
		if(L <= lo && hi <= R) return val;
		push();
		return op(l->prod(L, R), r->prod(L, R));
	}

	S all_prod() { return prod(lo, hi); }

	void set(ll L, ll R, S s) {
		if(R <= lo || hi <= L) return;
		if(L <= lo && hi <= R) {
			mset = s, mapp = id;
			val = power(s, hi - lo);
		} else {
			push(), l->set(L, R, s), r->set(L, R, s);
			val = op(l->val, r->val);
		}
	}

	void apply(ll L, ll R, F f) {
		if(R <= lo || hi <= L) return;
		if(L <= lo && hi <= R) {
			if(mset != replaced)
				mset = mapping(f, mset);
			else
				mapp = composition(f, mapp);
			val = mapping(f, val);
			return;
		}
		push(), l->apply(L, R, f), r->apply(L, R, f);
		val = op(l->val, r->val);
	}

	void push() {
		if(!l) {
			ll mid = lo + (hi - lo) / 2;
			l = new node(lo, mid), r = new node(mid, hi);
		}
		if(mset != replaced)
			l->set(lo, hi, mset), r->set(lo, hi, mset), mset = replaced;
		else if(mapp != id)
			l->apply(lo, hi, mapp), r->apply(lo, hi, mapp), mapp = id;
	}
};


void solve() {
	int n, q;
	cin >> n >> q;
	node *seg = new node(0, n);
	seg->set(0, n, 0);
	int now_time = 0;
	rep(i, q) {
		ll a, b, p;
		cin >> a >> b >> p;
		--a;
		seg->apply(a, b, p);
		while(now_time < n - 1 and seg->all_prod() > now_time) {
			seg->apply(++now_time, n, 1);
		}
		cout << seg->all_prod() << endl;
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
}
accuracy: 1
time_ms: 140
memory_kb: 15876
final_rank: 11

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

class segtree {
private:
	int sz;
	vector<long long> val;
	vector<long long> lazy;
	void push(int k) {
		if (lazy[k] != 0) {
			val[k] += lazy[k];
			if (k < sz) {
				lazy[k * 2] += lazy[k];
				lazy[k * 2 + 1] += lazy[k];
			}
			lazy[k] = 0;
		}
	}
	void rangeadd(int a, int b, int k, int l, int r, long long x) {
		push(k);
		if (r <= a || b <= l) return;
		if (a <= l && r <= b) {
			lazy[k] += x;
			push(k);
			return;
		}
		rangeadd(a, b, k * 2, l, (l + r) >> 1, x);
		rangeadd(a, b, k * 2 + 1, (l + r) >> 1, r, x);
		val[k] = max(val[k * 2], val[k * 2 + 1]);
	}
	long long rangemax(int a, int b, int k, int l, int r) {
		push(k);
		if (r <= a || b <= l) return 0;
		if (a <= l && r <= b) return val[k];
		long long lc = rangemax(a, b, k * 2, l, (l + r) >> 1);
		long long rc = rangemax(a, b, k * 2 + 1, (l + r) >> 1, r);
		val[k] = max(val[k * 2], val[k * 2 + 1]);
		return max(lc, rc);
	}
public:
	segtree() : sz(0), val(vector<long long>()), lazy(vector<long long>()) {}
	segtree(int n) {
		sz = 1;
		while (sz < n) {
			sz *= 2;
		}
		val = vector<long long>(sz * 2, 0);
		lazy = vector<long long>(sz * 2, 0);
	}
	void rangeadd(int l, int r, long long x) {
		rangeadd(l, r, 1, 0, sz, x);
	}
	long long rangemax(int l, int r) {
		return rangemax(l, r, 1, 0, sz);
	}
};

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N, Q;
	cin >> N >> Q;
	segtree seg(N);
	for (int i = 0; i < N; i++) {
		seg.rangeadd(i, i + 1, i);
	}
	long long answer = 0;
	for (int i = 0; i < Q; i++) {
		int a, b; long long p;
		cin >> a >> b >> p;
		a -= 1;
		seg.rangeadd(a, b, p);
		answer = max(answer, seg.rangemax(a, b));
		cout << answer << '\n';
	}
	return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 7312
final_rank: 7

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 SIZE 100005


int N;
ll max_data[SIZE*8],add_data[SIZE*8];

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;
			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 getMax(int left,int right,int node_id,int node_left,int node_right){
	if(right < node_left || left > node_right)return -HUGE_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,Q;
	scanf("%d %d",&first_N,&Q);

	N = 1;
	init(first_N);

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

	int from,to;
	ll num;

	int tmp = 0;

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

		scanf("%d %d %lld",&from,&to,&num);
		from--;
		to--;

		while(tmp < to){
			tmp++;
			add(tmp,N-1,1,0,0,N-1);
		}

		add(from,to,num,0,0,N-1);
		printf("%lld\n",getMax(0,N-1,0,0,N-1));
	}

	return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 7336
final_rank: 10

code_snippet: #include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define ll long long
#define lc (now<<1)
#define rc (now<<1|1)
using namespace std;
const int N=1e5+100;
int n,Q,r; 
ll tag[N<<2],mx[N<<2];
void add(int now,int l,int r,int x,int y,int v)
{
	if (x<=l&&r<=y)
	{
		tag[now]+=v; 
		mx[now]+=v; 
		return;
	}
	int mid=l+r>>1;
	if (x<=mid) add(lc,l,mid,x,y,v);
	if (y>mid) add(rc,mid+1,r,x,y,v);
	mx[now]=max(mx[lc],mx[rc])+tag[now];
}
int main(){
	scanf("%d%d",&n,&Q);
	r=1;
	while (Q--)
	{
		int x,y,w; 
		scanf("%d%d%d",&x,&y,&w);
		while (r<y) 
			add(1,1,n,++r,n,1);
		add(1,1,n,x,y,w);
		printf("%lld\n",mx[1]);
	}
	return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 7320
final_rank: 4

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll in()
{
    ll re=0,f=1;char x=getchar();
    while(x<'0'||x>'9'){if(x=='-')f=-1;x=getchar();}
    while(x>='0'&&x<='9')re=re*10+x-48,x=getchar();
    return re*f;
}
void out(ll x)
{
    if(x<0)putchar('-'),x=-x;
    if(!x){putchar('0');return;}
    char z[21],ct=0;
    while(x){z[++ct]=x%10+48,x/=10;}
    while(ct){putchar(z[ct]);--ct;}
}
struct node{
    int ls,rs;
    ll mx,tag;
};
struct segtree{
    int rt,ptr;
    node nd[1000010];
    void pushdown(int c)
    {
    	int L=nd[c].ls;
    	int R=nd[c].rs;
    	nd[L].mx+=nd[c].tag;
		nd[R].mx+=nd[c].tag; 
    	nd[L].tag+=nd[c].tag;
    	nd[R].tag+=nd[c].tag;
    	nd[c].tag=0;
	}
    void build(int &c,int l,int r)
    {
        c=++ptr;
        if(l==r)
        {
            nd[c].mx=l-1;
            return;
        }
        int mid=l+r>>1;
        build(nd[c].ls,l,mid);
        build(nd[c].rs,mid+1,r);
        nd[c].mx=max(nd[nd[c].ls].mx,nd[nd[c].rs].mx);
    }
    void modify(int c,int l,int r,int ql,int qr,ll v)
    {
		if(l==ql&&r==qr)
		{
		   nd[c].mx+=v;
		   nd[c].tag+=v;
		   return;
		}
		pushdown(c);
		int mid=l+r>>1;
		if(qr<=mid)modify(nd[c].ls,l,mid,ql,qr,v);
		else if(ql>mid)modify(nd[c].rs,mid+1,r,ql,qr,v);
		else
		{
			modify(nd[c].ls,l,mid,ql,mid,v);
			modify(nd[c].rs,mid+1,r,mid+1,qr,v);
		}
		nd[c].mx=max(nd[nd[c].ls].mx,nd[nd[c].rs].mx);
    }
    ll query(int c,int l,int r,int ql,int qr)
    {
		if(l==ql&&r==qr)return nd[c].mx;
		pushdown(c);
		int mid=l+r>>1;
		if(qr<=mid)return query(nd[c].ls,l,mid,ql,qr);
		if(ql>mid)return query(nd[c].rs,mid+1,r,ql,qr);
		return max(query(nd[c].ls,l,mid,ql,mid),query(nd[c].rs,mid+1,r,mid+1,qr));
	}
}tr;
int n,Q;
int main()
{
	n=in();Q=in();
	tr.build(tr.rt,1,n);
	ll mxr=0;
	for(int i=1;i<=Q;++i)
	{
		ll l=in(),r=in(),w=in();
		mxr=max(mxr,r);
		tr.modify(tr.rt,1,n,l,r,w);
		out(tr.query(tr.rt,1,n,1,mxr));
		putchar('\n');
	}
}
accuracy: 1
time_ms: 50
memory_kb: 7776
final_rank: 5

code_snippet: #include <bits/stdc++.h>
#define int long long 
#define N 100500
using namespace std;
int n,m,mx[N<<2],lz[N<<2];
void upd(int rt,int x){
	mx[rt]+=x;lz[rt]+=x;
}
void pushup(int rt){
	mx[rt]=max(mx[rt<<1],mx[rt<<1|1]);
}
void pushdown(int rt){
	if(lz[rt]){
		upd(rt<<1,lz[rt]);
		upd(rt<<1|1,lz[rt]);
		lz[rt]=0;
	}
}
void build(int rt,int l,int r){
	if(l==r){mx[rt]=l-1;return ;}
	int mid=(l+r)>>1;
	build(rt<<1,l,mid);
	build(rt<<1|1,mid+1,r);
	pushup(rt);
}
void update(int rt,int l,int r,int x,int y,int v){
	if(x<=l&&r<=y){upd(rt,v);return ;}
	pushdown(rt);
	int mid=(l+r)>>1;
	if(x<=mid)update(rt<<1,l,mid,x,y,v);
	if(y>mid)update(rt<<1|1,mid+1,r,x,y,v);
	pushup(rt);
}
int query(int rt,int l,int r,int x,int y){
	if(x<=l&&r<=y)return mx[rt];
	pushdown(rt);
	int mid=(l+r)>>1;
	if(y<=mid)return query(rt<<1,l,mid,x,y);
	if(x>mid)return query(rt<<1|1,mid+1,r,x,y);
	return max(query(rt<<1,l,mid,x,y),query(rt<<1|1,mid+1,r,x,y));
}
signed main(){
	scanf("%lld%lld",&n,&m);
	build(1,1,n);
	for(int i=1,x,y,v,r=0;i<=m;i++){
		scanf("%lld%lld%lld",&x,&y,&v);
		r=max(r,y);
		update(1,1,n,x,y,v);
		printf("%lld\n",query(1,1,n,1,r));
	}
	return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 7308
final_rank: 6

code_snippet: #include <iostream>
#include <cstdio>
#define ll long long
using namespace std;
ll mx[200001<<2],tag[200001<<2];
int n,m,rr,q;

inline void change(int rt,int l,int r,int L,int R,int k)
{
	if(L<=l && r<=R)
	{
		mx[rt]+=k; tag[rt]+=k;
		return;
	}
	int mid=l+r>>1;
	if(L<=mid) change(rt<<1,l,mid,L,R,k);
	if(R>mid) change(rt<<1|1,mid+1,r,L,R,k);
	mx[rt]=max(mx[rt<<1],mx[rt<<1|1])+tag[rt];
}

int main()
{
	scanf("%d%d",&n,&q);
	int rr=1,x,y,k;
	for(int i=1;i<=q;i++)
	{
		scanf("%d%d%d",&x,&y,&k);
		while(rr<y) change(1,1,n,++rr,n,1);
		change(1,1,n,x,y,k);
		printf("%lld\n",mx[1]);
	}
}
accuracy: 1
time_ms: 50
memory_kb: 7308
final_rank: 3