結果

問題 No.1557 Binary Variable
ユーザー ygd.ygd.
提出日時 2021-06-29 19:51:16
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,685 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 87,084 KB
実行使用メモリ 846,048 KB
最終ジャッジ日時 2023-09-08 04:59:24
合計ジャッジ時間 23,594 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 AC 70 ms
71,520 KB
testcase_04 AC 410 ms
90,176 KB
testcase_05 AC 392 ms
90,328 KB
testcase_06 AC 371 ms
90,256 KB
testcase_07 AC 391 ms
90,588 KB
testcase_08 AC 469 ms
90,540 KB
testcase_09 AC 501 ms
90,284 KB
testcase_10 AC 540 ms
91,476 KB
testcase_11 AC 533 ms
91,620 KB
testcase_12 AC 453 ms
90,432 KB
testcase_13 AC 539 ms
91,624 KB
testcase_14 AC 624 ms
123,540 KB
testcase_15 AC 523 ms
91,576 KB
testcase_16 AC 618 ms
121,592 KB
testcase_17 AC 585 ms
110,884 KB
testcase_18 AC 581 ms
105,828 KB
testcase_19 AC 939 ms
420,920 KB
testcase_20 AC 705 ms
193,516 KB
testcase_21 AC 728 ms
190,836 KB
testcase_22 AC 845 ms
272,804 KB
testcase_23 AC 730 ms
189,504 KB
testcase_24 AC 1,000 ms
470,944 KB
testcase_25 AC 957 ms
453,512 KB
testcase_26 MLE -
testcase_27 MLE -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

class SegmentTree(object):
    def __init__(self, A, dot, unit):
        n = 1 << (len(A) - 1).bit_length()
        tree = [unit] * (2 * n)
        for i, v in enumerate(A):
            tree[i + n] = v
        for i in range(n - 1, 0, -1):
            tree[i] = dot(tree[i << 1], tree[i << 1 | 1])
        self._n = n
        self._tree = tree
        self._dot = dot
        self._unit = unit

    def __getitem__(self, i):
        return self._tree[i + self._n]

    def update(self, i, v):
        i += self._n
        self._tree[i] = v
        while i != 1:
            i >>= 1
            self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1])

    def add(self, i, v):
        self.update(i, self[i] + v)

    def sum(self, l, r): #これで[l,r)から取り出す。
        l += self._n
        r += self._n
        l_val = r_val = self._unit
        while l < r:
            if l & 1:
                l_val = self._dot(l_val, self._tree[l])
                l += 1
            if r & 1:
                r -= 1
                r_val = self._dot(self._tree[r], r_val)
            l >>= 1
            r >>= 1
        return self._dot(l_val, r_val)

def segfunc(x,y):
    return x*y

def main():
    N,M = map(int,input().split())
    Z = []
    for _ in range(M):
        l,r = map(int,input().split())
        l-=1;r-=1 #0-index
        Z.append((l,r))
    Z.sort(key = lambda x: x[1])
    A = [1]*N
    Tree = SegmentTree(A,segfunc,1)
    for i in range(M):
        l,r = Z[i]
        if Tree.sum(l,r+1) == 1:
            Tree.update(r,0)
    ans = 0
    for i in range(N):
        ans += Tree.__getitem__(i)
    print(ans)


if __name__ == '__main__':
    main()
0