結果
| 問題 |
No.742 にゃんにゃんにゃん 猫の挨拶
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 20:25:02 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 84 ms / 2,500 ms |
| コード長 | 580 bytes |
| コンパイル時間 | 969 ms |
| コンパイル使用メモリ | 82,164 KB |
| 実行使用メモリ | 77,148 KB |
| 最終ジャッジ日時 | 2025-03-20 20:26:28 |
| 合計ジャッジ時間 | 1,590 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
ソースコード
class BIT:
def __init__(self, size):
self.size = size
self.tree = [0] * (self.size + 1)
def add(self, index, val):
while index <= self.size:
self.tree[index] += val
index += index & -index
def sum_query(self, index):
res = 0
while index > 0:
res += self.tree[index]
index -= index & -index
return res
n = int(input())
M = [int(input()) for _ in range(n)]
bit = BIT(n)
ans = 0
for x in reversed(M):
ans += bit.sum_query(x - 1)
bit.add(x, 1)
print(ans)
lam6er