結果
| 問題 |
No.1742 Binary Indexed Train
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2022-01-16 20:32:19 |
| 言語 | Lua (LuaJit 2.1.1734355927) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 995 bytes |
| コンパイル時間 | 318 ms |
| コンパイル使用メモリ | 5,376 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-23 12:18:03 |
| 合計ジャッジ時間 | 22,470 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 WA * 15 |
ソースコード
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())