結果

問題 No.2395 区間二次変換一点取得
ユーザー flygonflygon
提出日時 2023-07-28 21:56:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 396 ms / 2,000 ms
コード長 1,732 bytes
コンパイル時間 395 ms
コンパイル使用メモリ 82,312 KB
実行使用メモリ 97,808 KB
最終ジャッジ日時 2024-04-16 05:50:10
合計ジャッジ時間 5,475 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
54,824 KB
testcase_01 AC 46 ms
55,368 KB
testcase_02 AC 46 ms
54,520 KB
testcase_03 AC 46 ms
54,860 KB
testcase_04 AC 48 ms
56,616 KB
testcase_05 AC 47 ms
55,828 KB
testcase_06 AC 48 ms
56,052 KB
testcase_07 AC 49 ms
56,604 KB
testcase_08 AC 50 ms
55,764 KB
testcase_09 AC 49 ms
55,792 KB
testcase_10 AC 49 ms
57,136 KB
testcase_11 AC 94 ms
76,700 KB
testcase_12 AC 157 ms
79,740 KB
testcase_13 AC 396 ms
97,084 KB
testcase_14 AC 395 ms
97,096 KB
testcase_15 AC 388 ms
97,240 KB
testcase_16 AC 386 ms
97,756 KB
testcase_17 AC 396 ms
97,808 KB
testcase_18 AC 244 ms
97,652 KB
testcase_19 AC 244 ms
97,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(5*10**5)
input = sys.stdin.readline
from collections import defaultdict, deque, Counter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
from math import gcd
def add(x, y):
    return x + y


def e(a):
    if a == min:
        return 10**18
    if a == max:
        return -10**18
    if a == add:
        return 0


class SegTree:
    def __init__(self, segf, init_val):
        n = len(init_val)
        self.segf = segf
        self.e = e(segf)
        self.seg_len = 1 << n.bit_length()
        self.seg = [self.e] * 2*self.seg_len

        for i in range(n):
            self.seg[i + self.seg_len] = init_val[i]
        for i in range(self.seg_len)[::-1]:
            self.seg[i] = segf(self.seg[i << 1], self.seg[i << 1 | 1])

    def range_add(self, l, r, x):
        l += self.seg_len
        r += self.seg_len
        while l < r:
            if l & 1:
                self.seg[l] = self.segf(x, self.seg[l])
                l += 1
            if r & 1:
                r -= 1
                self.seg[r] = self.segf(x, self.seg[r])
            l >>= 1
            r >>= 1

    def get_point(self, pos):
        pos += self.seg_len
        res = self.seg[pos]
        while True:
            pos >>= 1
            if not pos:
                break
            res = self.segf(res, self.seg[pos])
        return res

n,b,q = map(int,input().split())
x,y,z = 1,1,1
ans = [(x,y,z)]
for i in range(q+10):
    x += 1
    y = 3*y+2*x*z
    z *= 3
    x %= b
    y %= b
    z %= b
    ans.append((x,y,z))
st = SegTree(add,[0]*(n+10))
for i in range(q):
    l,m,r = map(int,input().split())
    st.range_add(l,r+1,1)
    tmp = st.get_point(m)

    print(*ans[tmp])

0