結果

問題 No.1703 Much Matching
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-10-08 22:37:04
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,638 bytes
コンパイル時間 968 ms
コンパイル使用メモリ 86,772 KB
実行使用メモリ 241,076 KB
最終ジャッジ日時 2023-09-30 11:34:56
合計ジャッジ時間 15,636 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,084 KB
testcase_01 AC 70 ms
71,004 KB
testcase_02 AC 69 ms
70,848 KB
testcase_03 AC 72 ms
70,980 KB
testcase_04 AC 84 ms
75,760 KB
testcase_05 AC 80 ms
75,836 KB
testcase_06 AC 1,324 ms
122,992 KB
testcase_07 AC 141 ms
79,504 KB
testcase_08 AC 1,381 ms
124,868 KB
testcase_09 AC 1,596 ms
132,100 KB
testcase_10 AC 279 ms
84,940 KB
testcase_11 AC 366 ms
88,816 KB
testcase_12 AC 148 ms
78,504 KB
testcase_13 AC 613 ms
98,564 KB
testcase_14 AC 119 ms
77,892 KB
testcase_15 AC 310 ms
86,320 KB
testcase_16 AC 848 ms
106,832 KB
testcase_17 AC 966 ms
112,044 KB
testcase_18 AC 129 ms
77,460 KB
testcase_19 TLE -
testcase_20 AC 305 ms
86,572 KB
testcase_21 TLE -
testcase_22 AC 938 ms
110,400 KB
testcase_23 AC 705 ms
102,348 KB
testcase_24 AC 115 ms
78,120 KB
testcase_25 AC 172 ms
81,100 KB
testcase_26 AC 489 ms
93,852 KB
testcase_27 AC 1,037 ms
115,976 KB
testcase_28 TLE -
testcase_29 AC 393 ms
90,412 KB
testcase_30 AC 557 ms
97,572 KB
testcase_31 AC 143 ms
79,820 KB
testcase_32 AC 1,110 ms
114,984 KB
testcase_33 AC 707 ms
101,716 KB
testcase_34 AC 147 ms
79,488 KB
testcase_35 AC 240 ms
83,832 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

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))
0