結果

問題 No.865 24時間降水量
ユーザー batsumarubatsumaru
提出日時 2019-08-16 22:46:04
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 418 ms / 2,000 ms
コード長 1,599 bytes
コンパイル時間 1,485 ms
コンパイル使用メモリ 169,136 KB
実行使用メモリ 6,424 KB
最終ジャッジ日時 2023-10-24 02:16:42
合計ジャッジ時間 3,838 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 4 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 4 ms
4,348 KB
testcase_09 AC 4 ms
4,348 KB
testcase_10 AC 20 ms
4,348 KB
testcase_11 AC 20 ms
4,348 KB
testcase_12 AC 20 ms
4,348 KB
testcase_13 AC 20 ms
4,348 KB
testcase_14 AC 20 ms
4,348 KB
testcase_15 AC 418 ms
6,424 KB
testcase_16 AC 417 ms
6,424 KB
testcase_17 AC 415 ms
6,424 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>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()

//1-indexed
class BIT {
public:
  vector<ll> bit;
  ll M;
 
  BIT(ll M):
    bit(vector<ll>(M+1, 0)), M(M) {}
 
  //a[1] + a[2] + ... + a[i]を求める
  ll sum(ll i) {
    if (i==0) return 0;
    return bit[i] + sum(i-(i&-i));
  }
  //a[i] += x
  void add(ll i, ll x) {
    if (i > M) return;
    bit[i] += x;
    add(i+(i&-i), x);
  }
};

int main(){
  ll n; cin >> n;
  // BIT b(n);
  // REP(i,n){
  //   ll a; cin >> a;
  //   b.add(i+1,a);
  // }
  // ll q; cin >> q;
  // REP(i,q){
  //   ll t,v; cin >> t >> v;
  //   b.add(t,v-(b.sum(t)-b.sum(t-1)));
  //   ll ans = 0;
  //   FOR(j,24,n+1){
  //     ans = max(ans, b.sum(j)-b.sum(j-24));
  //   }
  //   cout << ans << endl;
  //}

  //b[i] = a[i] + a[i+1] + ... + a[i+23]
  //i = 1,2,...,n-23
  vector<ll> b(n-22,0), a(n+1,0);
  ll sum = 0;
  REP(i,n){
    cin >> a[i+1];
    if(i<24) sum += a[i+1];
  }
  b[1] = sum;
  ll ans = b[1];
  FOR(i,1,n-23){
    sum += a[i+24] - a[i];
    b[i+1] = sum;
    ans = max(ans,sum);
  }
  ll q; cin >> q;
  REP(i,q){
    ll t,v; cin >> t >> v;
    //bを更新
    REP(j,24) if(t-23+j>=1 && t-23+j<=n-23){
      b[t-23+j] += v-a[t]; 
      ans = max(ans, b[t-23+j]);
    }
    //aを更新
    a[t] = v;
    cout << ans << endl;
  }
}

0