結果
| 問題 | No.1952 xooooooooooor |
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 20:18:44 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 65 ms / 2,000 ms |
| コード長 | 977 bytes |
| 記録 | |
| コンパイル時間 | 248 ms |
| コンパイル使用メモリ | 96,356 KB |
| 実行使用メモリ | 78,976 KB |
| 最終ジャッジ日時 | 2026-07-07 08:45:57 |
| 合計ジャッジ時間 | 4,875 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 39 |
ソースコード
MOD = 998244353
N, M = map(int, input().split())
if N == 0:
print(0)
exit()
# Collect all set bits in N (0-indexed positions)
bits = []
for i in range(60):
if N & (1 << i):
bits.append(i)
if not bits:
print(0)
exit()
events = []
for i in bits:
s = i
e = i + M - 1
events.append((s, 1))
events.append((e + 1, -1))
# Sort events by position, and for the same position, -1 comes before +1
events.sort()
result = 0
prev_pos = 0
current_count = 0
for (pos, delta) in events:
if prev_pos < pos:
if current_count % 2 == 1:
# Calculate 2^prev_pos + 2^(prev_pos+1) + ... + 2^(pos-1)
a = pow(2, pos, MOD)
b = pow(2, prev_pos, MOD)
contribution = (a - b) % MOD
result = (result + contribution) % MOD
# Update current_count
current_count += delta
# Keep it modulo 2 to prevent large numbers
current_count %= 2
prev_pos = pos
print(result % MOD)
lam6er