結果

問題 No.1742 Binary Indexed Train
ユーザー H3PO4H3PO4
提出日時 2021-11-12 22:52:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 283 ms / 3,000 ms
コード長 350 bytes
コンパイル時間 264 ms
コンパイル使用メモリ 82,448 KB
実行使用メモリ 78,868 KB
最終ジャッジ日時 2024-05-04 10:28:31
合計ジャッジ時間 7,583 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
53,560 KB
testcase_01 AC 32 ms
52,408 KB
testcase_02 AC 31 ms
52,152 KB
testcase_03 AC 242 ms
77,204 KB
testcase_04 AC 246 ms
77,716 KB
testcase_05 AC 249 ms
77,420 KB
testcase_06 AC 125 ms
78,392 KB
testcase_07 AC 133 ms
78,868 KB
testcase_08 AC 283 ms
78,500 KB
testcase_09 AC 280 ms
78,136 KB
testcase_10 AC 281 ms
77,800 KB
testcase_11 AC 280 ms
78,232 KB
testcase_12 AC 272 ms
77,684 KB
testcase_13 AC 222 ms
77,260 KB
testcase_14 AC 229 ms
77,448 KB
testcase_15 AC 90 ms
76,608 KB
testcase_16 AC 90 ms
76,496 KB
testcase_17 AC 147 ms
77,644 KB
testcase_18 AC 150 ms
77,424 KB
testcase_19 AC 103 ms
77,692 KB
testcase_20 AC 75 ms
76,384 KB
testcase_21 AC 110 ms
76,456 KB
testcase_22 AC 159 ms
77,512 KB
testcase_23 AC 67 ms
76,056 KB
testcase_24 AC 61 ms
74,264 KB
testcase_25 AC 173 ms
77,184 KB
testcase_26 AC 119 ms
77,344 KB
testcase_27 AC 160 ms
76,768 KB
testcase_28 AC 78 ms
76,560 KB
testcase_29 AC 167 ms
77,164 KB
testcase_30 AC 131 ms
76,616 KB
testcase_31 AC 230 ms
77,696 KB
testcase_32 AC 117 ms
76,988 KB
testcase_33 AC 82 ms
76,428 KB
testcase_34 AC 171 ms
77,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

input = sys.stdin.buffer.readline


def solve(S, T):
    res = 0
    b = 0
    while S + (1 << b) <= T:
        if (S >> b) & 1:
            S += (1 << b)
            res += 1
        b += 1
    res += bin(T - S).count("1")
    return res


N, Q = map(int, input().split())
for _ in range(Q):
    print(solve(*map(int, input().split())))
0