結果
| 問題 |
No.3164 [Chery 7th Tune B] La vie en rose
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-05-31 16:01:23 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 593 ms / 2,000 ms |
| コード長 | 453 bytes |
| コンパイル時間 | 835 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 167,740 KB |
| 最終ジャッジ日時 | 2025-05-31 16:01:49 |
| 合計ジャッジ時間 | 19,124 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 34 |
ソースコード
(n,),a,(q,),*e=[[*map(int,s.split())]for s in open(0)]
uf=[*range(n)]
c=a[:]
def find(x):
q=[]
while uf[x]^x:q+=x,;x=uf[x]
for p in q:uf[p]=x
return x
def unite(x,y):
x,y=find(x),find(y)
if x^y:uf[x]=y;c[y]+=c[x];c[x]=0
for i in range(n-1):
if a[i] and a[i+1]:
unite(i,i+1)
for x,b in e:
x-=1
ans=c[find(x)]-a[x]+b
if x and find(x-1)!=find(x):
ans+=c[find(x-1)]
if x+1<n and find(x)!=find(x+1):
ans+=c[find(x+1)]
print(ans)