結果

問題 No.865 24時間降水量
ユーザー chocopuuchocopuu
提出日時 2019-08-16 23:32:02
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 907 ms / 2,000 ms
コード長 2,098 bytes
コンパイル時間 1,929 ms
コンパイル使用メモリ 174,176 KB
実行使用メモリ 10,668 KB
最終ジャッジ日時 2023-10-24 06:06:18
合計ジャッジ時間 6,472 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
4,348 KB
testcase_05 AC 6 ms
4,348 KB
testcase_06 AC 6 ms
4,348 KB
testcase_07 AC 5 ms
4,348 KB
testcase_08 AC 5 ms
4,348 KB
testcase_09 AC 5 ms
4,348 KB
testcase_10 AC 29 ms
4,348 KB
testcase_11 AC 28 ms
4,348 KB
testcase_12 AC 28 ms
4,348 KB
testcase_13 AC 28 ms
4,348 KB
testcase_14 AC 28 ms
4,348 KB
testcase_15 AC 899 ms
10,668 KB
testcase_16 AC 907 ms
10,668 KB
testcase_17 AC 903 ms
10,668 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
const long long MOD = 1e9+7, INF = 1e18;
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a=b;return true;}return false;}

template<class T>
class SegmentTree{
	private:
	int N;
	T initVal;
	std::vector<T>ary;
	std::function<T(T&,T&)>merge;
	void init(int n){
		while(N < n)N <<= 1;
		ary.resize(N << 1,initVal);
	}
	public:
		SegmentTree(int n,T initVal,std::function<T(T&,T&)>f):
			N(1),initVal(initVal),merge(f){init(n);}
	// -- a[i] = val;
	inline void update(int i,T val){
		ary[i += N] = val;
		while(i > 1){
			i >>= 1;
			ary[i] = merge(ary[i << 1],ary[(i << 1) + 1]);
		}
	}
	// -- a[i] += val;
	inline void add(int i,T val){
		update(i,ary[i + N] + val);
	}
	// -- [l,r)
	inline T query(int l,int r){
		if(l >= r)return initVal;
		T vr = initVal,vl = initVal;
		for(l += N,r += N;l != r;l >>= 1,r >>= 1){
			if(l & 1)vl = merge(vl,ary[l++]);
			if(r & 1)vr = merge(vr,ary[--r]);
		}
		return merge(vl,vr);
	}
	/*
	void debug show(){
		for(iint i = N;i < N;i++)std::cerr << ary[i] << ' ';
		std:::cerr << '\n';
	}
	*/
};
using ST = SegmentTree<int>;
#define SUM ST(n,0,[](int &a,int &b){return a+b};);
#define MIN ST(n,INF,[](int &a,int &b){return min(a,b);});
#define MAX ST(N,0,[](int &a,int &b){return max(a,b);});
//REP(i,N)f(seg.query(0,i),seg.query(i+1,N))でiを除いた全探索

signed main(){
	int N;
	cin>>N;
	vector<int>a(N);
	REP(i,N)cin>>a[i];
	auto seg = ST(N,0,[](int &a,int &b){return max(a,b);});
	REP(i,N){
		REP(j,24){
			int l = i - j;
			if(l>=0)seg.add(l,a[i]);
		}
	}
	int Q;
	cin>>Q;
	vector<int>ans(Q,0);
	REP(i,Q){
		int t,x;
		cin>>t>>x;
		t--;
		REP(j,24){
			int l = t - j;
			if(l>=0)seg.add(l,x-a[t]);
		}
		a[t] = x;
		ans[i] = seg.query(0,N-23);
	}
	for(auto e:ans){
		cout<<e<<endl;
	}
}
0