結果

問題 No.3116 More and more teleporter
ユーザー keymoon
提出日時 2025-04-19 06:15:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 366 ms / 2,000 ms
コード長 1,044 bytes
コンパイル時間 239 ms
コンパイル使用メモリ 82,736 KB
実行使用メモリ 93,108 KB
最終ジャッジ日時 2025-04-19 06:15:43
合計ジャッジ時間 6,229 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

INF = 2**60

class FenwickMin:
    def __init__(self, n):
        self.n = n
        self.t = [INF] * (n + 1)
    def update(self, i, v):
        while i <= self.n:
            if v < self.t[i]:
                self.t[i] = v
            else:
                pass
            i += i & -i
    def query(self, i):
        res = INF
        while i > 0:
            if self.t[i] < res:
                res = self.t[i]
            i -= i & -i
        return res

N, Q = map(int, input().split())
ft_left  = FenwickMin(N)
ft_right = FenwickMin(N)

out = []
for _ in range(Q):
    q = input().split()
    if q[0] == '1':
        x = int(q[1])
        ans = x - 1

        m1 = ft_left.query(x)
        if m1 < INF:
            ans = min(ans, m1 + x)

        j = N - x + 1
        m2 = ft_right.query(j)
        if m2 < INF:
            ans = min(ans, m2 - x)

        out.append(str(ans))

    else:
        x, c = int(q[1]), int(q[2])
        ft_left.update(x, c - x)
        j = N - x + 1
        ft_right.update(j, c + x)

print(*out, sep="\n")

0