結果

問題 No.2395 区間二次変換一点取得
ユーザー sotanishysotanishy
提出日時 2023-07-28 21:41:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 304 ms / 2,000 ms
コード長 793 bytes
コンパイル時間 305 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 94,080 KB
最終ジャッジ日時 2024-04-16 05:32:32
合計ジャッジ時間 5,189 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
51,840 KB
testcase_01 AC 41 ms
52,480 KB
testcase_02 AC 41 ms
52,352 KB
testcase_03 AC 42 ms
52,224 KB
testcase_04 AC 42 ms
52,608 KB
testcase_05 AC 42 ms
52,224 KB
testcase_06 AC 42 ms
52,352 KB
testcase_07 AC 43 ms
52,224 KB
testcase_08 AC 44 ms
52,352 KB
testcase_09 AC 44 ms
52,736 KB
testcase_10 AC 45 ms
52,480 KB
testcase_11 AC 81 ms
70,784 KB
testcase_12 AC 112 ms
78,336 KB
testcase_13 AC 298 ms
93,568 KB
testcase_14 AC 302 ms
94,080 KB
testcase_15 AC 298 ms
93,568 KB
testcase_16 AC 304 ms
93,696 KB
testcase_17 AC 299 ms
93,952 KB
testcase_18 AC 240 ms
93,696 KB
testcase_19 AC 241 ms
93,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline


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

    # i is exclusive
    def prefix_sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s

    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.data[i] += x
            i += i & -i


N, B, Q = map(int, input().split())
ft = FenwickTree(N+1)
x = y = z = 1
val = [(1, 1, 1)]
for _ in range(Q):
    x += 1
    y = 3*y+2*x*z
    z = 3*z
    x %= B
    y %= B
    z %= B
    val.append((x, y, z))
for _ in range(Q):
    L, M, R = map(int, input().split())
    L -= 1
    ft.add(L, 1)
    ft.add(R, -1)
    x = ft.prefix_sum(M)
    print(*val[x])
0