結果
| 問題 |
No.1742 Binary Indexed Train
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-01-07 18:55:34 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 545 ms / 3,000 ms |
| コード長 | 675 bytes |
| コンパイル時間 | 299 ms |
| コンパイル使用メモリ | 82,032 KB |
| 実行使用メモリ | 78,804 KB |
| 最終ジャッジ日時 | 2024-09-27 19:29:52 |
| 合計ジャッジ時間 | 14,217 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
from collections import *
from itertools import *
from functools import *
from heapq import *
import sys,math
input = sys.stdin.readline
N,Q = map(int,input().split())
def solve(s,t):
S = []
T = []
for i in range(61):
if (s>>i)&1:
S.append(i)
if (t>>i)&1:
T.append(i)
if len(S) == 0:
return len(T)
while S[-1]==T[-1]:
S.pop()
T.pop()
if len(S)==0:
break
if len(S) == 0:
return len(T)
cost = T[-1] - S[0] - (len(S) - 1)
cost += (len(T)-1)
return cost
for _ in range(Q):
s,t = map(int,input().split())
print(solve(s,t),flush=True)