結果

問題 No.1742 Binary Indexed Train
ユーザー rlangevinrlangevin
提出日時 2023-08-24 08:58:34
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 686 bytes
コンパイル時間 781 ms
コンパイル使用メモリ 87,008 KB
実行使用メモリ 78,532 KB
最終ジャッジ日時 2023-08-24 08:58:51
合計ジャッジ時間 15,882 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,364 KB
testcase_01 AC 69 ms
71,164 KB
testcase_02 AC 70 ms
71,420 KB
testcase_03 AC 434 ms
78,016 KB
testcase_04 AC 419 ms
77,904 KB
testcase_05 AC 419 ms
77,972 KB
testcase_06 AC 390 ms
78,432 KB
testcase_07 AC 371 ms
78,496 KB
testcase_08 AC 560 ms
78,072 KB
testcase_09 AC 525 ms
77,936 KB
testcase_10 AC 502 ms
77,896 KB
testcase_11 AC 536 ms
78,296 KB
testcase_12 AC 521 ms
78,252 KB
testcase_13 AC 388 ms
78,312 KB
testcase_14 AC 390 ms
78,532 KB
testcase_15 AC 212 ms
77,784 KB
testcase_16 AC 184 ms
77,820 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 230 ms
77,908 KB
testcase_22 AC 430 ms
77,976 KB
testcase_23 AC 143 ms
77,724 KB
testcase_24 AC 136 ms
77,704 KB
testcase_25 AC 356 ms
78,416 KB
testcase_26 WA -
testcase_27 AC 323 ms
78,168 KB
testcase_28 WA -
testcase_29 AC 442 ms
77,776 KB
testcase_30 AC 242 ms
77,908 KB
testcase_31 AC 445 ms
77,704 KB
testcase_32 AC 238 ms
77,976 KB
testcase_33 AC 159 ms
77,864 KB
testcase_34 AC 305 ms
78,240 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())
    print(solve(S, T))
0