結果
問題 |
No.3164 [Chery 7th Tune B] La vie en rose
|
ユーザー |
|
提出日時 | 2025-06-15 02:31:00 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 170 ms / 2,000 ms |
コード長 | 681 bytes |
コンパイル時間 | 4,591 ms |
コンパイル使用メモリ | 286,044 KB |
実行使用メモリ | 9,176 KB |
最終ジャッジ日時 | 2025-06-15 02:31:16 |
合計ジャッジ時間 | 16,311 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 34 |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll =long long; #include<atcoder/dsu> using namespace atcoder; void solve(){ ll N; cin>>N; dsu d(N); vector<ll> A(N),C(N); for(int i=0;i<N;i++){ cin>>A[i]; C[i]=A[i]; if(i>0&&A[i-1]>0&&A[i]>0){ ll z=C[d.leader(i-1)]+C[d.leader(i)]; d.merge(i-1,i); C[d.leader(i)]=z; } } ll Q; cin>>Q; for(int i=0;i<Q;i++){ ll x,b; cin>>x>>b; x--; ll an=C[d.leader(x)]-A[x]+b; if(x>0&&!d.same(x,x-1))an+=C[d.leader(x-1)]; if(x<N-1&&!d.same(x,x+1))an+=C[d.leader(x+1)]; cout<<an<<"\n"; } } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T=1; // cin>>T; while(T--)solve(); }