結果

問題 No.1891 Static Xor Range Composite Query
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2024-03-12 08:05:07
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 2,116 bytes
コンパイル時間 305 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 332,668 KB
最終ジャッジ日時 2024-03-12 08:05:20
合計ジャッジ時間 11,730 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
63,640 KB
testcase_01 AC 55 ms
63,640 KB
testcase_02 AC 56 ms
63,640 KB
testcase_03 AC 60 ms
63,640 KB
testcase_04 AC 68 ms
63,640 KB
testcase_05 AC 63 ms
63,640 KB
testcase_06 AC 57 ms
63,640 KB
testcase_07 AC 55 ms
63,640 KB
testcase_08 AC 55 ms
63,640 KB
testcase_09 AC 62 ms
63,640 KB
testcase_10 AC 58 ms
63,640 KB
testcase_11 AC 152 ms
79,628 KB
testcase_12 AC 156 ms
79,372 KB
testcase_13 AC 151 ms
79,628 KB
testcase_14 AC 182 ms
79,368 KB
testcase_15 AC 177 ms
79,372 KB
testcase_16 AC 150 ms
79,620 KB
testcase_17 AC 154 ms
79,620 KB
testcase_18 AC 151 ms
79,620 KB
testcase_19 AC 151 ms
79,628 KB
testcase_20 AC 153 ms
79,620 KB
testcase_21 TLE -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import pypyjit
pypyjit.set_param("max_unroll_recursion=-1")
from collections import *
from functools import *
from itertools import *
from heapq import *
import sys, math,random,time
# input = sys.stdin.readline

class XorSegmentTree:
    def __init__(self, A, f, E):
        self.N = len(A)
        self.ST = [[] for _ in range(self.N * 2 - 1)]
        self.f = f
        self.E = E
        for i in range(self.N):
            self.ST[self.N - 1 + i].append(A[i])
        for i in range(self.N - 2, -1, -1):
            cnt = len(self.ST[i * 2 + 1])
            for j in range(cnt):
                self.ST[i].append(f(self.ST[i * 2 + 1][j], self.ST[i * 2 + 2][j]))
            for j in range(cnt):
                self.ST[i].append(f(self.ST[i * 2 + 2][j], self.ST[i * 2 + 1][j]))

    def _range_fold(self, L, R, x, i=0, l=0, r=None):
        if r is None:
            r = self.N
        if r <= L or R <= l:
            return self.E
        elif L <= l and r <= R:
            assert x < len(self.ST[i])
            return self.ST[i][x]
        else:
            p = (r - l) // 2
            m = (l + r) // 2
            if (x & p) == 0:
                resL = self._range_fold(L, R, x, i * 2 + 1, l, m)
                resR = self._range_fold(L, R, x, i * 2 + 2, m, r)
                return self.f(resL, resR)
            else:
                resL = self.E
                if R >= m:
                    resL = self._range_fold(max(L, m) - p, R - p, x ^ p, i * 2 + 1, l, m)
                resR = self.E
                if L < m:
                    resR = self._range_fold(L + p, min(R, m) + p, x ^ p, i * 2 + 2, m, r)
                return self.f(resR, resL)

    def range_fold(self, L, R, x):
        return self._range_fold(L, R, x, 0, 0, self.N)
    
N,Q = map(int,input().split())
mod = 998244353
def segfunc(y,x):
    return (x[0]*y[0]%mod,(x[0]*y[1]+x[1])%mod)
ide_ele = (1,0)
X = []
for _ in range(N):
    X.append(tuple(map(int,input().split())))

T = XorSegmentTree(X,segfunc,ide_ele)
for _ in range(Q):
    l,r,p,x = map(int,input().split())
    a,b = T.range_fold(l,r,p)
    print((a*x+b)%mod)
0