結果

問題 No.2395 区間二次変換一点取得
ユーザー ecotteaecottea
提出日時 2023-07-22 01:32:56
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,174 bytes
コンパイル時間 170 ms
コンパイル使用メモリ 81,756 KB
実行使用メモリ 848,124 KB
最終ジャッジ日時 2023-10-22 01:16:30
合計ジャッジ時間 4,455 ms
ジャッジサーバーID
(参考情報)
judge9 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,256 KB
testcase_01 AC 39 ms
53,256 KB
testcase_02 AC 39 ms
53,256 KB
testcase_03 AC 39 ms
53,256 KB
testcase_04 AC 39 ms
53,256 KB
testcase_05 AC 40 ms
53,256 KB
testcase_06 AC 40 ms
53,256 KB
testcase_07 AC 41 ms
53,256 KB
testcase_08 AC 42 ms
53,256 KB
testcase_09 AC 42 ms
53,256 KB
testcase_10 AC 44 ms
53,256 KB
testcase_11 AC 86 ms
73,416 KB
testcase_12 AC 241 ms
97,832 KB
testcase_13 MLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

# Python3 でも 1,422 ms / 2,000 ms で AC

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], Y[i], Z[i] が j 回操作された後の値(i によらない)
x = [0] * (Q + 1)
y = [0] * (Q + 1)
z = [0] * (Q + 1)
x[0] = 1
y[0] = 1
z[0] = 1
for j in range(Q):
    x[j + 1] = (x[j] + 1)
    y[j + 1] = (3 * y[j] + 2 * x[j + 1] * z[j])
    z[j + 1] = (3 * z[j])

# 操作された回数だけを覚えておくためのフェニック木
ft = FenwickTree(N + 1)

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

    # 区間加算 & 1点参照は,1点加算 & 1点減算 & 左からの区間総和 で代用できる.
    ft.add(l, 1)
    ft.add(r, -1)
    j = ft.sum(m)

    print(x[j] % B, y[j] % B, z[j] % B)
0