結果

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

ソースコード

diff #

def solve(s, t, n):
    s += 2 ** n
    t += 2 ** 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