結果

問題 No.2395 区間二次変換一点取得
ユーザー ecotteaecottea
提出日時 2023-07-21 23:53:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 592 ms / 2,000 ms
コード長 1,366 bytes
コンパイル時間 888 ms
コンパイル使用メモリ 81,540 KB
実行使用メモリ 83,112 KB
最終ジャッジ日時 2023-10-21 23:51:24
合計ジャッジ時間 7,606 ms
ジャッジサーバーID
(参考情報)
judge15 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
63,404 KB
testcase_01 AC 54 ms
63,404 KB
testcase_02 AC 54 ms
63,404 KB
testcase_03 AC 55 ms
63,404 KB
testcase_04 AC 55 ms
63,404 KB
testcase_05 AC 54 ms
63,404 KB
testcase_06 AC 54 ms
63,404 KB
testcase_07 AC 55 ms
63,404 KB
testcase_08 AC 56 ms
63,404 KB
testcase_09 AC 57 ms
63,404 KB
testcase_10 AC 59 ms
65,452 KB
testcase_11 AC 116 ms
77,116 KB
testcase_12 AC 180 ms
79,464 KB
testcase_13 AC 592 ms
82,664 KB
testcase_14 AC 556 ms
82,652 KB
testcase_15 AC 556 ms
82,664 KB
testcase_16 AC 562 ms
82,652 KB
testcase_17 AC 561 ms
82,652 KB
testcase_18 AC 541 ms
83,112 KB
testcase_19 AC 539 ms
83,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import re
import sys

sys.setrecursionlimit(100000)

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

    def sum(self, r):
        res = 0
        while r > 0:
            res += self.v[r]
            r -= r & -r
        return res

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

content = input()
pattern = r'^(\d+) (\d+) (\d+)$'
result = re.match(pattern, content)

if not result:
    sys.exit("format error.")

N, B, Q = map(int, result.groups())

if not (1 <= N and N <= 10**5):
    sys.exit("N")
if not (1 <= B and B <= 10**9):
    sys.exit("B")
if not (1 <= Q and Q <= 10**5):
    sys.exit("Q")
    
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

ft = FenwickTree(N + 1)

for _ in range(Q):
    content = input()
    pattern = r'^(\d+) (\d+) (\d+)$'
    result = re.match(pattern, content)

    if not result:
        sys.exit("format error.")

    l, m, r = map(int, result.groups())

    if not (1 <= l and l <= m and m <= r and r <= N):
        sys.exit("l m r")

    l -= 1

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

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