結果
| 問題 |
No.1742 Binary Indexed Train
|
| コンテスト | |
| ユーザー |
gr1msl3y
|
| 提出日時 | 2021-11-12 22:37:34 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 602 bytes |
| コンパイル時間 | 277 ms |
| コンパイル使用メモリ | 82,436 KB |
| 実行使用メモリ | 92,036 KB |
| 最終ジャッジ日時 | 2024-11-25 20:10:16 |
| 合計ジャッジ時間 | 8,652 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 10 WA * 22 |
ソースコード
N, Q = map(int, input().split())
query = [list(map(int, input().split())) for _ in range(Q)]
ans = [0]*Q
for i in range(Q):
s, t = query[i]
if s == 0:
ans[i] = str(bin(t)).count('1')
continue
ct = 0
ind = t.bit_length()-1
while (s >> ind) & 1 and (t >> ind) & 1:
ind -= 1
if s == 0:
ans[i] = str(bin(t)).count('1')
continue
for j in range(ind):
if (s >> j) & 1:
ct += 1
s += 1 << j
for j in range(ind-1, -1, -1):
if (t >> j) & 1:
ct += 1
ans[i] = ct
print(*ans, sep='\n')
gr1msl3y