結果

問題 No.1758 Lazy Segment Tree...?
ユーザー NyaanNyaanNyaanNyaan
提出日時 2021-10-16 01:39:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 5,072 ms / 8,000 ms
コード長 952 bytes
コンパイル時間 266 ms
コンパイル使用メモリ 87,340 KB
実行使用メモリ 82,364 KB
最終ジャッジ日時 2023-09-01 23:35:38
合計ジャッジ時間 71,362 ms
ジャッジサーバーID
(参考情報)
judge16 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,564 KB
testcase_01 AC 71 ms
71,364 KB
testcase_02 AC 184 ms
78,816 KB
testcase_03 AC 70 ms
71,480 KB
testcase_04 AC 72 ms
71,628 KB
testcase_05 AC 72 ms
71,360 KB
testcase_06 AC 88 ms
76,712 KB
testcase_07 AC 148 ms
77,988 KB
testcase_08 AC 135 ms
77,724 KB
testcase_09 AC 187 ms
78,768 KB
testcase_10 AC 159 ms
77,688 KB
testcase_11 AC 175 ms
78,780 KB
testcase_12 AC 180 ms
78,708 KB
testcase_13 AC 188 ms
78,640 KB
testcase_14 AC 147 ms
78,292 KB
testcase_15 AC 188 ms
79,336 KB
testcase_16 AC 169 ms
77,996 KB
testcase_17 AC 191 ms
78,044 KB
testcase_18 AC 153 ms
77,720 KB
testcase_19 AC 161 ms
78,020 KB
testcase_20 AC 162 ms
77,688 KB
testcase_21 AC 3,784 ms
81,812 KB
testcase_22 AC 2,940 ms
81,388 KB
testcase_23 AC 3,901 ms
81,104 KB
testcase_24 AC 3,446 ms
81,572 KB
testcase_25 AC 2,468 ms
80,120 KB
testcase_26 AC 3,994 ms
81,532 KB
testcase_27 AC 2,936 ms
80,472 KB
testcase_28 AC 4,133 ms
81,504 KB
testcase_29 AC 4,029 ms
81,384 KB
testcase_30 AC 4,449 ms
81,876 KB
testcase_31 AC 3,208 ms
80,948 KB
testcase_32 AC 3,752 ms
81,204 KB
testcase_33 AC 3,639 ms
81,772 KB
testcase_34 AC 3,246 ms
80,544 KB
testcase_35 AC 2,523 ms
80,240 KB
testcase_36 AC 5,072 ms
82,364 KB
testcase_37 AC 4,774 ms
82,104 KB
testcase_38 AC 4,296 ms
81,584 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)%mod
  a[0][0]+=y
  a[0][0]+=n*(n+1)//2%mod
  a[1][1]+=y
  a[1][1]+=n*(n+1)//2%mod
  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