結果
| 問題 |
No.694 square1001 and Permutation 3
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-10-01 10:52:59 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 604 bytes |
| コンパイル時間 | 184 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 85,632 KB |
| 最終ジャッジ日時 | 2024-07-18 17:09:20 |
| 合計ジャッジ時間 | 5,743 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | WA * 4 RE * 9 |
ソースコード
class BinaryIndexedTree():
def __init__(self, n):
self.n = n
self.BIT = [0] * (self.n + 1)
def add(self, i, x):
while i <= self.n:
self.BIT[i] += x
i += i & -i
def query(self, i):
res = 0
while i > 0:
res += self.BIT[i]
i -= i & -i
return res
n = int(input())
a = [int(input()) - 1 for i in range(n)]
ans = 0
BIT = BinaryIndexedTree(n)
for i in range(n):
ans += i - BIT.query(a[i] + 1)
BIT.add(a[i] + 1, 1)
print(ans)
for i in range(n - 1):
ans += n - 2 * a[i] - 1
print(ans)