結果

問題 No.1868 Teleporting Cyanmond
ユーザー chineristACchineristAC
提出日時 2022-03-11 21:22:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 278 ms / 2,000 ms
コード長 2,506 bytes
コンパイル時間 284 ms
コンパイル使用メモリ 87,144 KB
実行使用メモリ 97,428 KB
最終ジャッジ日時 2023-10-14 06:02:00
合計ジャッジ時間 8,138 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
74,396 KB
testcase_01 AC 113 ms
74,620 KB
testcase_02 AC 114 ms
74,428 KB
testcase_03 AC 278 ms
95,404 KB
testcase_04 AC 246 ms
90,188 KB
testcase_05 AC 179 ms
82,400 KB
testcase_06 AC 194 ms
82,588 KB
testcase_07 AC 215 ms
87,676 KB
testcase_08 AC 202 ms
84,640 KB
testcase_09 AC 218 ms
86,832 KB
testcase_10 AC 265 ms
93,876 KB
testcase_11 AC 161 ms
81,664 KB
testcase_12 AC 200 ms
83,400 KB
testcase_13 AC 215 ms
87,628 KB
testcase_14 AC 248 ms
95,680 KB
testcase_15 AC 224 ms
89,932 KB
testcase_16 AC 194 ms
82,352 KB
testcase_17 AC 198 ms
83,444 KB
testcase_18 AC 234 ms
97,096 KB
testcase_19 AC 247 ms
97,120 KB
testcase_20 AC 248 ms
97,428 KB
testcase_21 AC 244 ms
97,084 KB
testcase_22 AC 247 ms
97,344 KB
testcase_23 AC 230 ms
97,048 KB
testcase_24 AC 226 ms
97,144 KB
testcase_25 AC 225 ms
97,152 KB
testcase_26 AC 222 ms
97,156 KB
testcase_27 AC 232 ms
97,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class SegmentTree:
    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        self.size = n
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        k += self.num
        self.tree[k] = x
        while k > 1:
            k >>= 1
            self.tree[k] = self.segfunc(self.tree[2*k], self.tree[2*k+1])

    def query(self, l, r):
        if r==self.size:
            r = self.num

        res = self.ide_ele

        l += self.num
        r += self.num
        right = []
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                right.append(self.tree[r-1])
            l >>= 1
            r >>= 1

        for e in right[::-1]:
            res = self.segfunc(res,e)
        return res

    def bisect(self,l,r,x):
        if r==self.size:
            r = self.num
        l += self.num
        r += self.num
        segment = []
        segment_r = []
        while l<r:
            if l&1:
                segment.append(l)
                l += 1
            if r&1:
                segment_r.append(r-1)
            l >>= 1
            r >>= 1
        segment += segment_r[::-1]
        tmp = self.ide_ele
        for pos in segment:
            check = self.segfunc(tmp,self.tree[pos])
            if check > x:
                break
            else:
                tmp = check
        else:
            return -1
        
        while pos < self.num:
            check = self.segfunc(tmp,self.tree[2*pos])
            if check > x:
                pos = 2 * pos
            else:
                tmp = check
                pos = 2 * pos + 1
        return pos - self.num

import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import log,gcd

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

N = int(input())
R = li()

dp = SegmentTree([N+1]*N,min,N+1)
dp.update(N-1,0)
for i in range(N-1)[::-1]:
    tmp = dp.query(i+1,R[i]) + 1
    dp.update(i,tmp)

print(dp.query(0,1))

0