結果

問題 No.1703 Much Matching
ユーザー kept1994kept1994
提出日時 2022-05-04 03:24:26
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 3,587 bytes
コンパイル時間 561 ms
コンパイル使用メモリ 87,132 KB
実行使用メモリ 171,220 KB
最終ジャッジ日時 2023-09-16 02:34:03
合計ジャッジ時間 25,853 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,264 KB
testcase_01 AC 76 ms
71,240 KB
testcase_02 AC 75 ms
71,340 KB
testcase_03 AC 77 ms
71,308 KB
testcase_04 AC 89 ms
75,840 KB
testcase_05 AC 81 ms
75,712 KB
testcase_06 AC 1,045 ms
97,380 KB
testcase_07 AC 147 ms
78,560 KB
testcase_08 AC 1,076 ms
97,900 KB
testcase_09 AC 1,243 ms
102,480 KB
testcase_10 AC 246 ms
80,056 KB
testcase_11 AC 319 ms
81,592 KB
testcase_12 AC 150 ms
78,744 KB
testcase_13 AC 499 ms
84,704 KB
testcase_14 AC 126 ms
77,504 KB
testcase_15 AC 279 ms
80,720 KB
testcase_16 AC 687 ms
88,284 KB
testcase_17 AC 788 ms
91,276 KB
testcase_18 AC 122 ms
77,584 KB
testcase_19 AC 1,657 ms
113,620 KB
testcase_20 AC 269 ms
80,552 KB
testcase_21 AC 1,965 ms
120,340 KB
testcase_22 AC 753 ms
90,544 KB
testcase_23 AC 580 ms
87,208 KB
testcase_24 AC 120 ms
77,560 KB
testcase_25 AC 164 ms
78,724 KB
testcase_26 AC 406 ms
83,656 KB
testcase_27 AC 849 ms
91,948 KB
testcase_28 AC 1,593 ms
108,648 KB
testcase_29 AC 337 ms
82,388 KB
testcase_30 AC 468 ms
84,844 KB
testcase_31 AC 137 ms
78,232 KB
testcase_32 AC 856 ms
92,052 KB
testcase_33 AC 573 ms
85,316 KB
testcase_34 AC 147 ms
78,512 KB
testcase_35 AC 209 ms
79,712 KB
testcase_36 TLE -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

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, M, Q = map(int, sys.stdin.readline().split())
    l = []
    for _ in range(Q):
        a, b = map(int, sys.stdin.readline().split())
        l.append((a, -b))
    l.sort()
    dp = SegTree(0, [0] * (M + 1), max)
    for ll in [-ll[1] for ll in l]:
        num = dp.getRange(0, ll)
        dp.pointUpdate(ll, num + 1)
    print(dp.getRange(0, M + 1))
    return

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