結果
問題 |
No.1742 Binary Indexed Train
|
ユーザー |
![]() |
提出日時 | 2021-11-12 22:39:43 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 646 bytes |
コンパイル時間 | 273 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 91,904 KB |
最終ジャッジ日時 | 2024-11-25 20:14:10 |
合計ジャッジ時間 | 8,543 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 WA * 20 |
ソースコード
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: s -= 1 << ind t -= 1 << ind 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')