結果

問題 No.631 Noelちゃんと電車旅行
ユーザー lumc_lumc_
提出日時 2018-01-01 20:06:10
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 391 ms / 2,000 ms
コード長 1,383 bytes
コンパイル時間 776 ms
コンパイル使用メモリ 58,536 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-10 07:41:02
合計ジャッジ時間 6,894 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 289 ms
6,816 KB
testcase_01 AC 383 ms
6,940 KB
testcase_02 AC 381 ms
6,944 KB
testcase_03 AC 375 ms
6,944 KB
testcase_04 AC 380 ms
6,940 KB
testcase_05 AC 391 ms
6,944 KB
testcase_06 AC 151 ms
6,940 KB
testcase_07 AC 79 ms
6,944 KB
testcase_08 AC 279 ms
6,940 KB
testcase_09 AC 331 ms
6,940 KB
testcase_10 AC 225 ms
6,944 KB
testcase_11 AC 208 ms
6,940 KB
testcase_12 AC 256 ms
6,940 KB
testcase_13 AC 247 ms
6,948 KB
testcase_14 AC 112 ms
6,944 KB
testcase_15 AC 209 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,940 KB
testcase_20 AC 2 ms
6,940 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[rN*rN];
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