結果
問題 |
No.1307 Rotate and Accumulate
|
ユーザー |
![]() |
提出日時 | 2020-12-04 15:03:41 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 932 bytes |
コンパイル時間 | 251 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 59,520 KB |
最終ジャッジ日時 | 2024-09-15 01:24:01 |
合計ジャッジ時間 | 7,627 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 5 TLE * 1 -- * 13 |
ソースコード
#!/usr/bin/env python3 # # No.1307 Rotate and Accumulate # import sys, os, math def read_ints(): return list(map(int, input().split())) n, q = read_ints() a, r = read_ints(), sorted(read_ints()) c = [0] * (2 * n + 1) for i in range(1, 2 * n + 1): c[i] = a[(i - 1) % n] + c[i - 1] b = [0] * n s = []; m = 0 for x in r: if not s: s = [x]; m = 1 elif x == s[-1]: if len(s) > 1: for i in range(n): b[i] += c[i + s[-1] + 1] - c[i + s[0]] s = [x]; m = 1 else: m += 1 elif x == s[-1] + 1: if m > 1: for i in range(n): b[i] += a[(i + s[-1]) % n] * (m - 1) m = 1 s.append(x) else: if m > 1: for i in range(n): b[i] += a[(i + s[-1]) % n] * m else: for i in range(n): b[i] += c[i + s[-1] + 1] - c[i + s[0]] s = [x]; m = 1 if m > 1: for i in range(n): b[i] += a[(i + s[-1]) % n] * m else: for i in range(n): b[i] += c[i + s[-1] + 1] - c[i + s[0]] print(" ".join(map(str, b)))