結果

問題 No.1742 Binary Indexed Train
コンテスト
ユーザー wolgnik
提出日時 2021-11-12 22:35:22
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 903 ms / 3,000 ms
コード長 391 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 403 ms
コンパイル使用メモリ 84,992 KB
実行使用メモリ 81,152 KB
最終ジャッジ日時 2026-05-20 09:52:43
合計ジャッジ時間 16,077 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
input = sys.stdin.readline
N, Q = map(int, input().split())

table = [1 << i for i in range(N + 1)]

for _ in range(Q):
  s, t = map(int, input().split())
  res = 0

  while s < t:
    ok = 0
    ng = N + 1
    while ng - ok > 1:
      m = (ok + ng) // 2
      x = table[m]
      if s % x == 0 and s + x <= t: ok = m
      else: ng = m
    s += table[ok]
    res += 1
  print(res)
0