結果
| 問題 | No.365 ジェンガソート | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2021-06-29 19:44:19 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 690 bytes | 
| コンパイル時間 | 240 ms | 
| コンパイル使用メモリ | 82,432 KB | 
| 実行使用メモリ | 92,288 KB | 
| 最終ジャッジ日時 | 2024-06-25 22:06:12 | 
| 合計ジャッジ時間 | 4,247 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 16 WA * 25 | 
ソースコード
# 0-indexed binary indexed tree
class BIT:
  def __init__(self, n):
    self.n = n
    self.data = [0]*(n+1)
    self.el = [0]*(n+1)
  # sum of [0,i) sum(a[:i])
  def sum(self, i):
    if i==0:return 0
    s = 0
    while i > 0:
      s += self.data[i]
      i -= i & -i
    return s
  def add(self, i, x):
    i+=1
    self.el[i] += x
    while i <= self.n:
      self.data[i] += x
      i += i & -i
  # sum of [l,r)   sum(a[l:r])
  def sumlr(self, i, j):
    return self.sum(j) - self.sum(i)
  # a[i]
  def get(self,i):
    i+=1
    return self.el[i]
n=int(input())
a=list(map(int,input().split()))
bit=BIT(n+1)
ans=0
for x in a[::-1]:
  ans=max(ans,bit.sum(x))
  bit.add(x,1)
print(ans)
            
            
            
        