結果
| 問題 |
No.3164 [Chery 7th Tune B] La vie en rose
|
| コンテスト | |
| ユーザー |
Kude
|
| 提出日時 | 2025-05-30 22:45:56 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 140 ms / 2,000 ms |
| コード長 | 1,305 bytes |
| コンパイル時間 | 3,834 ms |
| コンパイル使用メモリ | 300,176 KB |
| 実行使用メモリ | 7,956 KB |
| 最終ジャッジ日時 | 2025-05-30 22:46:15 |
| 合計ジャッジ時間 | 14,131 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 34 |
ソースコード
#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
} int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
VI a0(n + 2);
VL a(n + 2);
rep(i, n) cin >> a[i + 1], a0[i+1] = a[i+1];
n += 2;
dsu uf(n);
rep(i, n - 1) if (a[i] && a[i+1]) {
int l1 = uf.leader(i), l2 = uf.leader(i + 1);
a[uf.merge(l1, l2)] = a[l1] + a[l2];
}
int q;
cin >> q;
while (q--) {
int x, b;
cin >> x >> b;
ll ans = 0;
if (a[x] == 0) {
ans = a[uf.leader(x - 1)] + a[uf.leader(x + 1)] + b;
} else {
ans = a[uf.leader(x)] + b - a0[x];
}
cout << ans << '\n';
}
}
Kude