結果

問題 No.1703 Much Matching
ユーザー rlangevinrlangevin
提出日時 2023-03-01 12:36:06
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,187 bytes
コンパイル時間 245 ms
コンパイル使用メモリ 87,268 KB
実行使用メモリ 139,440 KB
最終ジャッジ日時 2023-10-14 17:08:28
合計ジャッジ時間 10,892 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,388 KB
testcase_01 AC 69 ms
71,436 KB
testcase_02 AC 69 ms
71,100 KB
testcase_03 AC 70 ms
71,140 KB
testcase_04 AC 84 ms
75,972 KB
testcase_05 AC 80 ms
75,692 KB
testcase_06 RE -
testcase_07 WA -
testcase_08 RE -
testcase_09 WA -
testcase_10 RE -
testcase_11 WA -
testcase_12 RE -
testcase_13 WA -
testcase_14 RE -
testcase_15 WA -
testcase_16 RE -
testcase_17 WA -
testcase_18 RE -
testcase_19 WA -
testcase_20 RE -
testcase_21 WA -
testcase_22 RE -
testcase_23 WA -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 RE -
testcase_31 WA -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 WA -
testcase_36 AC 835 ms
139,440 KB
testcase_37 AC 96 ms
75,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline

class SegmentTree:
    def __init__(self, size, f=max, default=0):
        self.size = 2**(size-1).bit_length() 
        self.default = default
        self.dat = [default]*(self.size*2) 
        self.f = f

    def update(self, i, x):
        i += self.size
        self.dat[i] = x
        while i > 0:
            i >>= 1
            self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1])

    def query(self, l, r):
        l += self.size
        r += self.size
        lres, rres = self.default, self.default
        while l < r:
            if l & 1:
                lres = self.f(lres, self.dat[l])
                l += 1

            if r & 1:
                r -= 1
                rres = self.f(self.dat[r], rres) 
            l >>= 1
            r >>= 1
        res = self.f(lres, rres)
        return res

N, M, Q = map(int, readline().split())
D = [[] for i in range(N)]
for i in range(Q):
    A, B = map(int, readline().split())
    A, B = A - 1, B - 1
    D[A].append(B)

dp = SegmentTree(M)
for i in range(M):
    for B in sorted(D[i], reverse=True):
        val = dp.query(0, B)
        dp.update(B, val + 1)

print(dp.query(0, M))
0