結果

問題 No.1995 CHIKA Road
ユーザー tassei903tassei903
提出日時 2022-07-01 22:45:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 569 ms / 2,000 ms
コード長 1,863 bytes
コンパイル時間 264 ms
コンパイル使用メモリ 86,948 KB
実行使用メモリ 166,652 KB
最終ジャッジ日時 2023-08-17 10:21:26
合計ジャッジ時間 12,343 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,580 KB
testcase_01 AC 72 ms
71,492 KB
testcase_02 AC 68 ms
71,496 KB
testcase_03 AC 67 ms
71,436 KB
testcase_04 AC 68 ms
71,444 KB
testcase_05 AC 76 ms
76,156 KB
testcase_06 AC 153 ms
82,032 KB
testcase_07 AC 213 ms
91,572 KB
testcase_08 AC 84 ms
76,316 KB
testcase_09 AC 80 ms
76,340 KB
testcase_10 AC 343 ms
98,144 KB
testcase_11 AC 569 ms
158,936 KB
testcase_12 AC 303 ms
122,608 KB
testcase_13 AC 254 ms
110,472 KB
testcase_14 AC 274 ms
111,152 KB
testcase_15 AC 514 ms
166,652 KB
testcase_16 AC 180 ms
85,224 KB
testcase_17 AC 332 ms
114,364 KB
testcase_18 AC 466 ms
136,528 KB
testcase_19 AC 486 ms
136,496 KB
testcase_20 AC 308 ms
114,584 KB
testcase_21 AC 280 ms
109,520 KB
testcase_22 AC 428 ms
137,352 KB
testcase_23 AC 221 ms
96,464 KB
testcase_24 AC 422 ms
121,844 KB
testcase_25 AC 182 ms
86,560 KB
testcase_26 AC 235 ms
99,848 KB
testcase_27 AC 405 ms
124,856 KB
testcase_28 AC 284 ms
109,572 KB
testcase_29 AC 469 ms
139,056 KB
testcase_30 AC 180 ms
86,000 KB
testcase_31 AC 156 ms
81,392 KB
testcase_32 AC 190 ms
88,472 KB
testcase_33 AC 389 ms
127,336 KB
testcase_34 AC 159 ms
82,056 KB
testcase_35 AC 233 ms
97,844 KB
testcase_36 AC 248 ms
102,184 KB
testcase_37 AC 423 ms
137,168 KB
testcase_38 AC 343 ms
111,620 KB
testcase_39 AC 148 ms
81,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################


class DualSegmentTree:
    def __init__(self, size, f, default):
        self.n = (size-1).bit_length()
        self.size = 1<<self.n
        self.default = default
        self.lazy = [default]*(self.size*2)
        self.f = f

    def propagate(self, k):
        lazy = self.lazy
        if lazy[k] != self.default:
            lazy[2*k] = self.f(lazy[2*k], lazy[k])
            lazy[2*k+1] = self.f(lazy[2*k+1], lazy[k])
            lazy[k] = self.default

    def thrust(self, k):
        for i in range(self.n,0,-1):
            self.propagate(k>>i)

    def update(self, a, b, x):
        a += self.size
        b += self.size-1
        self.thrust(a)
        self.thrust(b)
        l = a
        r = b + 1
        lazy = self.lazy
        while l < r:
            if l & 1:
                lazy[l] = self.f(lazy[l], x)
                l += 1
            if r & 1:
                r -= 1
                lazy[r] = self.f(lazy[r], x)
            l >>= 1
            r >>= 1
    
    def get(self, k):
        k += self.size
        self.thrust(k)
        return self.lazy[k]
n,m = na()
g = [na() for i in range(m)]
s = set()
for i in range(m):
    s.add(g[i][0])
    s.add(g[i][1])

d = {x:i for i, x in enumerate(sorted(s))}
for i in range(m):
    g[i] = [d[g[i][0]],d[g[i][1]]]
g = sorted(g,key = lambda x:x[1])

k = len(s)
inf = float("inf")
st = DualSegmentTree(k+1,max,-inf)
st.update(0,k+1,0)
for i in range(m):
    l,r = g[i]
    x = st.get(l)
    st.update(r,k+1,x + 1)
print(2*(n-1)-st.get(k))
0