結果

問題 No.905 Sorted?
ユーザー 👑 obakyanobakyan
提出日時 2019-10-11 22:03:46
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 221 ms / 2,000 ms
コード長 819 bytes
コンパイル時間 158 ms
コンパイル使用メモリ 5,296 KB
実行使用メモリ 14,396 KB
最終ジャッジ日時 2023-08-16 17:54:16
合計ジャッジ時間 3,448 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 10 ms
4,376 KB
testcase_08 AC 142 ms
8,256 KB
testcase_09 AC 87 ms
7,132 KB
testcase_10 AC 169 ms
13,328 KB
testcase_11 AC 136 ms
9,064 KB
testcase_12 AC 149 ms
8,792 KB
testcase_13 AC 199 ms
14,396 KB
testcase_14 AC 191 ms
14,036 KB
testcase_15 AC 183 ms
11,100 KB
testcase_16 AC 147 ms
9,444 KB
testcase_17 AC 221 ms
12,048 KB
testcase_18 AC 188 ms
12,136 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local function lltonumber(str)
  local ret = 0LL
  local sign = str:sub(1, 1) ~= "-"
  local begin = sign and 1 or 2
  for i = begin, #str do
    ret = ret * 10LL
    ret = ret + tonumber(str:sub(i, i))
  end
  if not sign then ret = ret * -1LL end
  return ret
end

local n = io.read("*n", "*l")
local s = io.read()
local t = {}
for w in s:gmatch("-?%d+") do
  local num = lltonumber(w)
  table.insert(t, num)
end
local inc = {1}
local dec = {1}
for i = 2, n do
  if t[i - 1] <= t[i] then
    inc[i] = inc[i - 1]
  else
    inc[i] = i
  end
  if t[i] <= t[i - 1] then
    dec[i] = dec[i - 1]
  else
    dec[i] = i
  end
end
local q = io.read("*n")
for i = 1, q do
  local l, r = io.read("*n", "*n")
  l, r = l + 1, r + 1
  local a = inc[r] <= l and 1 or 0
  local b = dec[r] <= l and 1 or 0
  print(a .. " " .. b)
end
0