結果
問題 | No.1549 [Cherry 2nd Tune] BANning Tuple |
ユーザー | convexineq |
提出日時 | 2021-06-11 22:24:04 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,559 bytes |
コンパイル時間 | 336 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 111,004 KB |
最終ジャッジ日時 | 2024-05-08 18:18:35 |
合計ジャッジ時間 | 15,929 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 139 ms
77,472 KB |
testcase_01 | AC | 120 ms
77,520 KB |
testcase_02 | AC | 2,179 ms
111,004 KB |
testcase_03 | AC | 1,386 ms
97,700 KB |
testcase_04 | AC | 1,339 ms
96,844 KB |
testcase_05 | AC | 1,429 ms
99,676 KB |
testcase_06 | AC | 1,464 ms
99,032 KB |
testcase_07 | AC | 387 ms
82,244 KB |
testcase_08 | AC | 398 ms
82,256 KB |
testcase_09 | AC | 398 ms
82,256 KB |
testcase_10 | AC | 386 ms
82,080 KB |
testcase_11 | WA | - |
testcase_12 | AC | 394 ms
82,248 KB |
testcase_13 | AC | 398 ms
82,376 KB |
testcase_14 | AC | 387 ms
82,244 KB |
testcase_15 | WA | - |
testcase_16 | AC | 387 ms
82,244 KB |
testcase_17 | AC | 322 ms
80,952 KB |
testcase_18 | AC | 323 ms
80,852 KB |
testcase_19 | AC | 2,168 ms
110,408 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)