結果

問題 No.865 24時間降水量
ユーザー pockynypockyny
提出日時 2019-08-16 21:51:19
言語 C++17
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 325 ms / 2,000 ms
コード長 863 bytes
コンパイル時間 659 ms
使用メモリ 5,024 KB
最終ジャッジ日時 2022-11-22 04:52:39
合計ジャッジ時間 3,197 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 1 ms
3,544 KB
testcase_01 AC 1 ms
3,464 KB
testcase_02 AC 1 ms
3,544 KB
testcase_03 AC 2 ms
3,552 KB
testcase_04 AC 1 ms
3,540 KB
testcase_05 AC 3 ms
3,512 KB
testcase_06 AC 3 ms
3,468 KB
testcase_07 AC 3 ms
3,472 KB
testcase_08 AC 3 ms
3,556 KB
testcase_09 AC 3 ms
3,436 KB
testcase_10 AC 16 ms
3,468 KB
testcase_11 AC 17 ms
3,540 KB
testcase_12 AC 16 ms
3,508 KB
testcase_13 AC 17 ms
3,560 KB
testcase_14 AC 17 ms
3,528 KB
testcase_15 AC 325 ms
4,956 KB
testcase_16 AC 316 ms
4,944 KB
testcase_17 AC 316 ms
5,024 KB
testcase_18 AC 1 ms
3,488 KB
testcase_19 AC 1 ms
3,396 KB
testcase_20 AC 2 ms
3,516 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