結果
問題 | No.742 にゃんにゃんにゃん 猫の挨拶 |
ユーザー |
![]() |
提出日時 | 2019-09-18 21:39:34 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 86 ms / 2,500 ms |
コード長 | 573 bytes |
コンパイル時間 | 418 ms |
コンパイル使用メモリ | 82,160 KB |
実行使用メモリ | 77,088 KB |
最終ジャッジ日時 | 2024-07-16 03:17:28 |
合計ジャッジ時間 | 1,663 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 |
ソースコード
class fenwick_tree:def __init__(self, n):self.n = n#x, a1, a2, ..., anself.arr = [0] * (n+1)def add(self, i, x): #1_indexedwhile i <= self.n:self.arr[i] += xi += i & -idef query(self, i): #a1 + a2 + ... + aires = 0while i > 0:res += self.arr[i]i -= i & -ireturn resN = int(input())M = [int(input()) for _ in range(N)]ft = fenwick_tree(N)ans = 0for i in range(N):ans += i - ft.query(M[i]-1)ft.add(M[i], 1)print(ans)