結果

問題 No.1742 Binary Indexed Train
コンテスト
ユーザー lam6er
提出日時 2025-04-09 21:06:10
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 150 ms / 3,000 ms
コード長 604 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 238 ms
コンパイル使用メモリ 95,476 KB
実行使用メモリ 121,856 KB
最終ジャッジ日時 2026-07-08 15:09:31
合計ジャッジ時間 8,427 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys

def main():
    input = sys.stdin.read
    data = input().split()
    idx = 0
    N = int(data[idx])
    Q = int(data[idx + 1])
    idx += 2
    for _ in range(Q):
        S = int(data[idx])
        T = int(data[idx + 1])
        idx += 2
        ans = 0
        while S < T:
            if S == 0:
                lsb_s = (T & -T)
            else:
                lsb_s = (S & -S)
            lsb_t = (T & -T)
            if lsb_s < lsb_t:
                S += lsb_s
            else:
                T -= lsb_t
            ans += 1
        print(ans)

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