結果

問題 No.1703 Much Matching
ユーザー aaaaaaaaaa2230
提出日時 2021-10-08 22:37:04
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,638 bytes
コンパイル時間 1,074 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 240,512 KB
最終ジャッジ日時 2024-07-23 05:39:09
合計ジャッジ時間 26,653 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31 TLE * 3 -- * 1
権限があれば一括ダウンロードができます

ソースコード

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