結果

問題 No.1703 Much Matching
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-10-08 22:38:58
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,749 bytes
コンパイル時間 1,371 ms
コンパイル使用メモリ 86,368 KB
実行使用メモリ 163,168 KB
最終ジャッジ日時 2023-09-30 11:38:11
合計ジャッジ時間 27,600 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
70,760 KB
testcase_01 AC 74 ms
70,952 KB
testcase_02 AC 76 ms
70,988 KB
testcase_03 AC 75 ms
70,924 KB
testcase_04 AC 92 ms
75,684 KB
testcase_05 AC 84 ms
75,524 KB
testcase_06 AC 1,311 ms
123,420 KB
testcase_07 AC 149 ms
79,332 KB
testcase_08 AC 1,387 ms
124,728 KB
testcase_09 AC 1,582 ms
132,128 KB
testcase_10 AC 274 ms
84,592 KB
testcase_11 AC 364 ms
88,736 KB
testcase_12 AC 151 ms
78,588 KB
testcase_13 AC 595 ms
98,064 KB
testcase_14 AC 124 ms
77,972 KB
testcase_15 AC 310 ms
86,628 KB
testcase_16 AC 846 ms
107,584 KB
testcase_17 AC 953 ms
111,700 KB
testcase_18 AC 125 ms
77,556 KB
testcase_19 TLE -
testcase_20 AC 305 ms
85,976 KB
testcase_21 TLE -
testcase_22 AC 936 ms
110,064 KB
testcase_23 AC 711 ms
102,056 KB
testcase_24 AC 120 ms
77,528 KB
testcase_25 AC 176 ms
80,884 KB
testcase_26 AC 482 ms
93,340 KB
testcase_27 AC 1,037 ms
114,776 KB
testcase_28 TLE -
testcase_29 AC 399 ms
89,812 KB
testcase_30 AC 572 ms
96,856 KB
testcase_31 AC 147 ms
79,148 KB
testcase_32 AC 1,065 ms
114,640 KB
testcase_33 AC 700 ms
101,276 KB
testcase_34 AC 150 ms
78,568 KB
testcase_35 AC 240 ms
83,568 KB
testcase_36 TLE -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

class SegTree:
    """ define what you want to do with 0 index, ex) size = tree_size, func = min or max, sta = default_value """
    
    def __init__(self,size,func,sta):
        self.n = size
        self.size = 1 << size.bit_length()
        self.func = func
        self.sta = sta
        self.tree = [sta]*(2*self.size)

    def build(self, list):
        """ set list and update tree"""
        for i,x in enumerate(list,self.size):
            self.tree[i] = x

        for i in range(self.size-1,0,-1):
            self.tree[i] = self.func(self.tree[i<<1],self.tree[i<<1 | 1])

    def set(self,i,x):
        i += self.size
        self.tree[i] = x
        while i > 1:
            i >>= 1
            self.tree[i] = self.func(self.tree[i<<1],self.tree[i<<1 | 1])

    def pointget(self,x):
        return self.tree[x+self.size]

    def get(self,l,r):
        """ take the value of [l r) with func (min or max)"""
        l += self.size
        r += self.size
        res = self.sta

        while l < r:
            if l & 1:
                res = self.func(self.tree[l],res)
                l += 1
            if r & 1:
                res = self.func(self.tree[r-1],res)
            l >>= 1
            r >>= 1
        return res

def main():
    n,m,q = map(int,input().split())
    AB = [list(map(int,input().split())) for i in range(q)]
    AB.sort(key=lambda x:(x[0],-x[1]))

    def func(x,y):
        if x > y:
            return x
        return y

    seg = SegTree(m+5,func,0)

    for a,b in AB:
        now = seg.pointget(b)
        nex = seg.get(0,b)
        if now == nex+1:
            continue
        seg.set(b,nex+1)
    print(seg.get(0,m+2))

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