結果
問題 | No.2952 Invision of Multiples |
ユーザー | とりゐ |
提出日時 | 2024-09-12 23:58:33 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,091 ms / 4,000 ms |
コード長 | 2,128 bytes |
コンパイル時間 | 474 ms |
コンパイル使用メモリ | 82,064 KB |
実行使用メモリ | 161,996 KB |
最終ジャッジ日時 | 2024-09-13 16:13:15 |
合計ジャッジ時間 | 41,472 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
53,352 KB |
testcase_01 | AC | 37 ms
53,408 KB |
testcase_02 | AC | 220 ms
152,132 KB |
testcase_03 | AC | 114 ms
78,340 KB |
testcase_04 | AC | 119 ms
78,288 KB |
testcase_05 | AC | 110 ms
78,172 KB |
testcase_06 | AC | 110 ms
78,452 KB |
testcase_07 | AC | 85 ms
78,136 KB |
testcase_08 | AC | 86 ms
78,480 KB |
testcase_09 | AC | 972 ms
126,672 KB |
testcase_10 | AC | 1,076 ms
122,188 KB |
testcase_11 | AC | 353 ms
158,332 KB |
testcase_12 | AC | 341 ms
160,280 KB |
testcase_13 | AC | 351 ms
122,108 KB |
testcase_14 | AC | 440 ms
157,660 KB |
testcase_15 | AC | 1,480 ms
161,352 KB |
testcase_16 | AC | 1,337 ms
161,440 KB |
testcase_17 | AC | 1,835 ms
161,700 KB |
testcase_18 | AC | 1,838 ms
161,680 KB |
testcase_19 | AC | 464 ms
161,456 KB |
testcase_20 | AC | 452 ms
161,608 KB |
testcase_21 | AC | 1,864 ms
161,892 KB |
testcase_22 | AC | 1,819 ms
161,236 KB |
testcase_23 | AC | 2,086 ms
161,720 KB |
testcase_24 | AC | 1,437 ms
161,536 KB |
testcase_25 | AC | 1,464 ms
161,904 KB |
testcase_26 | AC | 1,559 ms
161,568 KB |
testcase_27 | AC | 2,036 ms
161,996 KB |
testcase_28 | AC | 1,887 ms
161,260 KB |
testcase_29 | AC | 2,036 ms
161,844 KB |
testcase_30 | AC | 2,091 ms
161,500 KB |
testcase_31 | AC | 2,049 ms
161,672 KB |
testcase_32 | AC | 2,075 ms
161,300 KB |
testcase_33 | AC | 381 ms
161,544 KB |
testcase_34 | AC | 367 ms
161,504 KB |
testcase_35 | AC | 382 ms
161,700 KB |
testcase_36 | AC | 558 ms
161,332 KB |
testcase_37 | AC | 519 ms
161,236 KB |
testcase_38 | AC | 522 ms
161,396 KB |
testcase_39 | AC | 543 ms
161,600 KB |
testcase_40 | AC | 538 ms
161,616 KB |
testcase_41 | AC | 535 ms
161,872 KB |
testcase_42 | AC | 537 ms
161,956 KB |
testcase_43 | AC | 564 ms
161,516 KB |
ソースコード
mod = 998244353 class fenwick_tree: def __init__(self, n, init=None): self.n = n self.tree = [0] * (n + 1) if init: for i in range(n): self.add(i, init[i]) def add(self, k, x): while k < self.n: self.tree[k] = (self.tree[k] + x) % mod k |= k + 1 def prefix_sum(self, i): s = 0 i -= 1 while i >= 0: s += self.tree[i] i = (i & (i + 1)) - 1 return s % mod def floor_sum(n, m, a, b): # sum [i = 0, ..., n-1] floor((ai+b)/m) ans = 0 while True: ans += (n - 1) * n * (a // m) // 2 a %= m ans += n * (b // m) b %= m y = (a * n + b) // m x = y * m - b if y == 0: return ans ans += (n - (x + a - 1) // a) * y n, m, a, b = y, a, m, (-x) % a N, M = map(int, input().split()) D = list(map(int, input().split())) I = [0] + [pow(M // i, mod - 2, mod) for i in range(1, M + 1)] All = 1 for i in range(N): All *= M // D[i] All %= mod B = 100 cnt1 = [[0] * (B + 1) for i in range(M + 1)] cnt2 = [[0] * (M + 1) for i in range(B + 1)] c = [0] * (B + 1) for i in range(N): for j in range(1, B + 1): cnt1[D[i]][j] += c[j] if D[i] <= B: c[D[i]] += 1 ans = 0 c = [0] * (B + 1) ft = fenwick_tree(M + 1) for i in range(N - 1, -1, -1): if D[i] > B: for j in range(1, B + 1): cnt2[j][D[i]] += c[j] for j in range(D[i], M + 1, D[i]): ans += ft.prefix_sum(j) * I[D[i]] ans %= mod for j in range(D[i], M + 1, D[i]): ft.add(j, I[D[i]]) else: c[D[i]] += 1 for i in range(1, M + 1): for j in range(1, B + 1): if cnt1[i][j] != 0: ans += cnt1[i][j] * floor_sum(M // j, i, j, j - 1) % mod * I[i] % mod * I[j] ans %= mod for i in range(1, B + 1): for j in range(1, M + 1): if cnt2[i][j] != 0: ans += cnt2[i][j] * floor_sum(M // j, i, j, j - 1) % mod * I[i] % mod * I[j] ans %= mod ans *= All print(ans % mod)