結果

問題 No.1742 Binary Indexed Train
ユーザー Shirotsume
提出日時 2021-11-09 23:18:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 751 ms / 3,000 ms
コード長 343 bytes
コンパイル時間 141 ms
コンパイル使用メモリ 82,248 KB
実行使用メモリ 77,332 KB
最終ジャッジ日時 2024-11-25 11:24:37
合計ジャッジ時間 15,456 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(s, t, n):
    mid = 0
    for i in range(n + 1):
        if (s - 1) // (1 << i) != (t - 1) // (1 << i):
            mid = (1 << i) * (t // (1 << i))
    return str(bin(mid - s)).count('1') + str(bin(t - mid)).count('1')


n, q=map(int,input().split())

for _ in range(q):
    s, t = map(int,input().split())
    print(solve(s, t, n))
0