結果
| 問題 |
No.905 Sorted?
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-10-11 22:03:46 |
| 言語 | Lua (LuaJit 2.1.1734355927) |
| 結果 |
AC
|
| 実行時間 | 153 ms / 2,000 ms |
| コード長 | 819 bytes |
| コンパイル時間 | 107 ms |
| コンパイル使用メモリ | 6,820 KB |
| 実行使用メモリ | 13,876 KB |
| 最終ジャッジ日時 | 2024-11-25 07:30:46 |
| 合計ジャッジ時間 | 2,435 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
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