結果

問題 No.865 24時間降水量
ユーザー MarcusAureliusAntoninusMarcusAureliusAntoninus
提出日時 2019-08-16 22:13:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,613 bytes
コンパイル時間 2,103 ms
コンパイル使用メモリ 204,336 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 00:12:33
合計ジャッジ時間 6,267 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 8 ms
4,348 KB
testcase_06 AC 7 ms
4,348 KB
testcase_07 AC 8 ms
4,348 KB
testcase_08 AC 8 ms
4,348 KB
testcase_09 AC 8 ms
4,348 KB
testcase_10 AC 59 ms
4,348 KB
testcase_11 AC 60 ms
4,348 KB
testcase_12 AC 59 ms
4,348 KB
testcase_13 AC 59 ms
4,348 KB
testcase_14 AC 59 ms
4,348 KB
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

///////////////////////////
// Range Sum Query (BIT) //
///////////////////////////

class RSumQBIT {
private:
	std::vector<int64_t> container_;

	int64_t getHelper(const int index) const
	{
		if (index < 0) return 0;
		if ((int)(container_.size()) <= index) return container_.back();
		int64_t sum{};
		for (int add_place{index}; add_place > 0; add_place -= add_place & -add_place)
			sum += container_[add_place];
		return sum;
	}

public:
	RSumQBIT(const int array_size)
		: container_(array_size + 1) {}
	// indexは0-indexed
	void update(const int index, const int64_t added)
	{
		for (int update_place{index + 1}; update_place < (int)(container_.size()); update_place += update_place & -update_place)
			container_[update_place] += added;
	}
	// left,rightは0-indexed、[left, right)の半開区間
	int64_t get(const int left, const int right) const
	{
		return -getHelper(left) + getHelper(right);
	}
};

int main()
{
	int N;
	scanf("%d", &N);
	std::vector<int64_t> A(N);
	for (auto& e: A) scanf("%lld", &e);
	RSumQBIT rsq(N);
	for (int i{}; i < N; i++)
		rsq.update(i, A[i]);

	std::vector<int64_t> sum(N + 1);
	for (int i{}; i < N; i++)
		sum[i + 1] = sum[i] + A[i];
	int64_t max{};
	for (int i{}; i + 24 <= N; i++)
		max = std::max(max, sum[i + 24] - sum[i]);
	
	int Q;
	scanf("%d", &Q);
	for (int loop{}; loop < Q; loop++)
	{
		int T;
		int64_t V;
		scanf("%d%lld", &T, &V);
		T--;
		rsq.update(T, V - A[T]);
		A[T] = V;
		for (int left{std::max(0, T - 23)}; left + 24 <= N; left++)
			max = std::max(max, rsq.get(left, left + 24));
		printf("%lld\n", max);
	}

	return 0;
}
0