結果
問題 | No.1549 [Cherry 2nd Tune] BANning Tuple |
ユーザー | convexineq |
提出日時 | 2021-06-11 22:24:04 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,559 bytes |
コンパイル時間 | 274 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 110,892 KB |
最終ジャッジ日時 | 2024-12-15 00:32:08 |
合計ジャッジ時間 | 16,465 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 143 ms
77,472 KB |
testcase_01 | AC | 123 ms
77,480 KB |
testcase_02 | AC | 2,194 ms
110,892 KB |
testcase_03 | AC | 1,393 ms
97,948 KB |
testcase_04 | AC | 1,340 ms
96,432 KB |
testcase_05 | AC | 1,436 ms
99,496 KB |
testcase_06 | AC | 1,471 ms
98,632 KB |
testcase_07 | AC | 393 ms
82,232 KB |
testcase_08 | AC | 404 ms
82,256 KB |
testcase_09 | AC | 402 ms
81,956 KB |
testcase_10 | AC | 398 ms
81,940 KB |
testcase_11 | WA | - |
testcase_12 | AC | 412 ms
81,796 KB |
testcase_13 | AC | 412 ms
82,244 KB |
testcase_14 | AC | 406 ms
82,192 KB |
testcase_15 | WA | - |
testcase_16 | AC | 391 ms
82,184 KB |
testcase_17 | AC | 324 ms
80,920 KB |
testcase_18 | AC | 326 ms
80,672 KB |
testcase_19 | AC | 2,184 ms
110,404 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)) d = {} for _ in range(Q): k,a,b,s,t = map(int,input().split()) if k not in d: delta = 0 lst = [1]*M for i in range(1,M)[::-1]: p[i] -= p[i-1] p[i] %= MOD else: delta,lst = d[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 p = ([0]*ndelta + polymul(p,lst[delta:]))[:M] ans = p[t] - (p[s-1] if s else 0) print(ans%MOD) d[k] = (delta+ndelta,lst)