結果

問題 No.631 Noelちゃんと電車旅行
ユーザー mokomoko
提出日時 2018-01-11 22:06:32
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,884 bytes
コンパイル時間 2,542 ms
コンパイル使用メモリ 157,696 KB
実行使用メモリ 8,888 KB
最終ジャッジ日時 2023-08-25 04:08:23
合計ジャッジ時間 7,344 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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]/2;
				lazy[2*k+2]+=lazy[k]/2;
			}
			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;
}
0