結果

問題 No.865 24時間降水量
ユーザー edamame882edamame882
提出日時 2019-08-16 22:26:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,105 ms / 2,000 ms
コード長 1,827 bytes
コンパイル時間 4,279 ms
コンパイル使用メモリ 171,312 KB
実行使用メモリ 6,068 KB
最終ジャッジ日時 2023-10-24 01:18:50
合計ジャッジ時間 6,839 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 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 7 ms
4,348 KB
testcase_08 AC 6 ms
4,348 KB
testcase_09 AC 6 ms
4,348 KB
testcase_10 AC 42 ms
4,348 KB
testcase_11 AC 42 ms
4,348 KB
testcase_12 AC 42 ms
4,348 KB
testcase_13 AC 42 ms
4,348 KB
testcase_14 AC 42 ms
4,348 KB
testcase_15 AC 1,105 ms
6,068 KB
testcase_16 AC 1,105 ms
6,068 KB
testcase_17 AC 1,104 ms
6,068 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>
using namespace std;

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

int n;
vector<int> dat;

void init(int _n){
  n = 1;
  while(n < _n) n *= 2;
  dat.resize(n*2-1,0);
  rep(i,n*2-1){
    dat[i] = 0;
  }
}

void update(int i, int x){
  i += n-1;
  dat[i] += x;
  while(i > 0){
    i = (i-1)/2;
    dat[i] = dat[i*2+1] + dat[i*2+2];
  }
}

int getSum(int x, int y, int k, int l, int r){
  if(r <= x || y <= l) return 0;
  if(x <= l && r <= y) return dat[k];
  else{
    int vl = getSum(x,y,k*2+1,l,(l+r)/2);
    int vr = getSum(x,y,k*2+2,(l+r)/2,r);
    return vl + vr;
  }
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int _n;
  cin >> _n;
  VI a(_n);
  init(_n);
  rep(i,_n){
    cin >> a[i];
    update(i,a[i]);
  }
  int ans = 0;
  rep(i,_n-23){
    ans = max<int>(ans,getSum(i,i+24,0,0,n));
  }

  int q;
  cin >> q;
  rep(i,q) {
    int t,v;
    cin >> t >> v;
    t--;
    update(t,v-a[t]);
    a[t] = v;
    rep(j,24){
      if(t-j >= 0 && t-j+24 <= _n) ans = max<int>(ans,getSum(t-j,t-j+24,0,0,n));
    }
    cout << ans << endl;
  }
  return 0;
}
0