codeforces-scrape

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

1883F.md (1682B)


      1 Source: https://codeforces.com/problemset/problem/1883/F
      2 
      3 F. You Are So Beautiful
      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 You are given an array of integers $a_1, a_2, \ldots, a_n$. Calculate the number of subarrays of this array $1 \leq l \leq r \leq n$, such that:
     22 
     23 * The array $b = [a_l, a_{l+1}, \ldots, a_r]$ occurs in the array $a$ as a subsequence exactly once. In other words, there is exactly one way to select a set of indices $1 \leq i_1 \lt i_2 \lt \ldots \lt i_{r - l + 1} \leq n$, such that $b_j = a_{i_j}$ for all $1 \leq j \leq r - l + 1$.
     24 
     25 Input
     26 
     27 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. This is followed by their description.
     28 
     29 The first line of each test case contains an integer $n$ ($1 \leq n \leq 10^5$) — the size of the array $a$.
     30 
     31 The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$).
     32 
     33 It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
     34 
     35 Output
     36 
     37 For each test case, output the number of suitable subarrays.
     38 
     39 Example
     40 
     41 Input
     42 
     43 ```
     44 6
     45 
     46 1
     47 
     48 1
     49 
     50 2
     51 
     52 1 1
     53 
     54 3
     55 
     56 1 2 1
     57 
     58 4
     59 
     60 2 3 2 1
     61 
     62 5
     63 
     64 4 5 4 5 4
     65 
     66 10
     67 
     68 1 7 7 2 3 4 3 2 1 100
     69 ```
     70 
     71 Output
     72 
     73 ```
     74 1
     75 1
     76 4
     77 7
     78 4
     79 28
     80 ```
     81 
     82 Note
     83 
     84 In the first test case, there is exactly one subarray $(1, 1)$ that suits us.
     85 
     86 In the second test case, there is exactly one subarray $(1, 2)$ that suits us. Subarrays $(1, 1)$ and $(2, 2)$ do not suit us, as the subsequence $[1]$ occurs twice in the array.
     87 
     88 In the third test case, all subarrays except $(1, 1)$ and $(3, 3)$ are suitable.