結果

問題 No.1742 Binary Indexed Train
ユーザー H3PO4H3PO4
提出日時 2021-11-12 22:52:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 343 ms / 3,000 ms
コード長 350 bytes
コンパイル時間 291 ms
コンパイル使用メモリ 87,112 KB
実行使用メモリ 79,888 KB
最終ジャッジ日時 2023-08-17 03:15:09
合計ジャッジ時間 9,565 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,304 KB
testcase_01 AC 70 ms
71,248 KB
testcase_02 AC 69 ms
71,616 KB
testcase_03 AC 301 ms
79,172 KB
testcase_04 AC 303 ms
78,988 KB
testcase_05 AC 305 ms
78,884 KB
testcase_06 AC 174 ms
79,640 KB
testcase_07 AC 173 ms
79,672 KB
testcase_08 AC 339 ms
79,888 KB
testcase_09 AC 332 ms
79,424 KB
testcase_10 AC 339 ms
79,492 KB
testcase_11 AC 343 ms
79,856 KB
testcase_12 AC 337 ms
79,656 KB
testcase_13 AC 265 ms
78,312 KB
testcase_14 AC 277 ms
78,296 KB
testcase_15 AC 137 ms
78,364 KB
testcase_16 AC 134 ms
78,156 KB
testcase_17 AC 201 ms
79,364 KB
testcase_18 AC 208 ms
79,356 KB
testcase_19 AC 150 ms
78,976 KB
testcase_20 AC 103 ms
77,840 KB
testcase_21 AC 138 ms
78,352 KB
testcase_22 AC 219 ms
78,944 KB
testcase_23 AC 107 ms
78,068 KB
testcase_24 AC 106 ms
78,036 KB
testcase_25 AC 218 ms
78,532 KB
testcase_26 AC 161 ms
79,456 KB
testcase_27 AC 203 ms
78,696 KB
testcase_28 AC 107 ms
77,884 KB
testcase_29 AC 222 ms
79,092 KB
testcase_30 AC 164 ms
78,368 KB
testcase_31 AC 280 ms
79,308 KB
testcase_32 AC 164 ms
78,352 KB
testcase_33 AC 119 ms
77,940 KB
testcase_34 AC 218 ms
79,020 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