結果

問題 No.865 24時間降水量
ユーザー minatominato
提出日時 2019-12-24 03:26:26
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,178 ms / 2,000 ms
コード長 1,806 bytes
コンパイル時間 2,390 ms
コンパイル使用メモリ 186,016 KB
実行使用メモリ 12,964 KB
最終ジャッジ日時 2023-10-19 12:48:58
合計ジャッジ時間 8,093 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 7 ms
4,348 KB
testcase_07 AC 6 ms
4,348 KB
testcase_08 AC 6 ms
4,348 KB
testcase_09 AC 7 ms
4,348 KB
testcase_10 AC 44 ms
4,348 KB
testcase_11 AC 44 ms
4,348 KB
testcase_12 AC 44 ms
4,348 KB
testcase_13 AC 43 ms
4,348 KB
testcase_14 AC 44 ms
4,348 KB
testcase_15 AC 1,178 ms
12,964 KB
testcase_16 AC 1,172 ms
12,964 KB
testcase_17 AC 1,172 ms
12,964 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 #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
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;
}
///////////////////////////////////////////////////////////////

struct SegmentTree {
private:
    int n;
	vector<ll> node;

public:
	SegmentTree(vector<ll> v) {
		int sz = v.size();
		n = 1; while (n < sz) n *= 2;
		node.resize(2*n-1,0);

		rep(i,sz) node[i+n-1] = v[i];
		for (int i = n-2; i >= 0; i--) node[i] = node[2*i+1] + node[2*i+2];
	}

	void update(int x, ll val) {
		x += (n-1);

		node[x] = val;
		while (x > 0) {
			x = (x - 1) / 2;
			node[x] = node[2*x+1] + node[2*x+2];
		}
	}

	ll getsum(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		if (b <= l || r <= a) return 0;
		if(a <= l && r <= b) return node[k];

        ll vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getsum(a, b, 2*k+2, (l+r)/2, r);
        return vl + vr;
	}	
};


int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	int N; cin >> N;
	vector<ll> A(N);
	rep(i,N) cin >> A[i];
	int Q; cin >> Q;
	vector<int> T(Q);
	vector<ll> V(Q);
	rep(i,Q) cin >> T[i] >> V[i];
	rep(i,Q) T[i]--;

	SegmentTree RSQ(A);
	ll ans = 0;
	int k = -1;
	rep(i, N-23) chmax(ans,RSQ.getsum(i,i+24));
	rep(i,Q) {
		RSQ.update(T[i],V[i]);
		for (int j = max(0,T[i]-23); j < min(N-23,T[i]+1); j++) {
            chmax(ans,RSQ.getsum(j,j+24));
		}
		cout << ans << endl;
	}



}
0