結果

問題 No.1995 CHIKA Road
ユーザー 👑 rin204rin204
提出日時 2022-07-01 21:45:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 535 ms / 2,000 ms
コード長 2,030 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 87,192 KB
実行使用メモリ 166,696 KB
最終ジャッジ日時 2023-08-17 09:15:13
合計ジャッジ時間 12,212 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,372 KB
testcase_01 AC 72 ms
71,404 KB
testcase_02 AC 74 ms
71,428 KB
testcase_03 AC 74 ms
71,164 KB
testcase_04 AC 76 ms
71,108 KB
testcase_05 AC 81 ms
75,604 KB
testcase_06 AC 179 ms
82,140 KB
testcase_07 AC 219 ms
95,608 KB
testcase_08 AC 85 ms
75,936 KB
testcase_09 AC 80 ms
75,612 KB
testcase_10 AC 249 ms
89,228 KB
testcase_11 AC 535 ms
166,696 KB
testcase_12 AC 336 ms
132,340 KB
testcase_13 AC 254 ms
106,248 KB
testcase_14 AC 252 ms
104,480 KB
testcase_15 AC 464 ms
141,232 KB
testcase_16 AC 197 ms
85,924 KB
testcase_17 AC 313 ms
118,184 KB
testcase_18 AC 441 ms
142,264 KB
testcase_19 AC 447 ms
141,976 KB
testcase_20 AC 303 ms
106,156 KB
testcase_21 AC 285 ms
109,436 KB
testcase_22 AC 413 ms
123,308 KB
testcase_23 AC 221 ms
95,748 KB
testcase_24 AC 383 ms
129,852 KB
testcase_25 AC 194 ms
85,572 KB
testcase_26 AC 242 ms
98,416 KB
testcase_27 AC 373 ms
129,420 KB
testcase_28 AC 285 ms
109,316 KB
testcase_29 AC 432 ms
141,268 KB
testcase_30 AC 187 ms
87,036 KB
testcase_31 AC 163 ms
81,004 KB
testcase_32 AC 195 ms
90,488 KB
testcase_33 AC 369 ms
129,128 KB
testcase_34 AC 157 ms
81,936 KB
testcase_35 AC 231 ms
97,824 KB
testcase_36 AC 245 ms
97,424 KB
testcase_37 AC 401 ms
117,884 KB
testcase_38 AC 331 ms
119,244 KB
testcase_39 AC 155 ms
81,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class SegTree:
    def __init__(self, n, e, ope, lst=[]):
        self.N0 = 2 ** (n - 1).bit_length()
        self.e = e
        self.ope = ope
        self.data = [e] * (2 * self.N0)
        if lst:
            for i in range(n):
                self.data[self.N0 + i] = lst[i]
            for i in range(self.N0 - 1, 0, -1):
                self.data[i] = self.ope(self.data[2 * i], self.data[2 * i + 1])
    
    def build(self):
        for i in range(self.N0 - 1, 0, -1):
            self.data[i] = self.ope(self.data[2 * i], self.data[2 * i + 1])
                
    def update(self, i, x): #a_iの値をxに更新
        i += self.N0
        self.data[i] = x
        while i > 1:
            i >>= 1
            self.data[i] = self.ope(self.data[2 * i], self.data[2 * i + 1])
    
    def add(self, i, x):
        self.update(i, x + self.get(i))

    def set(self, i, x):
        self.data[self.N0 + i] = x
    
    def query(self, l, r): #区間[l, r)での演算結果
        if r <= l:
            return self.e
        lres = self.e
        rres = self.e
        l += self.N0
        r += self.N0
        while l < r:
            if l & 1:
                lres = self.ope(lres, self.data[l])
                l += 1
            if r & 1:
                r -= 1
                rres = self.ope(self.data[r], rres)
            l >>= 1
            r >>= 1
        return self.ope(lres, rres)
    
    def get(self, i): #a_iの値を返す
        return self.data[self.N0 + i]

n, m = map(int, input().split())
se = set()
ab = [list(map(int, input().split())) for _ in range(m)]
for a, b in ab:
    se.add(a)
    se.add(b)
se.add(1)
le = len(se)
lst = sorted(se)
dic = {l:i for i, l in enumerate(lst)}
R = [[] for _ in range(le)]
for a, b in ab:
    a = dic[a]
    b = dic[b]
    R[b].append(a)
seg = SegTree(le, -1 << 30, max)
seg.update(0, 0)
for r in range(le):
    for l in R[r]:
        tmp = seg.query(0, l + 1) + 1
        if seg.get(r) < tmp:
            seg.update(r, tmp)
print(2 * (n - 1) - seg.query(0, le))
0