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