結果

問題 No.1703 Much Matching
ユーザー ygd.ygd.
提出日時 2021-10-10 11:40:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 978 ms / 2,000 ms
コード長 2,179 bytes
コンパイル時間 463 ms
コンパイル使用メモリ 87,260 KB
実行使用メモリ 171,856 KB
最終ジャッジ日時 2023-10-12 06:36:38
合計ジャッジ時間 11,904 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
71,812 KB
testcase_01 AC 91 ms
71,576 KB
testcase_02 AC 91 ms
71,656 KB
testcase_03 AC 93 ms
72,460 KB
testcase_04 AC 109 ms
76,868 KB
testcase_05 AC 100 ms
76,656 KB
testcase_06 AC 316 ms
94,572 KB
testcase_07 AC 144 ms
78,972 KB
testcase_08 AC 342 ms
96,368 KB
testcase_09 AC 368 ms
99,488 KB
testcase_10 AC 161 ms
80,360 KB
testcase_11 AC 185 ms
81,520 KB
testcase_12 AC 139 ms
78,480 KB
testcase_13 AC 219 ms
85,060 KB
testcase_14 AC 130 ms
78,412 KB
testcase_15 AC 177 ms
81,268 KB
testcase_16 AC 252 ms
88,276 KB
testcase_17 AC 275 ms
90,464 KB
testcase_18 AC 127 ms
78,464 KB
testcase_19 AC 463 ms
109,104 KB
testcase_20 AC 182 ms
80,884 KB
testcase_21 AC 557 ms
116,664 KB
testcase_22 AC 271 ms
89,512 KB
testcase_23 AC 239 ms
86,488 KB
testcase_24 AC 127 ms
78,484 KB
testcase_25 AC 148 ms
79,160 KB
testcase_26 AC 217 ms
83,888 KB
testcase_27 AC 312 ms
90,868 KB
testcase_28 AC 467 ms
106,744 KB
testcase_29 AC 202 ms
82,368 KB
testcase_30 AC 226 ms
84,848 KB
testcase_31 AC 150 ms
79,644 KB
testcase_32 AC 285 ms
90,648 KB
testcase_33 AC 257 ms
86,168 KB
testcase_34 AC 153 ms
78,896 KB
testcase_35 AC 174 ms
80,516 KB
testcase_36 AC 978 ms
171,856 KB
testcase_37 AC 130 ms
76,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#input = sys.stdin.readline
input = sys.stdin.buffer.readline
from collections import defaultdict 

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 = []
    dic = defaultdict(list)
    for i in range(Q):
        a,b = map(int,input().split())
        #a -= 1; b -= 1
        #L.append((a,b)) #man,woman,index
        dic[a].append(b)
    #print(dic)
    KEY = list(dic.keys())
    KEY.sort()
    Tree = SegmentTree([0]*(M+1),max,0) #womanがyの時の最大値
    for x in KEY:
        L = sorted(dic[x])
        #print(L)
        val = []
        #if len(L) == 0: continue
        for y in L:
            temp = max(Tree.sum(0,y) + 1, Tree.__getitem__(y))
            #print(val)
            val.append(temp)
        for i in range(len(val)):
            y = L[i]
            v = val[i]
            Tree.update(y,v)
    ans = 0
    for i in range(M+1):
        ans = max(ans,Tree.__getitem__(i))
    print(ans)
        

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