結果
問題 | No.1557 Binary Variable |
ユーザー | ygd. |
提出日時 | 2021-06-29 19:58:15 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 962 ms / 2,000 ms |
コード長 | 1,940 bytes |
コンパイル時間 | 738 ms |
コンパイル使用メモリ | 87,012 KB |
実行使用メモリ | 215,424 KB |
最終ジャッジ日時 | 2023-09-08 05:09:26 |
合計ジャッジ時間 | 27,858 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 360 ms
155,536 KB |
testcase_01 | AC | 398 ms
114,212 KB |
testcase_02 | AC | 69 ms
71,204 KB |
testcase_03 | AC | 68 ms
71,376 KB |
testcase_04 | AC | 424 ms
90,476 KB |
testcase_05 | AC | 406 ms
90,584 KB |
testcase_06 | AC | 383 ms
90,148 KB |
testcase_07 | AC | 406 ms
90,456 KB |
testcase_08 | AC | 492 ms
90,772 KB |
testcase_09 | AC | 510 ms
90,868 KB |
testcase_10 | AC | 662 ms
107,004 KB |
testcase_11 | AC | 662 ms
108,576 KB |
testcase_12 | AC | 473 ms
90,720 KB |
testcase_13 | AC | 630 ms
109,412 KB |
testcase_14 | AC | 848 ms
191,424 KB |
testcase_15 | AC | 616 ms
113,072 KB |
testcase_16 | AC | 814 ms
189,184 KB |
testcase_17 | AC | 783 ms
161,376 KB |
testcase_18 | AC | 773 ms
150,796 KB |
testcase_19 | AC | 962 ms
215,144 KB |
testcase_20 | AC | 957 ms
214,600 KB |
testcase_21 | AC | 862 ms
214,996 KB |
testcase_22 | AC | 864 ms
215,424 KB |
testcase_23 | AC | 867 ms
215,040 KB |
testcase_24 | AC | 882 ms
214,948 KB |
testcase_25 | AC | 881 ms
214,896 KB |
testcase_26 | AC | 871 ms
211,200 KB |
testcase_27 | AC | 886 ms
210,972 KB |
testcase_28 | AC | 929 ms
211,084 KB |
testcase_29 | AC | 931 ms
211,216 KB |
testcase_30 | AC | 900 ms
210,860 KB |
testcase_31 | AC | 899 ms
210,672 KB |
testcase_32 | AC | 893 ms
211,108 KB |
testcase_33 | AC | 877 ms
207,540 KB |
testcase_34 | AC | 70 ms
71,316 KB |
testcase_35 | AC | 68 ms
71,380 KB |
testcase_36 | AC | 69 ms
71,332 KB |
ソースコード
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 = [] S = set([]) for _ in range(M): l,r = map(int,input().split()) l-=1;r-=1 #0-index Z.append((l,r)) S.add(l) S.add(r) Z.sort(key = lambda x: x[1]) val = 0 dic = {} S = list(S); S.sort() for s in S: dic[s] = val val += 1 NN = len(S) A = [1]*NN Tree = SegmentTree(A,segfunc,1) for i in range(M): l,r = Z[i] nl = dic[l] nr = dic[r] if Tree.sum(nl,nr+1) == 1: Tree.update(nr,0) ans = N for i in range(NN): if Tree.__getitem__(i) == 0: ans -= 1 #print(dic) print(ans) if __name__ == '__main__': main()