結果

問題 No.865 24時間降水量
ユーザー NagisaNagisa
提出日時 2019-08-17 00:11:03
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 505 ms / 2,000 ms
コード長 1,237 bytes
コンパイル時間 1,541 ms
コンパイル使用メモリ 171,744 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 12:35:29
合計ジャッジ時間 4,203 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

struct BIT{
  vector<int> bit;
  int n;
  //1-indexed
  BIT(){init();}
  BIT(int n):n(n){init();}
  void init(){
    bit.clear();
    bit.resize(n+1,0);
  }
  int sum(int i){
    int s=0;
    while(i>0){
      s+=bit[i];
      i-=i&-i;
    }
    return s;
  }
  void add(int i,int x){
    while(i<=n){
      bit[i]+=x;
      i+=i&-i;
    }
  }
};

signed main(){
    int N, Q, T, V, A;
    cin >> N;
    BIT bit(N+100);
    REP(i,N){
        cin >> A;
        bit.add(i+1,A);
    }
    cin >> Q;
    int ans = 0;
    REP(j,N-24+1){
        ans = max(ans, bit.sum(24+j)-bit.sum(j));
    }
    REP(i,Q){
        cin >> T >> V;
        int t = V - (bit.sum(T)-bit.sum(T-1));
        bit.add(T,t);
        if (T <= 24){
            REP(j,T+1){
                ans = max(ans, bit.sum(24+j)-bit.sum(j));
            }
        }else if (N <= T+24){
            REP(j,N-T+1){
                ans = max(ans, bit.sum(T+j)-bit.sum(T+j-24));
            }
        }else{
            REP(j,24){
                ans = max(ans, bit.sum(T+j)-bit.sum(T+j-24));
            }
        }
        cout << ans << endl;
    }
  return 0;
}
0