結果

問題 No.1742 Binary Indexed Train
ユーザー puzneko
提出日時 2021-11-25 00:22:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 192 ms / 3,000 ms
コード長 643 bytes
コンパイル時間 262 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 123,044 KB
最終ジャッジ日時 2024-06-27 10:02:42
合計ジャッジ時間 7,182 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin
n, q, *indata = map(int, stdin.read().split())
offset = 0
for i in range(q):
    s, t = indata[offset + 2*i],indata[offset + 2*i+1]
    ans = 0
    if s == 0:
        check = True
        while t > 0:
            kari = t & (-t)
            t -= kari
            ans += 1
    else:
        check = True
        while check:
            kari = s & (-s)
            if s + kari <= t:
                s += kari
                ans += 1
            else:
                check = False
        check = True
        while t > s:
            kari = t & (-t)
            t -= kari
            ans += 1
    print("{}".format(ans))
0