結果

問題 No.1687 What the Heck?
ユーザー wolgnikwolgnik
提出日時 2021-09-24 21:38:55
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,216 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 87,096 KB
実行使用メモリ 150,772 KB
最終ジャッジ日時 2023-09-18 20:57:01
合計ジャッジ時間 18,247 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
71,432 KB
testcase_01 AC 80 ms
71,392 KB
testcase_02 AC 83 ms
71,120 KB
testcase_03 WA -
testcase_04 AC 82 ms
71,320 KB
testcase_05 AC 82 ms
71,360 KB
testcase_06 WA -
testcase_07 AC 746 ms
101,920 KB
testcase_08 AC 1,014 ms
111,608 KB
testcase_09 AC 736 ms
101,736 KB
testcase_10 AC 518 ms
92,980 KB
testcase_11 AC 554 ms
93,364 KB
testcase_12 TLE -
testcase_13 TLE -
testcase_14 WA -
testcase_15 TLE -
testcase_16 WA -
testcase_17 WA -
testcase_18 TLE -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))

import heapq
hpush = heapq.heappush
hpop = heapq.heappop
h = []
for i in range(N):
  hpush(h, (-(i + 1) * 2, a[i] + 1, i))
  hpush(h, (-(i + 1), a[i], i))

class BIT:
  def __init__(self, n):
    self.n = n
    self.data = [0] * (n + 1)
    self.el = [0] * (n + 1)
  def sum(self, i):
    s = 0
    while i > 0:
      s += self.data[i]
      i -= i & -i
    return s
  def add(self, i, x):
    self.el[i] += x
    while i <= self.n:
      self.data[i] += x
      i += i & -i
  def get(self, i, j = None):
    if j is None:
      return self.el[i]
    return self.sum(j) - self.sum(i)
  def lowerbound(self, s):
    x = 0
    y = 0
    for i in range(self.n.bit_length(), -1, -1):
      k = x + (1 << i)
      if k <= self.n and (y + self.data[k] < s):
        y += self.data[k]
        x += 1 << i
    return x + 1

fwk = BIT(N + 1)
for x in range(1, N + 1): fwk.add(x, 1)

res = -N * (N + 1) // 2
vis = [0] * N
while len(h):
  c, x, i = hpop(h)
  if vis[i]: continue
  c = -c
  t = fwk.sum(x - 1)
  y = fwk.lowerbound(t + 1)
  if y > N: continue
  vis[i] = 1
  fwk.add(y, -1)
  res += c
  #print(i, c, res, t, y)
print(res)
0