結果

問題 No.1742 Binary Indexed Train
ユーザー tamato
提出日時 2021-11-12 22:30:34
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 476 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 82,756 KB
実行使用メモリ 77,060 KB
最終ジャッジ日時 2024-11-25 19:46:48
合計ジャッジ時間 7,770 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17 WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.buffer.readline

    N, Q = map(int, input().split())
    for _ in range(Q):
        s, t = map(int, input().split())
        if s == 0:
            print(1)
            continue
        ans = 0
        while t != s:
            x = s & (-s)
            y = 1 << ((t-s).bit_length() - 1)
            s += min(x, y)
            ans += 1
        print(ans)


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