結果

問題 No.1742 Binary Indexed Train
ユーザー LyricalMaestro
提出日時 2025-01-27 00:38:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 270 ms / 3,000 ms
コード長 612 bytes
コンパイル時間 1,170 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 82,688 KB
最終ジャッジ日時 2025-01-27 00:39:05
合計ジャッジ時間 9,164 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

## https://yukicoder.me/problems/no/1742


def main():
    N, Q = map(int, input().split())
    st = []
    for _ in range(Q):
        s, t = map(int, input().split())
        st.append((s, t))

    for s, t in st:
        c = 0
        for _ in range(N + 1):
            if s & 1 > 0:
                s += 1
                c += 1
            s = s // 2
            
            if t & 1 > 0:
                t -= 1
                c += 1
            t = t // 2
            if s == t:
                break
        print(c)
            

            







            



if __name__ == "__main__":
    main()
0