結果
| 問題 |
No.1952 xooooooooooor
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 20:18:44 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 40 ms / 2,000 ms |
| コード長 | 977 bytes |
| コンパイル時間 | 169 ms |
| コンパイル使用メモリ | 82,768 KB |
| 実行使用メモリ | 54,028 KB |
| 最終ジャッジ日時 | 2025-03-20 20:19:42 |
| 合計ジャッジ時間 | 2,927 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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