結果
問題 |
No.3164 [Chery 7th Tune B] La vie en rose
|
ユーザー |
|
提出日時 | 2025-06-12 23:44:53 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 236 ms / 2,000 ms |
コード長 | 994 bytes |
コンパイル時間 | 3,868 ms |
コンパイル使用メモリ | 281,204 KB |
実行使用メモリ | 9,236 KB |
最終ジャッジ日時 | 2025-06-12 23:45:12 |
合計ジャッジ時間 | 17,640 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 34 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, s, e) for (int i = (int)(s); i < (int)(e); ++i) #define all(a) (a).begin(),(a).end() int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int N; cin >> N; vector<ll> A(N); rep(i, 0, N) cin >> A[i]; vector<int> pos; pos.push_back(-1); rep(i, 0, N) if (A[i] == 0) pos.push_back(i); pos.push_back(N); vector<ll> sum(N); sum[0] = A[0]; rep(i, 1, N) sum[i] = sum[i - 1] + A[i]; int Q; cin >> Q; rep(query, 0, Q) { int X; ll B; cin >> X >> B; --X; int Lind = lower_bound(all(pos), X) - pos.begin() - 1; int Rind = lower_bound(all(pos), X + 1) - pos.begin(); ll ans; if (Lind == 0) ans = sum[pos[Rind] - 1]; else ans = sum[pos[Rind] - 1] - sum[pos[Lind]]; ans += B - A[X]; cout << ans << '\n'; } }