結果

問題 No.1758 Lazy Segment Tree...?
ユーザー 👑 PCTprobabilityPCTprobability
提出日時 2021-10-16 01:31:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 6,299 ms / 8,000 ms
コード長 942 bytes
コンパイル時間 496 ms
コンパイル使用メモリ 87,008 KB
実行使用メモリ 83,384 KB
最終ジャッジ日時 2023-09-01 23:31:37
合計ジャッジ時間 88,517 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,132 KB
testcase_01 AC 74 ms
71,128 KB
testcase_02 AC 189 ms
78,832 KB
testcase_03 AC 71 ms
71,216 KB
testcase_04 AC 74 ms
71,396 KB
testcase_05 AC 72 ms
71,132 KB
testcase_06 AC 90 ms
76,504 KB
testcase_07 AC 153 ms
77,932 KB
testcase_08 AC 141 ms
77,540 KB
testcase_09 AC 188 ms
78,492 KB
testcase_10 AC 162 ms
77,588 KB
testcase_11 AC 178 ms
78,452 KB
testcase_12 AC 185 ms
78,436 KB
testcase_13 AC 196 ms
78,520 KB
testcase_14 AC 150 ms
77,916 KB
testcase_15 AC 190 ms
79,244 KB
testcase_16 AC 178 ms
77,784 KB
testcase_17 AC 198 ms
77,832 KB
testcase_18 AC 156 ms
77,528 KB
testcase_19 AC 164 ms
77,672 KB
testcase_20 AC 170 ms
77,624 KB
testcase_21 AC 4,625 ms
82,492 KB
testcase_22 AC 3,645 ms
81,068 KB
testcase_23 AC 4,833 ms
82,432 KB
testcase_24 AC 4,228 ms
82,100 KB
testcase_25 AC 3,137 ms
80,260 KB
testcase_26 AC 5,032 ms
81,708 KB
testcase_27 AC 3,727 ms
82,064 KB
testcase_28 AC 4,982 ms
82,172 KB
testcase_29 AC 4,831 ms
82,612 KB
testcase_30 AC 5,520 ms
83,384 KB
testcase_31 AC 3,900 ms
81,480 KB
testcase_32 AC 4,562 ms
82,264 KB
testcase_33 AC 4,466 ms
82,284 KB
testcase_34 AC 4,002 ms
83,108 KB
testcase_35 AC 3,074 ms
81,408 KB
testcase_36 AC 6,299 ms
83,164 KB
testcase_37 AC 5,892 ms
83,228 KB
testcase_38 AC 5,237 ms
82,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod=998244353
def modpow(a,b,m):
  res=1
  while b:
    if b%2:
      res*=a
      res%=m
    a*=a
    a%=m
    b//=2
  return res
def prodmat(a,b):
  x,y,z=len(a),len(b[0]),len(b)
  c=[[0 for i in range(y)] for j in range(x)]
  for i in range(x):
    for j in range(y):
      for k in range(z):
        c[i][k]+=a[i][j]*b[j][k]
        c[i][k]%=mod
  return c
def powermat(a,k):
  x=len(a)
  b=[[0 for i in range(x)] for j in range(x)]
  for i in range(x):
    b[i][i]=1
  while k:
    if k%2:
      b=prodmat(b,a)
    a=prodmat(a,a)
    k//=2
  return b
n,q=map(int,input().split())
ans=0
for i in range(1,n):
  x=i*(n-i+1)
  y=n*(n+1)//2-x
  z=(n-i)*(n-i+1)*(n-i+2)//6
  x%=mod
  y%=mod
  z%=mod
  a=[[0 for i in range(3)] for j in range(3)]
  a[1][2]+=z;
  a[2][2]+=n*(n+1)
  a[0][0]+=y
  a[0][0]+=n*(n+1)//2
  a[1][1]+=y;
  a[1][1]+=n*(n+1)//2
  a[1][0]+=x
  a[0][1]+=x
  a=powermat(a,q)
  ans+=a[0][2]
print(ans*modpow(2,mod-2,mod)%mod)
0