結果
| 問題 | No.631 Noelちゃんと電車旅行 | 
| コンテスト | |
| ユーザー |  moko_freedom | 
| 提出日時 | 2018-01-11 22:12:52 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 291 ms / 2,000 ms | 
| コード長 | 1,880 bytes | 
| コンパイル時間 | 1,654 ms | 
| コンパイル使用メモリ | 169,120 KB | 
| 実行使用メモリ | 8,960 KB | 
| 最終ジャッジ日時 | 2024-10-02 09:35:24 | 
| 合計ジャッジ時間 | 6,792 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 21 | 
ソースコード
#include <bits/stdc++.h>
//#include <math.h>
using namespace std;
#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<int,P> PP;
struct edge {
	int to, cost;
	edge(int t,int c):to(t),cost(c) {}
};
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
//-----------------------------------------------------------------------------
struct LazySegTree {
	int z;
	vector<ll> node,lazy;
	LazySegTree(vector<ll> v) {
		int sz=(int)v.size();
		z=1; while(z<sz) z*=2;
		node.resize(2*z-1);
		lazy.resize(2*z-1,0);
		REP(i,sz) node[i+z-1]=v[i];
		for(int i=z-2;i>=0;i--) node[i]=max(node[i*2+1],node[i*2+2]);
	}
	void eval(int k,int l,int r) {
		if(lazy[k]!=0) {
			node[k]+=lazy[k];
			if(r-l>1) {
				lazy[2*k+1]+=lazy[k];
				lazy[2*k+2]+=lazy[k];
			}
			lazy[k]=0;
		}
	}
	void add(int a,int b,ll x,int k=0,int l=0,int r=-1) {
		if(r<0) r=z;
		eval(k,l,r);
		if(b<=l||r<=a) return;
		if(a<=l&&r<=b) {
			lazy[k]+=x;
			eval(k,l,r);
		}
		else {
			add(a,b,x,2*k+1,l,(l+r)/2);
			add(a,b,x,2*k+2,(l+r)/2,r);
			node[k]=max(node[2*k+1],node[2*k+2]);
		}
	}
	ll getmax(int a,int b,int k=0,int l=0,int r=-1) {
		if(r<0) r=z;
		eval(k,l,r);
		if(b<=l||r<=a) return -INF;
		if(a<=l&&r<=b) return node[k];
		ll vl=getmax(a,b,2*k+1,l,(l+r)/2);
		ll vr=getmax(a,b,2*k+2,(l+r)/2,r);
		return max(vr,vl);
	}
};
int n,m;
vector<ll> t;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin>>n;
	t.resize(n-1);
	REP(i,n-1) {
		cin>>t[i];t[i]+=3*(n-i-1);
	}
	LazySegTree seg(t);
	cin>>m;
	REP(i,m) {
		int l,r;ll d;
		cin>>l>>r>>d;
		seg.add(l-1,r,d);
		cout<<seg.getmax(0,n)<<endl;
	}
	return 0;
}
            
            
            
        