結果

問題 No.1891 Static Xor Range Composite Query
ユーザー googol_S0googol_S0
提出日時 2022-04-04 18:18:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,356 ms / 5,000 ms
コード長 1,491 bytes
コンパイル時間 990 ms
コンパイル使用メモリ 82,456 KB
実行使用メモリ 341,252 KB
最終ジャッジ日時 2024-05-04 03:47:23
合計ジャッジ時間 29,391 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
54,272 KB
testcase_01 AC 37 ms
55,040 KB
testcase_02 AC 38 ms
55,180 KB
testcase_03 AC 40 ms
55,168 KB
testcase_04 AC 40 ms
55,296 KB
testcase_05 AC 40 ms
55,040 KB
testcase_06 AC 40 ms
55,296 KB
testcase_07 AC 38 ms
55,296 KB
testcase_08 AC 38 ms
54,784 KB
testcase_09 AC 41 ms
55,168 KB
testcase_10 AC 40 ms
55,296 KB
testcase_11 AC 137 ms
79,776 KB
testcase_12 AC 135 ms
79,772 KB
testcase_13 AC 133 ms
79,640 KB
testcase_14 AC 141 ms
79,688 KB
testcase_15 AC 136 ms
79,624 KB
testcase_16 AC 135 ms
79,820 KB
testcase_17 AC 135 ms
79,940 KB
testcase_18 AC 138 ms
79,916 KB
testcase_19 AC 134 ms
79,980 KB
testcase_20 AC 134 ms
79,784 KB
testcase_21 AC 2,334 ms
341,252 KB
testcase_22 AC 2,320 ms
341,120 KB
testcase_23 AC 2,314 ms
341,252 KB
testcase_24 AC 2,258 ms
340,992 KB
testcase_25 AC 2,349 ms
340,972 KB
testcase_26 AC 2,356 ms
340,988 KB
testcase_27 AC 2,340 ms
341,120 KB
testcase_28 AC 2,323 ms
340,964 KB
testcase_29 AC 2,348 ms
340,984 KB
testcase_30 AC 2,313 ms
341,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod=998244353
def f(x,y):
  if len(x)==0:
    return y
  if len(y)==0:
    return x
  n=len(x)
  r=[(0,0) for i in range(n*2)]
  for i in range(n):
    r[i]=((x[i][0]*y[i][1]+y[i][0])%mod,x[i][1]*y[i][1]%mod)
    r[i+n]=((y[i][0]*x[i][1]+x[i][0])%mod,y[i][1]*x[i][1]%mod)
  return r

from copy import *
def init(N,node,A,unit,func):
  n=1
  while n<N:
    n<<=1
  for i in range(n*2-1):
    if len(node)<=i:
      node.append(deepcopy(unit))
    else:
      node[i]=deepcopy(unit)
  for i in range(len(A)):
    node[n-1+i]=deepcopy(A[i])
  for i in range(n-2,-1,-1):
    node[i]=func(node[(i<<1)+1],node[(i<<1)+2])
  node.append(func)
  node.append(unit)
  node.append(n)

def upd(node,x,a):
  y=node[-1]+x
  node[y-1]=a
  while y>1:
    y=y>>1
    node[y-1]=node[-3](node[(y<<1)-1],node[y<<1])

def g(x,y):
  return ((x[0]*y[1]+y[0])%mod,(x[1]*y[1])%mod)

def query(node,l,r,p):
  x,y=l,r
  z=node[-1]-1
  rr=(0,1)
  rl=(0,1)
  q=p
  while True:
    if x==y:
      return g(rl,rr)
    if x&1:
      rl=g(rl,node[(x^q)+z][p&(len(node[x+z])-1)])
      x+=1
    if y&1:
      rr=g(node[((y-1)^q)+z][p&(len(node[y+z-1])-1)],rr)
    if z==0:
      return g(rl,rr)
    x>>=1
    y>>=1
    z>>=1
    q>>=1

import sys
input=sys.stdin.buffer.readline
N,Q=map(int,input().split())
A=[]
for i in range(N):
  a,b=map(int,input().split())
  A.append([(b,a)])
seg=[]
init(N,seg,A,[],lambda x,y:f(x,y))
for i in range(Q):
  l,r,p,x=map(int,input().split())
  v=query(seg,l,r,p)
  print((v[1]*x+v[0])%mod)
0