結果

問題 No.1742 Binary Indexed Train
ユーザー brthyyjpbrthyyjp
提出日時 2022-01-19 12:09:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 372 ms / 3,000 ms
コード長 601 bytes
コンパイル時間 504 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 83,840 KB
最終ジャッジ日時 2024-05-02 19:44:58
合計ジャッジ時間 9,781 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
51,712 KB
testcase_01 AC 35 ms
51,968 KB
testcase_02 AC 35 ms
52,224 KB
testcase_03 AC 351 ms
80,000 KB
testcase_04 AC 372 ms
80,512 KB
testcase_05 AC 354 ms
80,256 KB
testcase_06 AC 96 ms
77,056 KB
testcase_07 AC 93 ms
76,800 KB
testcase_08 AC 339 ms
83,072 KB
testcase_09 AC 358 ms
83,840 KB
testcase_10 AC 347 ms
83,712 KB
testcase_11 AC 352 ms
83,456 KB
testcase_12 AC 344 ms
83,584 KB
testcase_13 AC 234 ms
80,128 KB
testcase_14 AC 253 ms
79,872 KB
testcase_15 AC 102 ms
76,928 KB
testcase_16 AC 103 ms
70,784 KB
testcase_17 AC 157 ms
78,080 KB
testcase_18 AC 166 ms
78,464 KB
testcase_19 AC 99 ms
76,416 KB
testcase_20 AC 52 ms
64,256 KB
testcase_21 AC 103 ms
77,312 KB
testcase_22 AC 181 ms
78,976 KB
testcase_23 AC 63 ms
65,792 KB
testcase_24 AC 55 ms
64,128 KB
testcase_25 AC 200 ms
80,000 KB
testcase_26 AC 109 ms
76,800 KB
testcase_27 AC 178 ms
79,488 KB
testcase_28 AC 61 ms
67,584 KB
testcase_29 AC 188 ms
79,232 KB
testcase_30 AC 148 ms
77,568 KB
testcase_31 AC 314 ms
79,872 KB
testcase_32 AC 149 ms
77,312 KB
testcase_33 AC 84 ms
68,608 KB
testcase_34 AC 222 ms
78,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

def popcount(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f

n, q = map(int, input().split())
for i in range(q):
    s, t = map(int, input().split())
    for i in range(n+1):
        if (s-1)//(1<<i) != (t-1)//(1<<i):
            mid = (1<<i)*(t//(1<<i))
    ans = popcount(mid-s)+popcount(t-mid)
    print(ans)
0