codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1793C.md (2385B)


      1 Source: https://codeforces.com/problemset/problem/1793/C
      2 
      3 C. Dora and Search
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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)$.
     22 
     23 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).
     24 
     25 Help Dora find such a subsegment, or tell her that such a subsegment does not exist.
     26 
     27 Input
     28 
     29 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.
     30 
     31 For each test case, the first line contains one integer $n$ ($1 \leq n \leq 2 \cdot 10^5$) — the length of permutation.
     32 
     33 The second line contains $n$ distinct integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq n$) — the elements of permutation.
     34 
     35 It is guarented that the sum of $n$ over all test cases doesn't exceed $2 \cdot 10^5$.
     36 
     37 Output
     38 
     39 For each test case, output $-1$ if the desired subsegment does not exist.
     40 
     41 Otherwise, output two indexes $l, r$ such that $[a_{l}, a_{l + 1}, \ldots, a_{r}]$ satisfies all conditions.
     42 
     43 If there are several solutions, then output any of them.
     44 
     45 Example
     46 
     47 Input
     48 
     49 ```
     50 4
     51 
     52 3
     53 
     54 1 2 3
     55 
     56 4
     57 
     58 2 1 4 3
     59 
     60 7
     61 
     62 1 3 2 4 6 5 7
     63 
     64 6
     65 
     66 2 3 6 5 4 1
     67 ```
     68 
     69 Output
     70 
     71 ```
     72 -1
     73 1 4
     74 2 6
     75 -1
     76 ```
     77 
     78 Note
     79 
     80 In the first and fourth test cases, it can be shown that there are no desired subsegments.
     81 
     82 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.
     83 
     84 In the third test case, the subsegment $[2, 6]$ also satisfies all the conditions described.