結果
問題 | No.742 にゃんにゃんにゃん 猫の挨拶 |
ユーザー | stng |
提出日時 | 2022-05-28 16:47:37 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 96 ms / 2,500 ms |
コード長 | 612 bytes |
コンパイル時間 | 233 ms |
コンパイル使用メモリ | 81,840 KB |
実行使用メモリ | 76,892 KB |
最終ジャッジ日時 | 2023-10-20 23:23:33 |
合計ジャッジ時間 | 2,154 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
55,600 KB |
testcase_01 | AC | 41 ms
55,600 KB |
testcase_02 | AC | 42 ms
55,600 KB |
testcase_03 | AC | 45 ms
55,600 KB |
testcase_04 | AC | 43 ms
55,600 KB |
testcase_05 | AC | 47 ms
61,484 KB |
testcase_06 | AC | 52 ms
63,548 KB |
testcase_07 | AC | 70 ms
72,968 KB |
testcase_08 | AC | 73 ms
72,968 KB |
testcase_09 | AC | 41 ms
55,608 KB |
testcase_10 | AC | 41 ms
55,608 KB |
testcase_11 | AC | 96 ms
76,892 KB |
testcase_12 | AC | 94 ms
76,892 KB |
testcase_13 | AC | 41 ms
55,608 KB |
testcase_14 | AC | 42 ms
55,608 KB |
testcase_15 | AC | 42 ms
55,608 KB |
ソースコード
from collections import defaultdict, deque 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の配列liの転倒数を数え上げる" n = int(input()) m = [int(input()) for i in range(n)] bit = Bit(n+1) ans = 0 for i, p in enumerate(m): bit.add(p+1, 1) ans += i + 1 - bit.sum(p+1) print(ans)