結果
| 問題 |
No.1742 Binary Indexed Train
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-11-12 23:01:24 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 608 bytes |
| コンパイル時間 | 300 ms |
| コンパイル使用メモリ | 81,764 KB |
| 実行使用メモリ | 168,832 KB |
| 最終ジャッジ日時 | 2024-11-25 21:04:42 |
| 合計ジャッジ時間 | 56,778 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 TLE * 1 |
| other | AC * 23 TLE * 9 |
ソースコード
n,q = map(int,input().split())
for i in range(q):
s,t = map(int,input().split())
if s == 0:
print(bin(t).count('1'))
continue
ans = 0
while (s).bit_length() != (t).bit_length():
s += s & -s
ans += 1
if ans != 0:
ans += bin(t).count('1') - 1
else:
ls = bin(s)
lt = bin(t)
for i in range(len(ls)):
if ls[i] != lt[i]:
ind = i
break
p = 1 << (len(ls) - ind - 1)
while s // p != t // p:
s += s & -s
ans += 1
ls = bin(s)
lt = bin(t)
for i in range(ind,len(ls)):
if ls[i] != lt[i]:
ans += 1
print(ans)