結果

問題 No.1995 CHIKA Road
ユーザー tassei903tassei903
提出日時 2022-07-01 22:45:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 592 ms / 2,000 ms
コード長 1,863 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 160,384 KB
最終ジャッジ日時 2024-05-04 17:09:25
合計ジャッジ時間 11,845 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,480 KB
testcase_01 AC 39 ms
52,736 KB
testcase_02 AC 37 ms
52,608 KB
testcase_03 AC 36 ms
52,480 KB
testcase_04 AC 38 ms
52,736 KB
testcase_05 AC 50 ms
61,824 KB
testcase_06 AC 135 ms
80,768 KB
testcase_07 AC 205 ms
90,060 KB
testcase_08 AC 60 ms
64,768 KB
testcase_09 AC 62 ms
63,104 KB
testcase_10 AC 342 ms
96,768 KB
testcase_11 AC 592 ms
160,384 KB
testcase_12 AC 278 ms
124,160 KB
testcase_13 AC 235 ms
109,312 KB
testcase_14 AC 250 ms
110,080 KB
testcase_15 AC 497 ms
140,036 KB
testcase_16 AC 154 ms
84,352 KB
testcase_17 AC 315 ms
116,992 KB
testcase_18 AC 483 ms
137,600 KB
testcase_19 AC 485 ms
137,728 KB
testcase_20 AC 295 ms
113,792 KB
testcase_21 AC 279 ms
100,888 KB
testcase_22 AC 432 ms
136,704 KB
testcase_23 AC 201 ms
90,988 KB
testcase_24 AC 411 ms
123,392 KB
testcase_25 AC 168 ms
85,376 KB
testcase_26 AC 218 ms
99,072 KB
testcase_27 AC 405 ms
126,720 KB
testcase_28 AC 279 ms
100,880 KB
testcase_29 AC 454 ms
140,672 KB
testcase_30 AC 159 ms
85,508 KB
testcase_31 AC 134 ms
80,640 KB
testcase_32 AC 171 ms
87,808 KB
testcase_33 AC 376 ms
128,384 KB
testcase_34 AC 135 ms
81,024 KB
testcase_35 AC 214 ms
97,408 KB
testcase_36 AC 233 ms
101,120 KB
testcase_37 AC 412 ms
136,064 KB
testcase_38 AC 333 ms
113,152 KB
testcase_39 AC 125 ms
79,872 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