結果
問題 |
No.365 ジェンガソート
|
ユーザー |
![]() |
提出日時 | 2022-05-13 23:14:02 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,163 bytes |
コンパイル時間 | 410 ms |
コンパイル使用メモリ | 82,012 KB |
実行使用メモリ | 92,424 KB |
最終ジャッジ日時 | 2024-07-22 03:31:55 |
合計ジャッジ時間 | 5,443 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 WA * 25 |
ソースコード
class Binary_Indexed_Tree: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) self.depth = n.bit_length() # 配列のi番目までの和 1-indexed def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s # 区間[l, r)の和 def get_sum(self, l, r): return self.sum(r-1) - self.sum(l-1) # 1-indexed 配列のi番目にxを足す def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i def lower_bound(self, x): """ 累積和がx以上になる最小のindexと、その直前までの累積和 """ sum_ = 0 pos = 0 for i in range(self.depth, -1, -1): k = pos + (1 << i) if k <= self.size and sum_ + self.tree[k] < x: sum_ += self.tree[k] pos += 1 << i return pos + 1, sum_ N = int(input()) a = list(map(int, input().split())) BIT = Binary_Indexed_Tree(N) res = 0 for i in range(N): BIT.add(a[i], 1) if BIT.get_sum(a[i]+1, N+1)>0: res += 1 print(res)