結果

問題 No.1868 Teleporting Cyanmond
ユーザー 👑 rin204rin204
提出日時 2022-03-11 21:27:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 199 ms / 2,000 ms
コード長 1,628 bytes
コンパイル時間 535 ms
コンパイル使用メモリ 86,968 KB
実行使用メモリ 93,972 KB
最終ジャッジ日時 2023-10-14 06:13:45
合計ジャッジ時間 6,703 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,112 KB
testcase_01 AC 70 ms
71,540 KB
testcase_02 AC 71 ms
71,180 KB
testcase_03 AC 199 ms
91,536 KB
testcase_04 AC 176 ms
86,400 KB
testcase_05 AC 123 ms
77,856 KB
testcase_06 AC 135 ms
78,576 KB
testcase_07 AC 158 ms
83,724 KB
testcase_08 AC 149 ms
80,500 KB
testcase_09 AC 164 ms
82,848 KB
testcase_10 AC 193 ms
89,928 KB
testcase_11 AC 108 ms
77,708 KB
testcase_12 AC 149 ms
79,592 KB
testcase_13 AC 159 ms
83,668 KB
testcase_14 AC 190 ms
91,584 KB
testcase_15 AC 171 ms
85,848 KB
testcase_16 AC 139 ms
78,756 KB
testcase_17 AC 150 ms
79,148 KB
testcase_18 AC 180 ms
93,688 KB
testcase_19 AC 186 ms
93,532 KB
testcase_20 AC 186 ms
93,208 KB
testcase_21 AC 186 ms
93,492 KB
testcase_22 AC 187 ms
93,404 KB
testcase_23 AC 177 ms
93,824 KB
testcase_24 AC 179 ms
93,972 KB
testcase_25 AC 182 ms
93,780 KB
testcase_26 AC 168 ms
93,808 KB
testcase_27 AC 173 ms
93,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class SegTree:
    def __init__(self, n, e, ope, lst=[]):
        self.N0 = 2 ** (n - 1).bit_length()
        self.e = e
        self.ope = ope
        self.data = [e] * (2 * self.N0)
        if lst:
            for i in range(n):
                self.data[self.N0 + i] = lst[i]
            for i in range(self.N0 - 1, 0, -1):
                self.data[i] = self.ope(self.data[2 * i], self.data[2 * i + 1])
    
    def f5(self):
        for i in range(self.N0 - 1, 0, -1):
            self.data[i] = self.ope(self.data[2 * i], self.data[2 * i + 1])
                
    def update(self, i, x): #a_iの値をxに更新
        i += self.N0
        self.data[i] = x
        while i > 1:
            i >>= 1
            self.data[i] = self.ope(self.data[2 * i], self.data[2 * i + 1])
    
    def add(self, i, x):
        self.update(i, x + self.get(i))
    
    def query(self, l, r): #区間[l, r)での演算結果
        if r <= l:
            return self.e
        lres = self.e
        rres = self.e
        l += self.N0
        r += self.N0
        while l < r:
            if l & 1:
                lres = self.ope(lres, self.data[l])
                l += 1
            if r & 1:
                r -= 1
                rres = self.ope(self.data[r], rres)
            l >>= 1
            r >>= 1
        return self.ope(lres, rres)
    
    def get(self, i): #a_iの値を返す
        return self.data[self.N0 + i]

n = int(input())
R = list(map(int, input().split()))
seg = SegTree(n, 1 << 30, min, [0] * n)

for i in range(n - 2, -1, -1):
    r = R[i]
    seg.update(i, seg.query(i + 1, r) + 1)

print(seg.get(0))
    
0