結果

問題 No.1734 Decreasing Elements
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-11-06 12:16:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,121 ms / 3,000 ms
コード長 1,602 bytes
コンパイル時間 1,441 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 132,244 KB
最終ジャッジ日時 2024-04-24 22:57:52
合計ジャッジ時間 21,205 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
57,088 KB
testcase_01 AC 48 ms
56,960 KB
testcase_02 AC 51 ms
63,488 KB
testcase_03 AC 48 ms
57,216 KB
testcase_04 AC 47 ms
57,088 KB
testcase_05 AC 48 ms
57,472 KB
testcase_06 AC 52 ms
63,104 KB
testcase_07 AC 994 ms
125,228 KB
testcase_08 AC 953 ms
125,940 KB
testcase_09 AC 949 ms
126,984 KB
testcase_10 AC 981 ms
129,044 KB
testcase_11 AC 938 ms
129,736 KB
testcase_12 AC 616 ms
110,504 KB
testcase_13 AC 924 ms
127,008 KB
testcase_14 AC 1,052 ms
132,244 KB
testcase_15 AC 1,006 ms
129,608 KB
testcase_16 AC 1,008 ms
131,236 KB
testcase_17 AC 1,028 ms
129,392 KB
testcase_18 AC 1,015 ms
130,084 KB
testcase_19 AC 1,079 ms
113,176 KB
testcase_20 AC 1,121 ms
113,824 KB
testcase_21 AC 890 ms
111,232 KB
testcase_22 AC 1,024 ms
117,352 KB
testcase_23 AC 980 ms
112,488 KB
testcase_24 AC 870 ms
113,056 KB
testcase_25 AC 1,090 ms
124,272 KB
testcase_26 AC 1,036 ms
123,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class BIT:
    def __init__(self, n):
        self.size = n
        self.tree = [0]*(n+1)
 
    def build(self, list):
        self.tree[1:] = list.copy()
        for i in range(self.size+1):
            j = i + (i & (-i))
            if j < self.size+1:
                self.tree[j] += self.tree[i]

    def sum(self, i):
        # [0, i) の要素の総和を返す
        s = 0
        while i>0:
            s += self.tree[i]
            i -= i & -i
        return s
    # 0 index を 1 index に変更  転倒数を求めるなら1を足していく
    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    # 総和がx以上になる位置のindex をbinary search
    def bsearch(self,x):
        le = 0
        ri = 1<<(self.size.bit_length()-1)
        while ri > 0:
            if le+ri <= self.size and self.tree[le+ri]<x:
                x -= self.tree[le+ri]
                le += ri
            ri >>= 1
        return le+1

from heapq import heappop, heappush

n = int(input())
A = list(map(int,input().split()))
M = 2*10**5
use = [0]*(2*M+1)
use[0] = 1
ans = 0
h = [[-M,0]]
bit = BIT(M+2)
bit.add(0,1)
bit.add(M+1,1)

for a in A:
    if use[a]:
        continue
    ans += 1
    num = bit.sum(a)

    ind = bit.bsearch(num)-1
    now = a-ind
    l = []
    while h and -h[0][0] >= now:
        size,lind = heappop(h)
        size *= -1
        use[lind+now] = 1
        bit.add(lind+now,1)
        l.append([-now+1,lind])
        l.append([-size+now,lind+now])
    for nex in l:
        heappush(h,nex)
print(ans)
0