結果

問題 No.865 24時間降水量
ユーザー pockynypockyny
提出日時 2019-08-16 21:51:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 359 ms / 2,000 ms
コード長 863 bytes
コンパイル時間 858 ms
コンパイル使用メモリ 75,276 KB
実行使用メモリ 5,180 KB
最終ジャッジ日時 2023-10-23 22:32:36
合計ジャッジ時間 3,214 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
int n,t[400010] = {},mx = 0;
void built(){
	for(int i = n-1;i>0;i--){
		t[i] = t[i<<1] + t[i<<1|1];
	}
}

void update(int p,int a){
	for(t[p+=n] = a;p>1;p >>= 1){
		t[p>>1] = t[p] + t[p^1];
	}
}

int query(int l, int r){
	int mn = mx;
	for(l += n, r += n; l<r; l >>= 1,r >>= 1){
		if(l&1) mn += t[l++];
		if(r&1) mn += t[--r];
	}
	return mn;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int i,j,q;
	cin >> n;
	for(i=0;i<n;i++){
		int a; cin >> a; t[i + n] = a;
	}
	built();
	int mx = -1;
	for(i=0;i<=n - 24;i++){
		mx = max(mx,query(i,i + 24));
	}
	cin >> q;
	for(i=0;i<q;i++){
		int t,v; cin >> t >> v;
		t--; update(t,v);
		for(j=t - 24;j<=t;j++){
			if(j<0) continue;
			if(j + 24>n) continue;
			mx = max(mx,query(j,j + 24));
		}
		cout << mx << endl;
	}
}
0