結果
問題 | No.1438 Broken Drawers |
ユーザー | shotoyoo |
提出日時 | 2021-03-27 12:16:34 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 129 ms / 2,000 ms |
コード長 | 3,838 bytes |
コンパイル時間 | 213 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 122,880 KB |
最終ジャッジ日時 | 2024-11-29 08:15:39 |
合計ジャッジ時間 | 4,122 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
52,352 KB |
testcase_01 | AC | 34 ms
52,352 KB |
testcase_02 | AC | 33 ms
52,480 KB |
testcase_03 | AC | 34 ms
52,608 KB |
testcase_04 | AC | 37 ms
52,480 KB |
testcase_05 | AC | 34 ms
52,864 KB |
testcase_06 | AC | 102 ms
114,688 KB |
testcase_07 | AC | 103 ms
114,756 KB |
testcase_08 | AC | 35 ms
52,736 KB |
testcase_09 | AC | 35 ms
52,352 KB |
testcase_10 | AC | 35 ms
52,480 KB |
testcase_11 | AC | 44 ms
64,000 KB |
testcase_12 | AC | 70 ms
91,648 KB |
testcase_13 | AC | 91 ms
109,184 KB |
testcase_14 | AC | 62 ms
82,432 KB |
testcase_15 | AC | 120 ms
120,320 KB |
testcase_16 | AC | 120 ms
122,880 KB |
testcase_17 | AC | 126 ms
121,464 KB |
testcase_18 | AC | 129 ms
119,552 KB |
testcase_19 | AC | 124 ms
118,400 KB |
testcase_20 | AC | 125 ms
116,984 KB |
testcase_21 | AC | 124 ms
120,052 KB |
testcase_22 | AC | 123 ms
116,952 KB |
testcase_23 | AC | 122 ms
114,560 KB |
testcase_24 | AC | 123 ms
114,688 KB |
testcase_25 | AC | 126 ms
114,816 KB |
testcase_26 | AC | 124 ms
114,816 KB |
testcase_27 | AC | 118 ms
114,560 KB |
ソースコード
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(2*10**5+10) write = lambda x: sys.stdout.write(x+"\n") debug = lambda x: sys.stderr.write(x+"\n") ### セグメント木(はやい) class SG: def __init__(self, n, v=None): self._n = n self.geta = 0 x = 0 while (1 << x) < n: x += 1 self._log = x self._size = 1 << self._log self._d = [ninf] * (2 * self._size) if v is not None: for i in range(self._n): self._d[self._size + i] = v[i] for i in range(self._size - 1, 0, -1): self._update(i) def update(self, p, x): # assert 0 <= p < self._n x -= self.geta p += self._size self._d[p] = x for i in range(1, self._log + 1): # self._update(p >> i) k = p>>i self._d[k] = op(self._d[2 * k], self._d[2 * k + 1]) def get(self, p): # assert 0 <= p < self._n return self._d[p + self._size] + self.geta def check(self): return [self.get(p) for p in range(self._n)] def query(self, left, right): # assert 0 <= left <= right <= self._n sml = ninf smr = ninf left += self._size right += self._size while left < right: if left & 1: sml = op(sml, self._d[left]) left += 1 if right & 1: right -= 1 smr = op(self._d[right], smr) left >>= 1 right >>= 1 return op(sml, smr) + self.geta def update_all(self, v): # 全体加算 self.geta += v def _update(self, k): self._d[k] = op(self._d[2 * k], self._d[2 * k + 1]) def query_all(self): return self._d[1] + self.geta def max_right(self, left, f): """f(op(a[l], a[l + 1], ..., a[r - 1])) = true となる最大の r -> rはf(op(a[l:r+1]))がFalseになる最小のr """ # assert 0 <= left <= self._n # assert f(ninf) if left == self._n: return self._n left += self._size sm = ninf first = True while first or (left & -left) != left: first = False while left % 2 == 0: left >>= 1 if not f(op(sm, self._d[left])): while left < self._size: left *= 2 if f(op(sm, self._d[left])): sm = op(sm, self._d[left]) left += 1 return left - self._size sm = op(sm, self._d[left]) left += 1 return self._n def min_left(self, right, f): """f(op(a[l], a[l + 1], ..., a[r - 1])) = true となる最小の l """ # assert 0 <= right <= self._n # assert f(ninf) if right == 0: return 0 right += self._size sm = ninf first = True while first or (right & -right) != right: first = False right -= 1 while right > 1 and right % 2: right >>= 1 if not f(op(self._d[right], sm)): while right < self._size: right = 2 * right + 1 if f(op(self._d[right], sm)): sm = op(self._d[right], sm) right -= 1 return right + 1 - self._size sm = op(self._d[right], sm) return 0 op = min ninf = 10**12 n = int(input()) a = list(map(int, input().split())) pos = {} for i,v in enumerate(a): pos[v] = i done = [0]*n ans = 0 for v in range(1,n+1): p = pos[v] if done[p]: continue else: ans += 1 if p>=1: done[p-1] = 1 print(ans)