結果

問題 No.1742 Binary Indexed Train
ユーザー 👑 obakyanobakyan
提出日時 2022-01-16 20:32:19
言語 Lua
(LuaJit 2.1.1696795921)
結果
WA  
実行時間 -
コード長 995 bytes
コンパイル時間 347 ms
コンパイル使用メモリ 5,376 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-02 18:34:22
合計ジャッジ時間 20,679 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 1,029 ms
5,376 KB
testcase_09 AC 1,195 ms
5,376 KB
testcase_10 AC 1,259 ms
5,376 KB
testcase_11 AC 1,159 ms
5,376 KB
testcase_12 AC 1,088 ms
5,376 KB
testcase_13 AC 1,042 ms
5,376 KB
testcase_14 AC 1,084 ms
5,376 KB
testcase_15 AC 160 ms
5,376 KB
testcase_16 AC 170 ms
5,376 KB
testcase_17 WA -
testcase_18 AC 389 ms
5,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 170 ms
5,376 KB
testcase_22 WA -
testcase_23 AC 46 ms
5,376 KB
testcase_24 AC 20 ms
5,376 KB
testcase_25 AC 577 ms
5,376 KB
testcase_26 WA -
testcase_27 AC 487 ms
5,376 KB
testcase_28 AC 35 ms
5,376 KB
testcase_29 AC 542 ms
5,376 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

local function mmi(a, b) return a < b and a or b end
local ffi = require("ffi")
local C = ffi.C
ffi.cdef[[
long long atoll(const char*);
]]

local function lltonumber(str)
  return C.atoll(str)
end

local n, q = io.read("*n", "*n", "*l")
for iq = 1, q do
  local s, t = io.read():match("(%d+) (%d+)")
  s = lltonumber(s)
  t = lltonumber(t)
  local z = 0
  local len = t - s
  local j1 = 1LL
  while s % (2LL * j1) == 0LL do
    j1 = j1 + j1
  end
  local j2 = 1LL
  while j2 + j2 <= len do
    j2 = j2 + j2
  end
  local j = mmi(j1, j2)
  s = s + j
  len = len - j
  
  while 0LL < len do
    while s % (2LL * j1) == 0LL do
      j1 = j1 + j1
      -- print("a", j1, s)
    end
    while s % j1 == 1LL do
      j1 = j1 / 2LL
      -- print("C", j1, s)
      -- print(j1, s)
    end
    while len < j2 do
      j2 = j2 / 2LL
      -- print("B", j2, len)
    end
    -- print(j1, j2)
    j = mmi(j1, j2)
    z = z + 1
    len = len - j
    s = s + j
  end
  print(z + 1)
end
-- print(os.clock())
0