A15692 | Dora and Search
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
As you know, the girl Dora is always looking for something. This time she was given a permutation, and she wants to find such a subsegment of it that none of the elements at its ends is either the minimum or the maximum of the entire subsegment. More formally, you are asked to find the numbers $l$ and $r$ $(1 \leq l \leq r \leq n)$ such that $a_l \neq \min(a_l, a_{l + 1}, \ldots, a_r)$ , $a_l \neq \max(a_l, a_{l + 1}, \ldots, a_r)$ and $a_r \neq \min(a_l, a_{l + 1}, \ldots, a_r)$ , $a_r \neq \max(a_l, a_{l + 1}, \ldots, a_r)$ .
A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in any order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ( $2$ occurs twice in the array) and $[1,3,4]$ is also not a permutation ( $n=3$ , but $4$ is present in the array).
Help Dora find such a subsegment, or tell her that such a subsegment does not exist.
A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in any order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ( $2$ occurs twice in the array) and $[1,3,4]$ is also not a permutation ( $n=3$ , but $4$ is present in the array).
Help Dora find such a subsegment, or tell her that such a subsegment does not exist.
输入格式
Each test consists of multiple test cases. The first line contains a single integer $t$ ( $1 \leq t \leq 10^4$ ) — the number of test cases. Description of the test cases follows.
For each test case, the first line contains one integer $n$ ( $1 \leq n \leq 2 \cdot 10^5$ ) — the length of permutation.
The second line contains $n$ distinct integers $a_1, a_2, \ldots, a_n$ ( $1 \leq a_i \leq n$ ) — the elements of permutation.
It is guarented that the sum of $n$ over all test cases doesn't exceed $2 \cdot 10^5$ .
For each test case, the first line contains one integer $n$ ( $1 \leq n \leq 2 \cdot 10^5$ ) — the length of permutation.
The second line contains $n$ distinct integers $a_1, a_2, \ldots, a_n$ ( $1 \leq a_i \leq n$ ) — the elements of permutation.
It is guarented that the sum of $n$ over all test cases doesn't exceed $2 \cdot 10^5$ .
输出格式
For each test case, output $-1$ if the desired subsegment does not exist.
Otherwise, output two indexes $l, r$ such that $[a_{l}, a_{l + 1}, \ldots, a_{r}]$ satisfies all conditions.
If there are several solutions, then output any of them.
Otherwise, output two indexes $l, r$ such that $[a_{l}, a_{l + 1}, \ldots, a_{r}]$ satisfies all conditions.
If there are several solutions, then output any of them.
输入输出样例
输入 #1
4 3 1 2 3 4 2 1 4 3 7 1 3 2 4 6 5 7 6 2 3 6 5 4 1
输出 #1
-1 1 4 2 6 -1
In the first and fourth test cases, it can be shown that there are no desired subsegments.
In the second test case, the subsegment $[1, 4]$ satisfies all the conditions, because $\max(a_1, a_2, a_3, a_4) = 4, \min(a_1, a_2, a_3, a_4) = 1$ , as we see, all the conditions are met.
In the third test case, the subsegment $[2, 6]$ also satisfies all the conditions described.
In the second test case, the subsegment $[1, 4]$ satisfies all the conditions, because $\max(a_1, a_2, a_3, a_4) = 4, \min(a_1, a_2, a_3, a_4) = 1$ , as we see, all the conditions are met.
In the third test case, the subsegment $[2, 6]$ also satisfies all the conditions described.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted