結果

問題 No.1703 Much Matching
ユーザー kept1994kept1994
提出日時 2022-05-04 03:19:38
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 3,592 bytes
コンパイル時間 395 ms
コンパイル使用メモリ 87,312 KB
実行使用メモリ 181,884 KB
最終ジャッジ日時 2023-09-16 02:27:32
合計ジャッジ時間 25,685 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
75,516 KB
testcase_01 AC 73 ms
71,140 KB
testcase_02 AC 74 ms
71,256 KB
testcase_03 AC 76 ms
71,120 KB
testcase_04 AC 92 ms
75,948 KB
testcase_05 AC 81 ms
76,136 KB
testcase_06 AC 1,137 ms
104,628 KB
testcase_07 AC 172 ms
78,868 KB
testcase_08 AC 1,195 ms
105,752 KB
testcase_09 AC 1,371 ms
109,996 KB
testcase_10 AC 279 ms
80,640 KB
testcase_11 AC 361 ms
82,956 KB
testcase_12 AC 171 ms
79,072 KB
testcase_13 AC 553 ms
87,904 KB
testcase_14 AC 140 ms
78,304 KB
testcase_15 AC 311 ms
81,768 KB
testcase_16 AC 766 ms
92,544 KB
testcase_17 AC 872 ms
95,900 KB
testcase_18 AC 138 ms
77,960 KB
testcase_19 AC 1,830 ms
123,752 KB
testcase_20 AC 306 ms
81,476 KB
testcase_21 TLE -
testcase_22 AC 840 ms
95,292 KB
testcase_23 AC 635 ms
90,224 KB
testcase_24 AC 139 ms
77,792 KB
testcase_25 AC 187 ms
79,348 KB
testcase_26 AC 448 ms
84,320 KB
testcase_27 AC 922 ms
98,284 KB
testcase_28 AC 1,746 ms
119,764 KB
testcase_29 AC 383 ms
83,180 KB
testcase_30 AC 526 ms
86,508 KB
testcase_31 AC 158 ms
78,560 KB
testcase_32 AC 944 ms
97,824 KB
testcase_33 AC 649 ms
89,236 KB
testcase_34 AC 169 ms
79,088 KB
testcase_35 AC 242 ms
80,440 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, input().split())
    l = []
    for _ in range(Q):
        a, b = list(map(int, input().split()))
        l.append((a, -b))
    l.sort()
    # print(l)
    l = [-ll[1] for ll in l]
    dp = SegTree(0, [0] * (M + 1), max)
    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