結果

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

ソースコード

diff #

def solve(s, t, n):
    s += 1 << n
    t += 1 << n
    ans = 0
    while s < t:
        if s & 1:
            ans += 1
            s += 1
        if t & 1:
            t -= 1
            ans += 1
        s >>= 1
        t >>= 1

    return ans

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

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