結果

問題 No.1742 Binary Indexed Train
ユーザー 👑 obakyanobakyan
提出日時 2022-01-16 20:37:13
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 1,281 ms / 3,000 ms
コード長 1,105 bytes
コンパイル時間 83 ms
コンパイル使用メモリ 5,376 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-02 18:36:26
合計ジャッジ時間 20,442 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1,281 ms
5,376 KB
testcase_04 AC 1,166 ms
5,376 KB
testcase_05 AC 1,179 ms
5,376 KB
testcase_06 AC 48 ms
5,376 KB
testcase_07 AC 46 ms
5,376 KB
testcase_08 AC 1,187 ms
5,376 KB
testcase_09 AC 1,229 ms
5,376 KB
testcase_10 AC 1,200 ms
5,376 KB
testcase_11 AC 1,087 ms
5,376 KB
testcase_12 AC 1,119 ms
5,376 KB
testcase_13 AC 1,082 ms
5,376 KB
testcase_14 AC 1,110 ms
5,376 KB
testcase_15 AC 162 ms
5,376 KB
testcase_16 AC 175 ms
5,376 KB
testcase_17 AC 402 ms
5,376 KB
testcase_18 AC 396 ms
5,376 KB
testcase_19 AC 137 ms
5,376 KB
testcase_20 AC 16 ms
5,376 KB
testcase_21 AC 176 ms
5,376 KB
testcase_22 AC 507 ms
5,376 KB
testcase_23 AC 48 ms
5,376 KB
testcase_24 AC 21 ms
5,376 KB
testcase_25 AC 598 ms
5,376 KB
testcase_26 AC 186 ms
5,376 KB
testcase_27 AC 459 ms
5,376 KB
testcase_28 AC 35 ms
5,376 KB
testcase_29 AC 548 ms
5,376 KB
testcase_30 AC 417 ms
5,376 KB
testcase_31 AC 1,205 ms
5,376 KB
testcase_32 AC 416 ms
5,376 KB
testcase_33 AC 147 ms
5,376 KB
testcase_34 AC 761 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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")
local lim = 1LL
for i = 1, n do
  lim = lim + lim
end
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 % (j1 + j1) == 0LL and j1 + j1 <= lim do
    j1 = j1 + j1
  end
  local j2 = 1LL
  while j2 + j2 <= len and j2 + j2 <= lim 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 and j1 + j1 <= lim 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