結果

問題 No.905 Sorted?
ユーザー 👑 obakyanobakyan
提出日時 2019-10-11 22:03:46
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 177 ms / 2,000 ms
コード長 819 bytes
コンパイル時間 373 ms
コンパイル使用メモリ 5,376 KB
実行使用メモリ 13,880 KB
最終ジャッジ日時 2024-05-04 01:40:51
合計ジャッジ時間 3,065 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 5 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 12 ms
5,376 KB
testcase_08 AC 109 ms
8,376 KB
testcase_09 AC 62 ms
6,940 KB
testcase_10 AC 157 ms
13,116 KB
testcase_11 AC 93 ms
9,728 KB
testcase_12 AC 98 ms
9,344 KB
testcase_13 AC 177 ms
13,756 KB
testcase_14 AC 177 ms
13,880 KB
testcase_15 AC 91 ms
9,728 KB
testcase_16 AC 98 ms
9,760 KB
testcase_17 AC 149 ms
12,824 KB
testcase_18 AC 136 ms
12,696 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,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