結果

問題 No.2395 区間二次変換一点取得
ユーザー ecotteaecottea
提出日時 2023-07-21 23:45:33
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 1,623 ms / 2,000 ms
コード長 1,051 bytes
コンパイル時間 142 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 23,552 KB
最終ジャッジ日時 2024-09-22 01:12:20
合計ジャッジ時間 14,348 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

class FenwickTree:
    def __init__(self, n):
        self.n = n
        self.v = [0] * (n + 1)

    # 区間 [0..r) の和を返す
    def sum(self, r):
        res = 0
        while r > 0:
            res += self.v[r]
            r -= r & -r
        return res

    # 位置 i に x を加算する
    def add(self, i, x):
        i += 1
        while i <= self.n:
            self.v[i] += x
            i += i & -i

N, B, Q = map(int, input().split())

# x[j], y[j], z[j] : X[i] が j 回操作された後の値(i によらない)
x = [0] * (Q + 1)
y = [0] * (Q + 1)
z = [0] * (Q + 1)
x[0] = 1 % B
y[0] = 1 % B
z[0] = 1 % B
for j in range(Q):
    x[j + 1] = (x[j] + 1) % B
    y[j + 1] = (3 * y[j] + 2 * x[j + 1] * z[j]) % B
    z[j + 1] = (3 * z[j]) % B

# 区間加算 & 1点参照は,1点加算 & 1点減算 & 左からの区間総和 で代用できる.
ft = FenwickTree(N + 1)

for _ in range(Q):
    l, m, r = map(int, input().split())
    l -= 1

    ft.add(l, 1)
    ft.add(r, -1)
    j = ft.sum(m)

    print(x[j], y[j], z[j])

0