結果

問題 No.1742 Binary Indexed Train
ユーザー 👑 Kazun
提出日時 2021-10-14 17:36:25
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 536 bytes
コンパイル時間 281 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 137,728 KB
最終ジャッジ日時 2024-11-25 10:55:04
合計ジャッジ時間 32,160 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 TLE * 1
other AC * 19 WA * 8 TLE * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

popcount=lambda x:bin(x).count("1")

def solve(S,T,N):
    l=0; r=1<<N
    while True:
        mid=(l+r)>>1

        if T<mid:
            r=mid
        elif mid<=S:
            l=mid
        else:
            break

    return popcount(mid-S)+popcount(T-mid)

#================================================
import sys
input=sys.stdin.readline
write=sys.stdout.write

N,Q=map(int,input().split())

Max=1<<N
Ans=[0]*Q
for quest in range(Q):
    S,T=map(int,input().split())
    Ans[quest]=solve(S,T,N)

write("\n".join(map(str,Ans)))
0