結果

問題 No.711 競技レーティング単調増加
ユーザー kept1994kept1994
提出日時 2022-05-03 13:04:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 367 ms / 2,000 ms
コード長 3,668 bytes
コンパイル時間 322 ms
コンパイル使用メモリ 87,132 KB
実行使用メモリ 189,832 KB
最終ジャッジ日時 2023-09-15 09:18:44
合計ジャッジ時間 10,440 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
80,556 KB
testcase_01 AC 81 ms
80,508 KB
testcase_02 AC 82 ms
80,668 KB
testcase_03 AC 84 ms
80,700 KB
testcase_04 AC 86 ms
80,804 KB
testcase_05 AC 87 ms
80,620 KB
testcase_06 AC 85 ms
80,612 KB
testcase_07 AC 86 ms
80,660 KB
testcase_08 AC 85 ms
80,708 KB
testcase_09 AC 86 ms
80,632 KB
testcase_10 AC 86 ms
80,648 KB
testcase_11 AC 84 ms
80,660 KB
testcase_12 AC 85 ms
80,612 KB
testcase_13 AC 83 ms
80,508 KB
testcase_14 AC 82 ms
80,880 KB
testcase_15 AC 83 ms
80,476 KB
testcase_16 AC 85 ms
80,556 KB
testcase_17 AC 85 ms
80,596 KB
testcase_18 AC 269 ms
119,496 KB
testcase_19 AC 265 ms
111,916 KB
testcase_20 AC 277 ms
114,744 KB
testcase_21 AC 285 ms
120,476 KB
testcase_22 AC 267 ms
114,712 KB
testcase_23 AC 292 ms
124,044 KB
testcase_24 AC 298 ms
124,416 KB
testcase_25 AC 269 ms
111,396 KB
testcase_26 AC 281 ms
114,964 KB
testcase_27 AC 266 ms
111,556 KB
testcase_28 AC 167 ms
107,604 KB
testcase_29 AC 163 ms
106,436 KB
testcase_30 AC 300 ms
123,440 KB
testcase_31 AC 363 ms
157,420 KB
testcase_32 AC 367 ms
158,512 KB
testcase_33 AC 262 ms
119,892 KB
testcase_34 AC 249 ms
117,472 KB
testcase_35 AC 272 ms
142,464 KB
testcase_36 AC 113 ms
109,196 KB
testcase_37 AC 331 ms
189,832 KB
testcase_38 AC 301 ms
149,668 KB
testcase_39 AC 168 ms
109,384 KB
testcase_40 AC 179 ms
107,868 KB
testcase_41 AC 81 ms
80,552 KB
testcase_42 AC 149 ms
102,268 KB
testcase_43 AC 250 ms
130,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
import sys

MOD = 998244353

class SegTree:
    def __init__(self, monoid, bottomList, func, convertLengthToThePowerOf2: bool = False):
        self.monoid = monoid
        self.func = func
        if convertLengthToThePowerOf2:
            self.actualLen = len(bottomList)
            self.bottomLen = self.getSegLenOfThePowerOf2(len(bottomList))
            self.offset = self.bottomLen        # セグ木の最下層の最初のインデックスに合わせるためのオフセット
            self.segLen = self.bottomLen * 2
            self.tree = [monoid] * self.segLen
        else:
            self.actualLen = len(bottomList)
            self.bottomLen = len(bottomList)
            self.offset = self.bottomLen        # セグ木の最下層の最初のインデックスに合わせるためのオフセット
            self.segLen = self.bottomLen * 2
            self.tree = [monoid] * self.segLen
        self.build(bottomList)

    """
    初期化
    O(self.segLen)
    """
    def build(self, seq):
        # 最下段の初期化
        for i, x in enumerate(seq, self.offset):
            self.tree[i] = x
        # ビルド
        for i in range(self.offset - 1, 0, -1):
            self.tree[i] = self.func(self.tree[i << 1], self.tree[i << 1 | 1])

    """
    直近の2べきの長さを算出
    """
    def getSegLenOfThePowerOf2(self, ln: int):
        if ln <= 0:
            return 1
        else:    
            import math
            decimalPart, integerPart = math.modf(math.log2(ln))
            return 2 ** (int(integerPart) + 1)

    """
    一点加算 他演算
    O(log(self.bottomLen))
    """
    def pointAdd(self, i: int, val: int):
        i += self.offset
        self.tree[i] += val
        # self.tree[i] = self.func(self.tree[i], val) <- こっちの方が都度の修正は発生しない。再帰が遅くないか次第。
        while i > 1:
            i >>= 1 # 2で割って頂点に達するまで下層から遡上
            self.tree[i] = self.func(self.tree[i << 1], self.tree[i << 1 | 1]) # 必ず末尾0と1がペアになるのでor演算子

    """
    一点更新
    O(log(self.bottomLen))
    """
    def pointUpdate(self, i: int, val: int):
        i += self.offset
        self.tree[i] = val
        while i > 1:
            i >>= 1 # 2で割って頂点に達するまで下層から遡上
            self.tree[i] = self.func(self.tree[i << 1], self.tree[i << 1 | 1]) # 必ず末尾0と1がペアになるのでor演算子

    """
    区間取得
    O(log(self.bottomLen))
    """
    def getRange(self, l: int, r: int):
        l += self.offset
        r += self.offset
        vL = self.monoid
        vR = self.monoid
        while l < r:
            if l & 1:
                vL = self.func(vL, self.tree[l])
                l += 1
            if r & 1:
                r -= 1
                vR = self.func(self.tree[r], vR)
            l >>= 1
            r >>= 1
        return self.func(vL, vR)

    """
    一点取得
    O(log(self.bottomLen))
    """
    def getPoint(self, i: int):
        i += self.offset
        return self.tree[i]

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = [ aa - i for i, aa in enumerate(A) if aa - i > 0 ]
    compressed = {val : index for index, val in enumerate(sorted(list(set(B))))}
    B = [compressed[bb] for bb in B]
    dp = SegTree(0, [0] * (2 * 10 ** 5 + 1), max)
    for bb in B:
        num = dp.getRange(0, bb + 1)
        dp.pointUpdate(bb, num + 1)
    res = dp.getRange(0, 2 * 10 ** 5 + 1)
    print(N - res)
    return

if __name__ == '__main__':
    main()
0