結果

問題 No.3164 [Chery 7th Tune B] La vie en rose
ユーザー HoyHoyCharhang
提出日時 2025-05-30 21:33:49
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 794 ms / 2,000 ms
コード長 1,345 bytes
コンパイル時間 3,320 ms
コンパイル使用メモリ 277,124 KB
実行使用メモリ 9,088 KB
最終ジャッジ日時 2025-05-30 21:34:28
合計ジャッジ時間 25,842 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define eb emplace_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using ull = unsigned long long;
template<typename T> using pq = priority_queue<T,vector<T>,greater<T>>;
using P = pair<int,int>;
template<class T>bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,T b){if(b<a){a=b;return 1;}return 0;}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<ll> s(n+1, 0);
  vector<ll> c(n);
  int idx = -1;
  rep(i,0,n) {
    cin >> a[i];
    s[i+1] = s[i] + a[i];
    if (a[i] == 0) {
      rep(j,idx+1,i) {
        c[j] = s[i]-s[idx+1];
      }
      idx = i;
    }
  }
  rep(j,idx+1,n) c[j] = s[n]-s[idx+1];
  // rep(i,0,n) {
  //   cout << c[i] << " ";
  // }
  // cout << endl;
  int q;
  cin >> q;
  while(q--) {
    int x, b;
    cin >> x >> b;
    --x;
    if (a[x] > 0) {
      cout << c[x]-a[x]+b << endl;
    } else {
      ll ans = (x > 0 ? c[x-1] : 0) + (x < n-1 ? c[x+1] : 0) + b;
      cout << ans << endl;
    }
  }
  return 0;
}
0