結果

問題 No.631 Noelちゃんと電車旅行
ユーザー mokomoko
提出日時 2018-01-11 22:12:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 296 ms / 2,000 ms
コード長 1,880 bytes
コンパイル時間 1,496 ms
コンパイル使用メモリ 168,928 KB
実行使用メモリ 8,832 KB
最終ジャッジ日時 2024-04-10 07:51:07
合計ジャッジ時間 6,795 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 222 ms
6,816 KB
testcase_01 AC 286 ms
8,832 KB
testcase_02 AC 293 ms
8,832 KB
testcase_03 AC 282 ms
8,832 KB
testcase_04 AC 296 ms
8,832 KB
testcase_05 AC 286 ms
8,704 KB
testcase_06 AC 112 ms
6,940 KB
testcase_07 AC 53 ms
6,940 KB
testcase_08 AC 207 ms
8,320 KB
testcase_09 AC 269 ms
6,940 KB
testcase_10 AC 172 ms
8,192 KB
testcase_11 AC 151 ms
6,944 KB
testcase_12 AC 190 ms
8,704 KB
testcase_13 AC 193 ms
6,944 KB
testcase_14 AC 90 ms
6,940 KB
testcase_15 AC 162 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,948 KB
権限があれば一括ダウンロードができます

ソースコード

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];
				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;
}
0