結果

問題 No.1742 Binary Indexed Train
ユーザー suosuo
提出日時 2021-11-12 23:05:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 842 ms / 3,000 ms
コード長 637 bytes
コンパイル時間 452 ms
コンパイル使用メモリ 87,112 KB
実行使用メモリ 79,328 KB
最終ジャッジ日時 2023-08-17 03:35:07
合計ジャッジ時間 18,438 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
70,908 KB
testcase_01 AC 72 ms
70,904 KB
testcase_02 AC 77 ms
71,344 KB
testcase_03 AC 770 ms
77,472 KB
testcase_04 AC 766 ms
77,656 KB
testcase_05 AC 773 ms
77,580 KB
testcase_06 AC 364 ms
79,328 KB
testcase_07 AC 371 ms
79,128 KB
testcase_08 AC 835 ms
77,652 KB
testcase_09 AC 842 ms
77,576 KB
testcase_10 AC 839 ms
78,184 KB
testcase_11 AC 828 ms
77,600 KB
testcase_12 AC 833 ms
77,600 KB
testcase_13 AC 548 ms
77,232 KB
testcase_14 AC 569 ms
76,920 KB
testcase_15 AC 243 ms
77,768 KB
testcase_16 AC 220 ms
78,208 KB
testcase_17 AC 494 ms
78,028 KB
testcase_18 AC 492 ms
78,228 KB
testcase_19 AC 341 ms
79,048 KB
testcase_20 AC 158 ms
77,784 KB
testcase_21 AC 268 ms
77,496 KB
testcase_22 AC 528 ms
77,452 KB
testcase_23 AC 149 ms
77,712 KB
testcase_24 AC 133 ms
77,756 KB
testcase_25 AC 484 ms
77,568 KB
testcase_26 AC 352 ms
78,408 KB
testcase_27 AC 429 ms
78,008 KB
testcase_28 AC 168 ms
78,280 KB
testcase_29 AC 515 ms
77,772 KB
testcase_30 AC 326 ms
77,568 KB
testcase_31 AC 696 ms
77,396 KB
testcase_32 AC 320 ms
77,536 KB
testcase_33 AC 162 ms
77,196 KB
testcase_34 AC 494 ms
77,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,q = map(int,input().split())
for i in range(q):
  s,t = map(int,input().split())
  if s == 0:
    print(bin(t).count('1'))
    continue
  ans = 0
  while (s).bit_length() != (t).bit_length():
    s += s & -s
    ans += 1
  if ans != 0:
    ans += bin(t).count('1') - 1
  else:
    ls = bin(s)
    lt = bin(t)
    for i in range(len(ls)):
      if ls[i] != lt[i]:
        ind = i
        break
    p = 1 << (len(ls) - ind - 1)
    if s % p != 0:
      while s // p != t // p:
        s += s & -s
        ans += 1
      ls = bin(s)
      lt = bin(t)
    for i in range(ind,len(ls)):
      if ls[i] != lt[i]:
        ans += 1
  print(ans)
0