結果
| 問題 |
No.1742 Binary Indexed Train
|
| コンテスト | |
| ユーザー |
👑 Kazun
|
| 提出日時 | 2021-10-14 17:45:35 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 326 ms / 3,000 ms |
| コード長 | 459 bytes |
| コンパイル時間 | 302 ms |
| コンパイル使用メモリ | 82,604 KB |
| 実行使用メモリ | 78,208 KB |
| 最終ジャッジ日時 | 2024-11-25 10:55:27 |
| 合計ジャッジ時間 | 8,556 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
popcount=lambda x:bin(x).count("1")
def solve(S,T,N):
k=1<<N
while not((T-1)//k > (S-1)//k):
k>>=1
mid=k*((S+k-1)//k)
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)))
Kazun