結果

問題 No.631 Noelちゃんと電車旅行
ユーザー gazellegazelle
提出日時 2018-01-05 22:58:03
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 274 ms / 2,000 ms
コード長 2,099 bytes
コンパイル時間 1,365 ms
コンパイル使用メモリ 113,148 KB
実行使用メモリ 8,832 KB
最終ジャッジ日時 2024-04-10 07:45:38
合計ジャッジ時間 6,379 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 210 ms
6,812 KB
testcase_01 AC 269 ms
8,832 KB
testcase_02 AC 274 ms
8,832 KB
testcase_03 AC 265 ms
8,832 KB
testcase_04 AC 272 ms
8,832 KB
testcase_05 AC 268 ms
8,832 KB
testcase_06 AC 108 ms
6,940 KB
testcase_07 AC 52 ms
6,940 KB
testcase_08 AC 195 ms
8,576 KB
testcase_09 AC 252 ms
6,944 KB
testcase_10 AC 170 ms
8,320 KB
testcase_11 AC 153 ms
6,944 KB
testcase_12 AC 180 ms
8,704 KB
testcase_13 AC 192 ms
6,940 KB
testcase_14 AC 92 ms
6,940 KB
testcase_15 AC 163 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,940 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<bitset>
#include<random>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

struct LazySegmentTree {
private:
	int n;
	vector<ll> node, lazy;

public:
	LazySegmentTree(vector<ll> v) {
		int sz = (int)v.size();
		n = 1; while(n < sz) n *= 2;
		node.resize(2*n-1);
		lazy.resize(2*n-1, 0);

		for(int i=0; i<sz; i++) node[i+n-1] = v[i];
		for(int i=n-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 = n;
		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 find(int a, int b, int k=0, int l=0, int r=-1) {
		if(r < 0) r = n;
		eval(k, l, r);
		if(b <= l || r <= a) return -INF*INF;
		if(a <= l && r <= b) return node[k];
		ll vl = find(a, b, 2*k+1, l, (l+r)/2);
		ll vr = find(a, b, 2*k+2, (l+r)/2, r);
		return max(vl,vr);
	}
};
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vector<ll> t(n);
	REP(i,n-1) cin>>t[i];
	REP(i,n-1) t[i]-=i*3;
	t[n-1]=-INF*INF;
	LazySegmentTree seg(t);
	ll m;
	cin>>m;
	REP(roop,m) {
		ll l,r,d;
		cin>>l>>r>>d;
		l--;
		r--;
		seg.add(l,r+1,d);
		ll dirr=seg.find(0,n);
		cout<<3*(n-1)+max(0ll,dirr)<<endl;
	}
}
0