結果

問題 No.865 24時間降水量
ユーザー SSRSSSRS
提出日時 2020-11-06 21:06:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,658 bytes
コンパイル時間 1,465 ms
コンパイル使用メモリ 168,548 KB
実行使用メモリ 9,644 KB
最終ジャッジ日時 2023-09-29 17:59:52
合計ジャッジ時間 4,399 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
struct lazy_segment_tree{
  int N;
  vector<int> ST, lazy;
  lazy_segment_tree(vector<int> &A){
    int n = A.size();
    N = 1;
    while (N < n){
      N *= 2;
    }
    ST = vector<int>(N * 2 - 1, 0);
    lazy = vector<int>(N * 2 - 1, 0);
    for (int i = 0; i < n; i++){
      ST[N - 1 + i] = A[i];
    }
    for (int i = N - 2; i >= 0; i--){
      ST[i] = max(ST[i * 2 + 1], ST[i * 2 + 2]);
    }
  }
  void eval(int i){
    if (lazy[i] != 0){
      if (i < N - 1){
        lazy[i * 2 + 1] += lazy[i];
        lazy[i * 2 + 2] += lazy[i];
      }
      ST[i] += lazy[i];
      lazy[i] = 0;
    }
  }
  void range_add(int L, int R, int x, int i, int l, int r){
    eval(i);
    if (r <= L || R <= l){
      return;
    } else if (L <= l && r <= R){
      lazy[i] = x;
      eval(i);
    } else {
      int m = (l + r) / 2;
      range_add(L, R, x, i * 2 + 1, l, m);
      range_add(L, R, x, i * 2 + 2, m, r);
      ST[i] = max(ST[i * 2 + 1], ST[i * 2 + 2]);
    }
  }
  void range_add(int L, int R, int x){
    range_add(L, R, x, 0, 0, N);
  }
  int all(){
    eval(0);
    return ST[0];
  }
};
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  vector<int> S(N + 1);
  S[0] = 0;
  for (int i = 0; i < N; i++){
    S[i + 1] += S[i];
  }
  vector<int> B(N - 23);
  for (int i = 0; i < N - 23; i++){
    B[i] = S[i + 24] - S[i];
  }
  lazy_segment_tree ST(B);
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++){
    int T, V;
    cin >> T >> V;
    T--;
    ST.range_add(T, min(T + 24, N - 23), V - A[T]);
    A[T] = V;
    cout << ST.all() << endl;
  }
}
0