結果

問題 No.1703 Much Matching
ユーザー ygd.ygd.
提出日時 2021-10-10 11:26:21
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,808 bytes
コンパイル時間 798 ms
コンパイル使用メモリ 86,880 KB
実行使用メモリ 193,964 KB
最終ジャッジ日時 2023-10-12 06:21:04
合計ジャッジ時間 27,178 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
75,564 KB
testcase_01 AC 72 ms
71,452 KB
testcase_02 AC 73 ms
71,272 KB
testcase_03 AC 72 ms
71,372 KB
testcase_04 WA -
testcase_05 AC 77 ms
75,612 KB
testcase_06 WA -
testcase_07 AC 138 ms
78,776 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 755 ms
96,224 KB
testcase_18 WA -
testcase_19 AC 1,612 ms
120,720 KB
testcase_20 WA -
testcase_21 AC 1,888 ms
127,152 KB
testcase_22 WA -
testcase_23 AC 562 ms
93,268 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 818 ms
98,968 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 TLE -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#input = sys.stdin.readline
input = sys.stdin.buffer.readline

class SegmentTree(object):
    def __init__(self, A, dot, unit):
        n = 1 << (len(A) - 1).bit_length()
        tree = [unit] * (2 * n)
        for i, v in enumerate(A):
            tree[i + n] = v
        for i in range(n - 1, 0, -1):
            tree[i] = dot(tree[i << 1], tree[i << 1 | 1])
        self._n = n
        self._tree = tree
        self._dot = dot
        self._unit = unit

    def __getitem__(self, i):
        return self._tree[i + self._n]

    def update(self, i, v):
        i += self._n
        self._tree[i] = v
        while i != 1:
            i >>= 1
            self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1])

    def add(self, i, v):
        self.update(i, self[i] + v)

    def sum(self, l, r): #これで[l,r)から取り出す。
        l += self._n
        r += self._n
        l_val = r_val = self._unit
        while l < r:
            if l & 1:
                l_val = self._dot(l_val, self._tree[l])
                l += 1
            if r & 1:
                r -= 1
                r_val = self._dot(self._tree[r], r_val)
            l >>= 1
            r >>= 1
        return self._dot(l_val, r_val)

def main():
    N,M,Q = map(int,input().split())
    G = [[] for _ in range(Q)]
    L = []
    for i in range(Q):
        a,b = map(int,input().split())
        #a -= 1; b -= 1
        L.append((a,b)) #man,woman,index
    L.sort()
    Tree = SegmentTree([0]*(M+1),max,0) #womanがyの時の最大値
    for x,y in L:
        val = max(Tree.sum(0,y) + 1, Tree.__getitem__(y))
        #print(val)
        Tree.update(y,val)
    ans = 0
    for i in range(M+1):
        ans = max(ans,Tree.__getitem__(i))
    print(ans)
        

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