結果

問題 No.3164 [Chery 7th Tune B] La vie en rose
コンテスト
ユーザー tnakao0123
提出日時 2025-05-31 16:50:48
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 89 ms / 2,000 ms
+ 386µs
コード長 927 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 170 ms
コンパイル使用メモリ 52,684 KB
実行使用メモリ 7,552 KB
最終ジャッジ日時 2026-07-11 05:19:02
合計ジャッジ時間 9,759 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 3164.cc:  No.3164 [Chery 7th Tune B] La vie en rose - yukicoder
 */

#include<cstdio>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 300000;

/* typedef */

using ll = long long;

/* global variables */

int as[MAX_N];
ll ass[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", as + i);

  for (int i = 0; i < n;) {
    while (i < n && as[i] == 0) i++;
    if (i >= n) break;

    int j = i;
    ll s = 0;
    while (i < n && as[i] > 0) s += as[i++];
    while (j < i) ass[j++] = s;
  }

  int qn;
  scanf("%d", &qn);

  while (qn--) {
    int x, b;
    scanf("%d%d", &x, &b), x--;

    ll s = ass[x] - as[x] + b;
    if (as[x] == 0) {
      if (x > 0 && as[x - 1] > 0) s += ass[x - 1];
      if (x + 1 < n && as[x + 1] > 0) s += ass[x + 1];
    }

    printf("%lld\n", s);
  }
  
  return 0;
}
0