結果

問題 No.3116 More and more teleporter
ユーザー hir355
提出日時 2025-04-19 04:26:29
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,222 bytes
コンパイル時間 785 ms
コンパイル使用メモリ 82,848 KB
実行使用メモリ 83,424 KB
最終ジャッジ日時 2025-04-19 04:26:39
合計ジャッジ時間 9,551 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 6 WA * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

class SegmentTree:
    # 初期化処理
    # f : SegmentTreeにのせるモノイド
    # default : fに対する単位元
    def __init__(self, size, f=lambda x,y : max(x, y), default=0):
        self.size = 2**(size-1).bit_length()
        self.default = default
        self.dat = [default]*(self.size*2)
        self.f = f

    def update(self, i, x):
        i += self.size
        self.dat[i] = x
        while i > 0:
            i >>= 1
            self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1])

    def query(self, l, r):
        l += self.size
        r += self.size
        lres, rres = self.default, self.default
        while l < r:
            if l & 1:
                lres = self.f(lres, self.dat[l])
                l += 1
            l >>= 1

            if r & 1:
                r -= 1
                rres = self.f(self.dat[r], rres) 
            r >>= 1
        res = self.f(lres, rres)
        return res

n, q = map(int, input().split())
seg = SegmentTree(n)
for _ in range(q):
    t, *u = map(int, input().split())
    if t == 1:
        x = u[0]
        print(x - seg.query(0, x + 1) - 1)
    else:
        x, c = u
        x -= 1
        seg.update(x, max(x - c, seg.query(x, x + 1)))
0