結果
| 問題 | No.742 にゃんにゃんにゃん 猫の挨拶 |
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 20:25:02 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 85 ms / 2,500 ms |
| コード長 | 580 bytes |
| 記録 | |
| コンパイル時間 | 237 ms |
| コンパイル使用メモリ | 96,116 KB |
| 実行使用メモリ | 85,120 KB |
| 最終ジャッジ日時 | 2026-07-07 09:08:55 |
| 合計ジャッジ時間 | 2,622 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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