結果
| 問題 | No.2306 [Cherry 5th Tune C] ウソツキタマシイ |
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 21:07:00 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 139 ms / 2,000 ms |
| コード長 | 1,129 bytes |
| コンパイル時間 | 275 ms |
| コンパイル使用メモリ | 82,360 KB |
| 実行使用メモリ | 133,456 KB |
| 最終ジャッジ日時 | 2025-03-20 21:07:12 |
| 合計ジャッジ時間 | 5,569 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
ソースコード
def main():
import sys
input = sys.stdin.read().split()
ptr = 0
N = int(input[ptr])
ptr += 1
M = int(input[ptr])
ptr += 1
A = list(map(int, input[ptr:ptr+M]))
ptr += M
count = [0] * (M + 1)
soul_power = 0
for i in range(1, M + 1):
count[i] = A[i - 1]
soul_power += count[i] ** 2
Q = int(input[ptr])
ptr += 1
for _ in range(Q):
C = int(input[ptr])
ptr += 1
K = int(input[ptr])
ptr += 1
D = int(input[ptr])
ptr += 1
x = count[C]
y = count[D]
# Calculate changes for C
old_c = x ** 2
new_c = x - K
new_c_sq = new_c ** 2
delta_c = new_c_sq - old_c
# Calculate changes for D
old_d = y ** 2
new_d = y + K
new_d_sq = new_d ** 2
delta_d = new_d_sq - old_d
# Update soul power
soul_power += delta_c + delta_d
# Update counts
count[C] = new_c
count[D] = new_d
print(soul_power)
if __name__ == '__main__':
main()
lam6er