結果

問題 No.865 24時間降水量
ユーザー snow39snow39
提出日時 2019-08-16 22:08:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,561 ms / 2,000 ms
コード長 1,923 bytes
コンパイル時間 1,130 ms
コンパイル使用メモリ 100,964 KB
実行使用メモリ 14,596 KB
最終ジャッジ日時 2023-10-23 23:49:40
合計ジャッジ時間 7,472 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 7 ms
4,348 KB
testcase_06 AC 8 ms
4,348 KB
testcase_07 AC 8 ms
4,348 KB
testcase_08 AC 7 ms
4,348 KB
testcase_09 AC 8 ms
4,348 KB
testcase_10 AC 58 ms
4,348 KB
testcase_11 AC 58 ms
4,348 KB
testcase_12 AC 58 ms
4,348 KB
testcase_13 AC 58 ms
4,348 KB
testcase_14 AC 58 ms
4,348 KB
testcase_15 AC 1,557 ms
14,596 KB
testcase_16 AC 1,556 ms
14,596 KB
testcase_17 AC 1,561 ms
14,596 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 <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
#define mkp make_pair
typedef long long ll;
using namespace std;

class LazySegmentTree{
private:
  int n;
  vector<ll> node,lazy;

public:
  LazySegmentTree(vector<ll> v){
      n=1;
      while(n<v.size()) n*=2;
      node.resize(2*n-1,0);
      lazy.resize(2*n-1,0);
      
      for(int i=0;i<v.size();i++) 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 eval(int k,int l,int r){
      if(lazy[k]!=0){
          node[k]+=lazy[k];
          if(r-l>1){
              lazy[2*k+1]+=lazy[k]/2;
              lazy[2*k+2]+=lazy[k]/2;
          }
          lazy[k]=0;
      }
  }

  void add(int a,int b,ll x,int k=0,int l=0,int r=-1){
      if(r<0) r=n;
      eval(k,l,r);
      if(b<=l||r<=a) return;
      if(a<=l&&r<=b){
          lazy[k]+=(r-l)*x;
          eval(k,l,r);
      }else{
          add(a,b,x,2*k+1,l,(r+l)/2);
          add(a,b,x,2*k+2,(r+l)/2,r);
          node[k]=node[2*k+1]+node[2*k+2];
      }
  }

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

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

int N,Q;
vector<ll> A;

int L=24;

int main(){
  cin>>N;
  A.resize(N);
  for(int i=0;i<N;i++) cin>>A[i];

  LazySegmentTree seg(A);
  ll ans=0;
  for(int i=0;i+L-1<N;i++){
    ans=max(ans,seg.getSum(i,i+L,0,0,-1));
  }

  cin>>Q;
  for(int i=0;i<Q;i++){
    int t,v;
    cin>>t>>v;
    t--;

    ll val=seg.getSum(t,t+1,0,0,-1);
    seg.add(t,t+1,v-val);

    for(int j=0;j<L;j++){
      if(t-j>=0&&t-j+L-1<N) ans=max(ans,seg.getSum(t-j,t-j+L,0,0,-1));
    }
    cout<<ans<<endl;
  }

  return 0;
}
0