codeforces-scrape

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

2201A1.md (2245B)


      1 Source: https://codeforces.com/problemset/problem/2201/A1
      2 
      3 A1. Lost Civilization (Easy Version)
      4 
      5 time limit per test
      6 
      7 2 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 This is the easy version of the problem. The difference between the versions is that in this version, you must compute a value for one sequence. You can hack only if you solved all versions of this problem.
     22 
     23 Let's define an algorithm to generate a sequence of $m+k$ integers as follows:
     24 
     25 1. First, receive a sequence $x$ of $m$ integers as input. If $k=0$, terminate immediately and return the sequence $x$.
     26 2. Then, select any index $1 \le i \le |x|$ and insert $(x_i+1)$ immediately after the element $x_i$.
     27 3. If $x$ contains exactly $m+k$ integers, terminate and return the sequence $x$. Otherwise, return to the second step.
     28 
     29 Alice knows that this algorithm was used by an ancient civilization in order to hide their secrets safely. Alice wants to learn the knowledge that they wanted to hide, but it is not an easy job to infer the input from the output of the algorithm.
     30 
     31 Given a sequence $a$ of $n$ integers, determine the length of the shortest sequence that could be given as an input for the algorithm to generate $a$.
     32 
     33 Input
     34 
     35 Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.
     36 
     37 The first line of each test case contains a single integer $n$ ($1 \le n \le 300\,000$).
     38 
     39 The second line of each test case contains $n$ integers $a_1,a_2,\ldots,a_n$ ($1 \le a_i \le 10^9$).
     40 
     41 It is guaranteed that the sum of $n$ over all test cases does not exceed $300\,000$.
     42 
     43 Output
     44 
     45 For each test case, output the length of the shortest sequence on a separate line.
     46 
     47 Example
     48 
     49 Input
     50 
     51 ```
     52 5
     53 
     54 5
     55 
     56 1 2 3 4 5
     57 
     58 5
     59 
     60 1 3 5 7 9
     61 
     62 5
     63 
     64 1 2 5 6 5
     65 
     66 7
     67 
     68 1 2 4 5 3 7 8
     69 
     70 9
     71 
     72 9 8 9 2 3 4 4 5 3
     73 ```
     74 
     75 Output
     76 
     77 ```
     78 1
     79 
     80 5
     81 
     82 3
     83 
     84 4
     85 
     86 3
     87 ```
     88 
     89 Note
     90 
     91 In the first test case, the sequence $[1]$ can generate the sequence $a=[1,2,3,4,5]$ by the following process:
     92 
     93 $$[1] \to [1,\color{red}{2}] \to [1,2,\color{red}{3}] \to [1,2,3,\color{red}{4}] \to [1,2,3,4,\color{red}{5}]$$
     94 
     95 In the second test case, the only sequence that can generate $a=[1,3,5,7,9]$ is $a$ itself.