結果
| 問題 |
No.694 square1001 and Permutation 3
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-11-30 09:13:10 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 680 bytes |
| コンパイル時間 | 353 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 103,108 KB |
| 最終ジャッジ日時 | 2024-09-13 02:15:14 |
| 合計ジャッジ時間 | 12,948 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 1 |
| other | AC * 2 WA * 6 TLE * 2 -- * 3 |
ソースコード
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]
bit = Bit(max(Ac))
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] - (p - 1) + (N - p)
print(*ans, sep='\n')