結果

問題 No.1703 Much Matching
ユーザー tktk_snsntktk_snsn
提出日時 2021-10-08 22:33:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 821 ms / 2,000 ms
コード長 3,721 bytes
コンパイル時間 319 ms
コンパイル使用メモリ 86,872 KB
実行使用メモリ 130,948 KB
最終ジャッジ日時 2023-09-30 11:26:37
合計ジャッジ時間 9,962 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
70,928 KB
testcase_01 AC 75 ms
71,072 KB
testcase_02 AC 75 ms
71,008 KB
testcase_03 AC 76 ms
70,980 KB
testcase_04 AC 93 ms
75,604 KB
testcase_05 AC 85 ms
75,740 KB
testcase_06 AC 301 ms
83,324 KB
testcase_07 AC 125 ms
77,268 KB
testcase_08 AC 304 ms
83,248 KB
testcase_09 AC 331 ms
85,736 KB
testcase_10 AC 147 ms
77,584 KB
testcase_11 AC 169 ms
78,296 KB
testcase_12 AC 121 ms
77,392 KB
testcase_13 AC 196 ms
78,860 KB
testcase_14 AC 112 ms
77,332 KB
testcase_15 AC 154 ms
78,348 KB
testcase_16 AC 234 ms
80,560 KB
testcase_17 AC 245 ms
81,168 KB
testcase_18 AC 113 ms
77,112 KB
testcase_19 AC 422 ms
90,476 KB
testcase_20 AC 149 ms
78,404 KB
testcase_21 AC 472 ms
95,368 KB
testcase_22 AC 255 ms
80,632 KB
testcase_23 AC 213 ms
79,648 KB
testcase_24 AC 113 ms
77,648 KB
testcase_25 AC 129 ms
77,732 KB
testcase_26 AC 182 ms
79,064 KB
testcase_27 AC 266 ms
81,280 KB
testcase_28 AC 394 ms
88,276 KB
testcase_29 AC 168 ms
78,720 KB
testcase_30 AC 198 ms
78,852 KB
testcase_31 AC 127 ms
77,344 KB
testcase_32 AC 266 ms
81,412 KB
testcase_33 AC 218 ms
79,404 KB
testcase_34 AC 124 ms
77,844 KB
testcase_35 AC 143 ms
77,800 KB
testcase_36 AC 821 ms
130,948 KB
testcase_37 AC 99 ms
75,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)


class SegTree(object):
    def __init__(self, N, op_data, u_data):
        self._n = N
        self.log = (N-1).bit_length()
        self.size = 1 << self.log

        self.op = op_data
        self.e = u_data

        self.data = [u_data] * (2 * self.size)
        # self.len = [1] * (2 * self.size)

    def __repr__(self):
        res = [self.get(i) for i in range(self._n)]
        return " ".join(map(str, res))

    def _update(self, i):
        self.data[i] = self.op(self.data[i << 1], self.data[i << 1 | 1])

    def initialize(self, arr=None):
        """ segtreeをarrで初期化する。len(arr) == Nにすること """
        if arr:
            for i, a in enumerate(arr, self.size):
                self.data[i] = a
        for i in reversed(range(1, self.size)):
            self._update(i)
            # self.len[i] = self.len[i << 1] + self.len[i << 1 | 1]

    def update(self, p, x):
        """ data[p] = x とする (0-indexed)"""
        p += self.size
        self.data[p] = x
        for i in range(1, self.log + 1):
            self._update(p >> i)

    def get(self, p):
        """ data[p]を返す """
        return self.data[p + self.size]

    def prod(self, l, r):
        """
        op_data(data[l], data[l+1], ..., data[r-1])を返す (0-indexed)
        """
        sml = self.e
        smr = self.e
        l += self.size
        r += self.size

        while l < r:
            if l & 1:
                sml = self.op(sml, self.data[l])
                l += 1
            if r & 1:
                r -= 1
                smr = self.op(self.data[r], smr)
            l >>= 1
            r >>= 1
        return self.op(sml, smr)

    def all_prod(self):
        """ op(data[0], data[1], ... data[N-1])を返す """
        return self.data[1]

    def max_right(self, l, func):
        """
        func(l, l+1, ..., r-1) = True,
        func(l, l+1, ..., r-1, r) = Falseとなる r を返す
        """
        if l == self._n:
            return self._n
        l += self.size
        sm = self.e
        while True:
            while l % 2 == 0:
                l >>= 1
            if not func(self.op(sm, self.data[l])):
                while l < self.size:
                    l <<= 1
                    if func(self.op(sm, self.data[l])):
                        sm = self.op(sm, self.data[l])
                        l += 1
                return l - self.size
            sm = self.op(sm, self.data[l])
            l += 1
            if (l & -l) == l:
                break
        return self._n

    def min_left(self, r, func):
        """
        func(     l, l+1, ..., r-1) = True,
        func(l-1, l, l+1, ..., r-1) = Falseとなる l を返す
        """
        if r == 0:
            return 0
        r += self.size
        sm = self.e
        while True:
            r -= 1
            while r > 1 and r & 1:
                r >>= 1
            if not func(self.op(self.data[r], sm)):
                while r < self.size:
                    r = r << 1 | 1
                    if func(self.op(self.data[r], sm)):
                        sm = self.op(self.data[r], sm)
                        r -= 1
                return r + 1 - self.size
            sm = self.op(self.data[r], sm)
            if (r & -r) == r:
                break
        return 0


N, M, Q = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(Q):
    a, b = map(int, input().split())
    G[a-1].append(b)

seg = SegTree(M+1, max, -10)
seg.update(0, 0)
for x in range(N):
    for y in sorted(G[x], reverse=True):
        val = seg.prod(0, y) + 1
        seg.update(y, val)

print(seg.all_prod())
0