結果

問題 No.631 Noelちゃんと電車旅行
ユーザー lumc_lumc_
提出日時 2018-01-01 20:03:58
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,379 bytes
コンパイル時間 786 ms
コンパイル使用メモリ 61,216 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-24 15:41:30
合計ジャッジ時間 8,904 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 280 ms
4,380 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 148 ms
4,384 KB
testcase_07 AC 76 ms
4,384 KB
testcase_08 AC 268 ms
4,384 KB
testcase_09 AC 328 ms
4,380 KB
testcase_10 AC 224 ms
4,384 KB
testcase_11 AC 199 ms
4,384 KB
testcase_12 AC 251 ms
4,384 KB
testcase_13 AC 244 ms
4,384 KB
testcase_14 AC 115 ms
4,380 KB
testcase_15 AC 204 ms
4,384 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,384 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>

// 平方分割解
// O(MN^.5)
// 2sなら間に合うかな~

using namespace std;

using ll = long long;
const ll LINF = 1e18;
const int N = 1e5;
const int rN = 317;

ll data[N];
ll rdata[rN];
ll all[rN];

// [a, b]
void add(int a, int b, int x) {
	int ag = (a + rN - 1) / rN;
	int bg = (b - rN + 1 + rN) / rN - 1; // 0の方へ丸まるので
	for(int i=ag;i<=bg;i++) {
		all[i] += x;
	}
	if(ag > bg) {
		for(int i=a;i<=b;i++) {
			data[i] += x;
			rdata[i/rN] = max(rdata[i/rN], data[i]);
		}
		return;
	}
	for(int i=a;i<ag*rN;i++) {
		data[i] += x;
		rdata[i/rN] = max(rdata[i/rN], data[i]);
	}
	for(int i=(bg+1)*rN;i<=b;i++) {
		data[i] += x;
		rdata[i/rN] = max(rdata[i/rN], data[i]);
	}
}

// 全域しかないのでさぼる!w
// [0, b]
ll getMax(int b) {
	int bg = (b + rN - 1) / rN;
	ll res = -LINF;
	for(int i=0;i<=bg;i++) {
		res = max(res, rdata[i] + all[i]);
	}
	return res;
}

int main() {
	int n; cin >> n; n--;
	int ng = (n + rN) / rN;
	for(int i=0;i<n;i++) cin >> data[i], data[i] += (n - i) * 3;
	for(int i=n;i<ng*rN;i++) {
		data[i] = -LINF;
	}
	for(int i=0;i<ng*rN;i+=rN) {
		ll res = -LINF;
		for(int j=i;j<i+rN;j++) {
			res = max(res, data[j]);
		}
		rdata[i/rN] = res;
	}
	int q; cin >> q;
	for(int i=0;i<q;i++) {
		int a, b, x; cin >> a >> b >> x;
		add(a-1, b-1, x);
		cout << getMax(n) << endl;
	}
}

0