結果

問題 No.865 24時間降水量
ユーザー chocopuuchocopuu
提出日時 2019-08-16 22:26:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,365 bytes
コンパイル時間 2,218 ms
コンパイル使用メモリ 177,876 KB
実行使用メモリ 15,100 KB
最終ジャッジ日時 2023-10-24 01:19:04
合計ジャッジ時間 6,027 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
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){
		seg.add(i,a[i]);
		REP(j,23){
			int l = i - j - 1;
			if(l>=0)seg.add(l,a[i]);
		}
	}
	int Q;
	cin>>Q;
	vector<int>ans(Q,0);
	vector<int>T(Q),X(Q),id(Q);
	REP(i,Q){
		cin>>T[i]>>X[i];
		T[i]--;
	}
	iota(ALL(id),0);
	sort(ALL(id),[&](int l,int r){
		if(T[l]<T[r])return true;
		else if(T[l]==T[r])return X[l]<X[r];
		else return false;
	});
	REP(i,Q){
		int x = X[id[i]],t=T[id[i]];
		seg.add(t,x-a[t]);
		REP(j,23){
			int l = t - j - 1;
			if(l>=0)seg.add(l,x-a[t]);
		}
		a[t] = x;
		ans[id[i]] = seg.query(0,N-23);
	}
	for(auto e:ans){
		cout<<e<<endl;
	}
}
0