結果
| 問題 |
No.3164 [Chery 7th Tune B] La vie en rose
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-05-30 21:24:29 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,163 bytes |
| コンパイル時間 | 786 ms |
| コンパイル使用メモリ | 82,668 KB |
| 実行使用メモリ | 143,616 KB |
| 最終ジャッジ日時 | 2025-05-30 21:24:45 |
| 合計ジャッジ時間 | 15,348 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 2 WA * 22 RE * 10 |
ソースコード
import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random
#sys.setrecursionlimit(10**9)
#sys.set_int_max_str_digits(0)
input = sys.stdin.readline
#n = int(input())
#a = list(map(int,input().split()))
#a = []
#s = input()
#n,m = map(int,input().split())
#for i in range(n):
# a.append(list(map(int,input().split())))
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
group_members = collections.defaultdict(list)
for member in range(self.n):
group_members[self.find(member)].append(member)
return group_members
def __str__(self):
return ''.join(f'{r}: {m}' for r, m in self.all_group_members().items())
n = int(input())
a = list(map(int,input().split()))
q = int(input())
cnt = [0 for i in range(n)]
uf = UnionFind(n)
for i in range(n-1):
if a[i] > 0 and a[i+1] > 0:
uf.union(i,i+1)
for i in range(n):
cnt[uf.find(i)] += a[i]
for i in range(q):
x,b = map(int,input().split())
x -= 1
if a[x] > 0:
print(cnt[uf.find(x)] - a[x] + b)
else:
ans = 0
if i-1 >= 0:
ans += cnt[uf.find(i-1)]
if i+1 < n:
ans += cnt[uf.find(i+1)]
ans += b
print(ans)