結果

問題 No.1742 Binary Indexed Train
ユーザー rlangevinrlangevin
提出日時 2023-08-24 12:15:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 622 ms / 3,000 ms
コード長 855 bytes
コンパイル時間 597 ms
コンパイル使用メモリ 87,020 KB
実行使用メモリ 78,620 KB
最終ジャッジ日時 2023-08-24 12:15:24
合計ジャッジ時間 15,405 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,344 KB
testcase_01 AC 71 ms
71,132 KB
testcase_02 AC 69 ms
71,540 KB
testcase_03 AC 469 ms
77,924 KB
testcase_04 AC 462 ms
77,928 KB
testcase_05 AC 470 ms
78,356 KB
testcase_06 AC 455 ms
78,136 KB
testcase_07 AC 467 ms
77,884 KB
testcase_08 AC 622 ms
77,860 KB
testcase_09 AC 529 ms
77,856 KB
testcase_10 AC 572 ms
78,068 KB
testcase_11 AC 542 ms
78,620 KB
testcase_12 AC 600 ms
78,464 KB
testcase_13 AC 398 ms
78,156 KB
testcase_14 AC 403 ms
77,552 KB
testcase_15 AC 214 ms
77,572 KB
testcase_16 AC 173 ms
77,504 KB
testcase_17 AC 482 ms
77,364 KB
testcase_18 AC 476 ms
77,636 KB
testcase_19 AC 332 ms
78,052 KB
testcase_20 AC 123 ms
77,540 KB
testcase_21 AC 241 ms
77,736 KB
testcase_22 AC 489 ms
77,756 KB
testcase_23 AC 129 ms
77,464 KB
testcase_24 AC 115 ms
77,480 KB
testcase_25 AC 357 ms
77,808 KB
testcase_26 AC 354 ms
77,868 KB
testcase_27 AC 331 ms
78,004 KB
testcase_28 AC 139 ms
77,428 KB
testcase_29 AC 454 ms
77,256 KB
testcase_30 AC 256 ms
78,560 KB
testcase_31 AC 486 ms
77,792 KB
testcase_32 AC 247 ms
77,904 KB
testcase_33 AC 158 ms
78,300 KB
testcase_34 AC 331 ms
77,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(S, T):
    if S == 0:
        ans = 0
        for i in range(65):
            ans += (T >> i) & 1
        return ans 
    flag = 0
    M = 65
    L = []
    start = -1
    ans = 0
    for i in range(M - 1, -1, -1):
        if flag == 0:
            if (T >> i) & 1 == ((S >> i) & 1) + 1:
                flag = 1
                start = i
        else:
            if (S >> i) & 1:
                L.append(i)
            if (T >> i) & 1:
                ans += 1
    if L:
        return ans + start - L[-1] - len(L) + 1
    else:
        return ans + start + 1


N, Q = map(int, input().split())
for _ in range(Q):
    S, T = map(int, input().split())
    for i in range(65, -1, -1):
        vs, vt = (S >> i) & 1, (T >> i) & 1
        if vs != vt:
            break
        S -= vs * (1 << i)
        T -= vt * (1 << i)
    print(solve(S, T))
0