結果

問題 No.865 24時間降水量
ユーザー ゆきのんゆきのん
提出日時 2019-08-17 00:37:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 502 ms / 2,000 ms
コード長 1,440 bytes
コンパイル時間 1,233 ms
コンパイル使用メモリ 162,816 KB
実行使用メモリ 7,164 KB
最終ジャッジ日時 2023-10-24 13:47:35
合計ジャッジ時間 3,840 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,008 KB
testcase_01 AC 3 ms
6,008 KB
testcase_02 AC 3 ms
6,008 KB
testcase_03 AC 3 ms
6,008 KB
testcase_04 AC 3 ms
6,008 KB
testcase_05 AC 6 ms
6,012 KB
testcase_06 AC 5 ms
6,012 KB
testcase_07 AC 5 ms
6,012 KB
testcase_08 AC 5 ms
6,012 KB
testcase_09 AC 5 ms
6,012 KB
testcase_10 AC 23 ms
6,012 KB
testcase_11 AC 24 ms
6,012 KB
testcase_12 AC 24 ms
6,012 KB
testcase_13 AC 24 ms
6,012 KB
testcase_14 AC 24 ms
6,012 KB
testcase_15 AC 501 ms
7,164 KB
testcase_16 AC 498 ms
7,164 KB
testcase_17 AC 502 ms
7,164 KB
testcase_18 AC 3 ms
6,004 KB
testcase_19 AC 3 ms
6,004 KB
testcase_20 AC 4 ms
6,004 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

const int M_N=300000;

struct BIT{
    //1-indexed
    LL bit[M_N+1],n;
    //iまでの総和を返す
    LL sum(int i){
        LL s=0;
        while(i>0){
            s+=bit[i];
            i=i&(i-1);
        }
        return s;
    }
    //iにx加算する
    void add(int i,LL x){
        while(i<=n){
            bit[i]+=x;
            i+=i&-i;
        }
    }

};



int main(){
    int n;cin >> n;
    vector<LL> a(n);
    BIT bit;
    bit.n=n+100;
    for (int i = 0;i < n; i++) {
        cin >> a[i];
        bit.add(i+2,a[i]);
    }
    LL ans = 0;
    for (int i = 0; i < n; i++) {
        ans = max(ans,bit.sum(i+25)-bit.sum(i+1));
    }
    LL q;cin >> q;
    for (int i = 0; i < q; i++) {
        LL t,v;cin >> t >> v;
        bit.add(t+1,-a[t-1]);
        bit.add(t+1,v);
        a[t-1]=v;
        for (int j = 0; j < 24; j++) {
            if(t-j<1) continue;
            if(ans < bit.sum(t-j+24)-bit.sum(t-j)){
                ans = max(ans,bit.sum(t-j+24)-bit.sum(t-j));
            }
        }
        cout << ans << endl;
    }
    return 0;
}
0