結果
問題 | No.694 square1001 and Permutation 3 |
ユーザー |
|
提出日時 | 2020-11-30 09:25:33 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 903 ms / 3,000 ms |
コード長 | 790 bytes |
コンパイル時間 | 365 ms |
コンパイル使用メモリ | 82,464 KB |
実行使用メモリ | 193,204 KB |
最終ジャッジ日時 | 2024-09-13 02:15:45 |
合計ジャッジ時間 | 7,756 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 13 |
ソースコード
class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i N = int(input()) A = [int(input()) for _ in range(N)] d = {x: i for i, x in enumerate(sorted(list(set(A))), 1)} Ac = [d[a] for a in A] M = max(Ac) ct = [0] * (M + 1) for c in Ac: ct[c] += 1 for i in range(1, M + 1): ct[i] += ct[i - 1] bit = Bit(M) ans = [0] * N for i, p in enumerate(Ac): bit.add(p, 1) ans[0] += i + 1 - bit.sum(p) for i, p in enumerate(Ac[:-1]): ans[i + 1] = ans[i] - ct[p - 1] + (N - ct[p]) print(*ans, sep='\n')