結果

問題 No.865 24時間降水量
ユーザー okok
提出日時 2019-08-16 22:34:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 424 ms / 2,000 ms
コード長 2,216 bytes
コンパイル時間 1,779 ms
コンパイル使用メモリ 82,720 KB
実行使用メモリ 10,460 KB
最終ジャッジ日時 2023-10-24 01:45:32
合計ジャッジ時間 3,815 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include <functional>
#include <limits>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

template<typename T>
class segment_tree{
	int n;
	T fval;
	function<T(T,T)> operation;
	vector<T> dat;
	
	T _query(int a, int b, int k, int l, int r){
		if(r <= a || b <= l){
			return fval;
		}
		
		if(a <= l && r <= b){
			return dat[k];
		}else {
			T vl = _query(a, b, k * 2 + 1, l, (l + r) / 2 );
			T vr = _query(a, b, k * 2 + 2, (l + r) / 2, r);
			return operation(vl, vr);
		}
	}
	
public:
	
	segment_tree(){
		
	}
	
	segment_tree(int n_, T val, function<T(T,T)> fun){
		init(n_, val, fun);
	}
	
	~segment_tree(){
		
	}
	
	void init(int n_, T val, function<T(T,T)> fun){
		fval = val;
		
		operation = fun;
		
		n = 1;
		
		while(n < n_) n *= 2;
		
		dat.resize(2 * n - 1);
	
		for(int i = 0; i < 2 * n - 1; i++) dat[i] = fval;
	}

	void update(int k, T a){
		k += n - 1;
		dat[k] = a;
		while(k > 0){
			k = (k - 1) / 2;
			dat[k] = operation(dat[k*2 + 1],dat[k*2 + 2]);
		}
	}
	
	T query(int a, int b){
		return _query(a, b, 0, 0, n);
	}
	
};

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	const int TF = 24;
	segment_tree<int> seg;
	int N, Q, T, V;
	vector<int> sum, A;
	
	cin>>N;
	
	sum.resize(N+TF+2);
	A.resize(N+2);
	seg.init(N+TF+2,0ll, [](int first, int second){ return max(first,second);});
	
	for(int i = 0; i < N; i++){
		cin>>A[i];
		sum[i] += A[i];
		sum[i+TF] -= A[i];
	}
	
	for(int i = 0; i < N; i++){
		sum[i+1] += sum[i];
		// cout<<"i = "<<i<<" sum "<<sum[i]<<endl;
		seg.update(i, sum[i]);
	}
	
	cin>>Q;
	
	for(int i = 0; i < Q; i++){
		cin>>T>>V;
		T--;
		for(int j = T; j < T+TF && j < N; j++){
			seg.update(j, V - A[T] + sum[j]);
			sum[j] += V - A[T];
		}
		A[T] = V;
		// cout<<"------------- "<<"T = "<<T<< " V = "<<V<<endl;
		// for(int j = 0; j < N; j++){
			// cout<<"j = "<<j<<" sum "<<sum[j]<<endl;
		// }
		cout<<seg.query(0,N)<<endl;
	}
	
	return 0;
}
0