結果

問題 No.631 Noelちゃんと電車旅行
ユーザー ふっぴーふっぴー
提出日時 2018-02-19 18:52:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 386 ms / 2,000 ms
コード長 2,869 bytes
コンパイル時間 1,918 ms
コンパイル使用メモリ 169,776 KB
実行使用メモリ 9,856 KB
最終ジャッジ日時 2024-04-10 07:53:00
合計ジャッジ時間 8,346 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 274 ms
6,816 KB
testcase_01 AC 384 ms
9,728 KB
testcase_02 AC 380 ms
9,728 KB
testcase_03 AC 379 ms
9,728 KB
testcase_04 AC 386 ms
9,856 KB
testcase_05 AC 379 ms
9,728 KB
testcase_06 AC 150 ms
6,940 KB
testcase_07 AC 81 ms
6,944 KB
testcase_08 AC 280 ms
9,216 KB
testcase_09 AC 331 ms
6,944 KB
testcase_10 AC 230 ms
9,088 KB
testcase_11 AC 209 ms
6,944 KB
testcase_12 AC 265 ms
9,216 KB
testcase_13 AC 242 ms
6,944 KB
testcase_14 AC 115 ms
6,944 KB
testcase_15 AC 214 ms
6,944 KB
testcase_16 AC 2 ms
6,944 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 3 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
const int inf = 1000000001;
const ll INF = 2e18 * 2;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };



class LazySegmentTree {
public:
	int n;
	vl node, lazy;
	bool ismax; //trueなら最大値、falseなら最小値

	LazySegmentTree(vl a, bool _ismax) {
		ismax = _ismax;
		int _n = a.size();
		n = 1; while (n < _n) n *= 2;
		node.resize(2 * n - 1, INF * (1 - (int)ismax * 2) );
		lazy.resize(2 * n - 1, 0);
		for (int i = 0; i < _n; i++) node[i + n - 1] = a[i];
		for (int i = n - 2; i >= 0; i--) {
			if (ismax) node[i] = max(node[i * 2 + 1], node[i * 2 + 2]);
			else node[i] = min(node[i * 2 + 1], node[i * 2 + 2]);
		}
	}

	// k番目のノードについて遅延評価を行う
	inline 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, int l, int r) {
		// k 番目のノードに対して遅延評価を行う
		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);
			if (ismax) node[k] = max(node[2 * k + 1], node[2 * k + 2]);
			else node[k] = min(node[2 * k + 1], node[2 * k + 2]);
		}
	}

	ll getmax(int a, int b, int k, int l, int r) {
		eval(k, l, r);
		if (b <= l || r <= a) return 0;
		if (a <= l && r <= b) return node[k];
		ll resl = getmax(a, b, 2 * k + 1, l, (l + r) / 2);
		ll resr = getmax(a, b, 2 * k + 2, (l + r) / 2, r);
		if (ismax) return max(resl, resr);
		else return min(resl, resr);
	}

};




int main() {
	int i, j, n;
	cin >> n;
	n--;
	vl a(n);
	vl t(n);
	for (i = 0; i < n; i++) {
		cin >> t[i];
		a[i] = t[i] - 3 * i;
	}
	LazySegmentTree lst(a, true);
	int m;
	cin >> m;
	for (int unko = 0; unko < m; unko++) {
		ll l, r, d;
		cin >> l >> r >> d;
		l--; r--;
		lst.add(l, r + 1, d, 0, 0, lst.n);
		cout << 3 * n + lst.getmax(0, lst.n, 0, 0, lst.n) << endl;
	}
}
0