codeforces-scrape

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

2064B.md (2982B)


      1 Source: https://codeforces.com/problemset/problem/2064/B
      2 
      3 B. Variety is Discouraged
      4 
      5 time limit per test
      6 
      7 1.5 seconds
      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 Define the score of an arbitrary array $b$ to be the length of $b$ minus the number of distinct elements in $b$. For example:
     22 
     23 * The score of $[1, 2, 2, 4]$ is $1$, as it has length $4$ and only $3$ distinct elements ($1$, $2$, $4$).
     24 * The score of $[1, 1, 1]$ is $2$, as it has length $3$ and only $1$ distinct element ($1$).
     25 * The empty array has a score of $0$.
     26 
     27 You have an array $a$. You need to remove some non-empty contiguous subarray from $a$ at most once.
     28 
     29 More formally, you can do the following at most once:
     30 
     31 * pick two integers $l$, $r$ where $1 \le l \le r \le n$, and
     32 * delete the contiguous subarray $[a_l,\ldots,a_r]$ from $a$ (that is, replace $a$ with $[a_1,\ldots,a_{l - 1},a_{r + 1},\ldots,a_n]$).
     33 
     34 Output an operation such that the score of $a$ is maximum; if there are multiple answers, output one that minimises the final length of $a$ after the operation. If there are still multiple answers, you may output any of them.
     35 
     36 Input
     37 
     38 The first line contains an integer $t$ ($1 \le t \le 10^4$) — the number of testcases.
     39 
     40 The first line of each testcase contains an integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the length of the array $a$.
     41 
     42 The second line of each testcase contains $n$ integers $a_1,a_2,\ldots,a_n$ ($1 \le a_i \le n$).
     43 
     44 The sum of $n$ across all testcases does not exceed $2 \cdot 10^5$.
     45 
     46 Output
     47 
     48 For each testcase, if you wish to not make a move, output $0$.
     49 
     50 Otherwise, output two integers $l$ and $r$ ($1 \le l \le r \le n$), representing the left and right bound of the removed subarray.
     51 
     52 The removed subarray should be chosen such that the score is maximized, and over all such answers choose any of them that minimises the final length of the array.
     53 
     54 Example
     55 
     56 Input
     57 
     58 ```
     59 3
     60 
     61 1
     62 
     63 1
     64 
     65 5
     66 
     67 1 1 1 1 1
     68 
     69 4
     70 
     71 2 1 3 2
     72 ```
     73 
     74 Output
     75 
     76 ```
     77 1 1
     78 0
     79 2 3
     80 ```
     81 
     82 Note
     83 
     84 In the first testcase, we have two options:
     85 
     86 * do nothing: the score of $[1]$ is $1-1=0$.
     87 * remove the subarray with $l=1$, $r=1$: we remove the only element, and we get an empty array with score $0$.
     88 
     89 Therefore, the maximum score possible is $0$. However, since we need to additionally minimise the final length of the array, we must output the second option with $l=r=1$. Note that the first option of doing nothing is incorrect, since it has a longer final length.
     90 
     91 In the second testcase, no subarray is selected, so after which $a$ is still $[1, 1, 1, 1, 1]$. This has length $5$ and $1$ distinct element, so it has a score of $5 - 1 = 4$. This can be proven to be a shortest array which maximises the score.
     92 
     93 In the third testcase, the subarray selected is $[2, \color{red}1, \color{red}3, 2]$, after which $a$ becomes $[2, 2]$. This has length $2$ and $1$ distinct element, so it has a score of $2 - 1 = 1$. This can be proven to be a shortest array which maximises the score.