結果

問題 No.3164 [Chery 7th Tune B] La vie en rose
ユーザー テナガザル
提出日時 2025-05-30 21:30:42
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,086 ms / 2,000 ms
コード長 667 bytes
コンパイル時間 1,212 ms
コンパイル使用メモリ 109,636 KB
実行使用メモリ 20,608 KB
最終ジャッジ日時 2025-05-30 21:31:19
合計ジャッジ時間 27,577 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  set<int> st;
  st.insert(0);
  st.insert(n + 1);
  for (int i = 0; i < n; ++i)
  {
    if (a[i]) continue;
    st.insert(i + 1);
  }
  vector<long long> sum(n + 2);
  for (int i = 0; i < n; ++i) sum[i + 1] = sum[i] + a[i];
  sum[n + 1] = sum[n];
  int q;
  cin >> q;
  while (q--)
  {
    int x, b;
    cin >> x >> b;
    auto r = *st.upper_bound(x);
    auto itr = st.lower_bound(x);
    --itr;
    int l = *itr;
    cout << sum[r] - sum[l] - a[x - 1] + b << endl;
  }
}
0