結果
問題 | No.1549 [Cherry 2nd Tune] BANning Tuple |
ユーザー | convexineq |
提出日時 | 2021-06-11 22:33:07 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,178 ms / 4,000 ms |
コード長 | 2,627 bytes |
コンパイル時間 | 187 ms |
コンパイル使用メモリ | 82,364 KB |
実行使用メモリ | 111,048 KB |
最終ジャッジ日時 | 2024-05-08 18:30:28 |
合計ジャッジ時間 | 16,244 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 138 ms
77,516 KB |
testcase_01 | AC | 118 ms
77,516 KB |
testcase_02 | AC | 2,178 ms
111,048 KB |
testcase_03 | AC | 1,377 ms
98,060 KB |
testcase_04 | AC | 1,333 ms
96,468 KB |
testcase_05 | AC | 1,413 ms
99,912 KB |
testcase_06 | AC | 1,451 ms
98,848 KB |
testcase_07 | AC | 383 ms
82,248 KB |
testcase_08 | AC | 394 ms
81,868 KB |
testcase_09 | AC | 393 ms
81,876 KB |
testcase_10 | AC | 383 ms
81,876 KB |
testcase_11 | AC | 417 ms
82,260 KB |
testcase_12 | AC | 391 ms
81,976 KB |
testcase_13 | AC | 392 ms
82,244 KB |
testcase_14 | AC | 381 ms
82,240 KB |
testcase_15 | AC | 409 ms
82,852 KB |
testcase_16 | AC | 385 ms
82,632 KB |
testcase_17 | AC | 354 ms
81,340 KB |
testcase_18 | AC | 355 ms
81,608 KB |
testcase_19 | AC | 2,164 ms
110,700 KB |
ソースコード
ROOT = 3 MOD = 998244353 roots = [pow(ROOT,(MOD-1)>>i,MOD) for i in range(24)] # 1 の 2^i 乗根 iroots = [pow(x,MOD-2,MOD) for x in roots] # 1 の 2^i 乗根の逆元 def untt(a,n): for i in range(n): m = 1<<(n-i-1) for s in range(1<<i): w_N = 1 s *= m*2 for p in range(m): a[s+p], a[s+p+m] = (a[s+p]+a[s+p+m])%MOD, (a[s+p]-a[s+p+m])*w_N%MOD w_N = w_N*roots[n-i]%MOD def iuntt(a,n): for i in range(n): m = 1<<i for s in range(1<<(n-i-1)): w_N = 1 s *= m*2 for p in range(m): a[s+p], a[s+p+m] = (a[s+p]+a[s+p+m]*w_N)%MOD, (a[s+p]-a[s+p+m]*w_N)%MOD w_N = w_N*iroots[i+1]%MOD inv = pow((MOD+1)//2,n,MOD) for i in range(1<<n): a[i] = a[i]*inv%MOD def convolution(a,b): la = len(a) lb = len(b) if min(la, lb) <= 50: if la < lb: la,lb = lb,la a,b = b,a res = [0]*(la+lb-1) for i in range(la): for j in range(lb): res[i+j] += a[i]*b[j] res[i+j] %= MOD return res deg = la+lb-2 n = deg.bit_length() N = 1<<n a += [0]*(N-len(a)) b += [0]*(N-len(b)) untt(a,n) untt(b,n) for i in range(N): a[i] = a[i]*b[i]%MOD iuntt(a,n) return a[:deg+1] def fpsinv(f,N): g = [pow(f[0],MOD-2,MOD)] n = 1 while n <= N: ng = [2*i for i in g]+[0]*n fgg = polymul(polymul(g,g),f) for i in range(min(len(fgg),2*n)): ng[i] -= fgg[i] ng[i] %= MOD n *= 2 g = ng return g[:N+1] def polymul(a,b): return convolution(a[:],b[:]) def inv(x): return pow(x,MOD-2,MOD) n,Q = map(int,input().split()) n %= MOD M = 3001 p = [1] for i in range(M): v = p[-1]*(n+i+1)%MOD p.append(v*inv(i+1)) dlst = {} ddelta = {} for _ in range(Q): k,a,b,s,t = map(int,input().split()) if k not in ddelta: delta = 0 lst = [1]*M for i in range(1,M)[::-1]: p[i] -= p[i-1] p[i] %= MOD else: delta,lst = ddelta[k],dlst[k] if delta != M: p = polymul(p,fpsinv(lst[delta:]+[0]*delta,M))[:M] for i in range(a,b+1): lst[i] = 0 ndelta = 0 for i in range(delta,M): if lst[i] == 0: ndelta += 1 else: break delta += ndelta p = ([0]*ndelta + polymul(p,lst[delta:]))[:M] ans = p[t] - (p[s-1] if s else 0) print(ans%MOD) ddelta[k] = delta dlst[k] = lst