結果

問題 No.885 アマリクエリ
ユーザー lam6er
提出日時 2025-03-20 20:58:20
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 709 bytes
コンパイル時間 404 ms
コンパイル使用メモリ 82,376 KB
実行使用メモリ 269,136 KB
最終ジャッジ日時 2025-03-20 20:58:53
合計ジャッジ時間 4,723 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other AC * 1 TLE * 1 -- * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
a = list(map(int, input().split()))
q = int(input())
x_list = list(map(int, input().split()))

current_sum = sum(a)
active = list(range(n))  # Indices of active elements (non-zero)

for x in x_list:
    new_active = []
    delta = 0  # The total change in sum due to this query
    for idx in active:
        orig = a[idx]
        if orig == 0:
            continue  # Skip if already zero (though this shouldn't happen as per active list)
        new_val = orig % x
        delta += new_val - orig
        a[idx] = new_val
        if new_val != 0:
            new_active.append(idx)
    current_sum += delta
    print(current_sum)
    active = new_active  # Update active list for next query
0