310790: CF1888C. You Are So Beautiful

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. You Are So Beautifultime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

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:

  • 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 < i_2 < \ldots < i_{r - l + 1} \leq n$, such that $b_j = a_{i_j}$ for all $1 \leq j \leq r - l + 1$.
Input

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.

The first line of each test case contains an integer $n$ ($1 \leq n \leq 10^5$) — the size of the array $a$.

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$).

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.

Output

For each test case, output the number of suitable subarrays.

ExampleInput
6
1
1
2
1 1
3
1 2 1
4
2 3 2 1
5
4 5 4 5 4
10
1 7 7 2 3 4 3 2 1 100
Output
1
1
4
7
4
28
Note

In the first test case, there is exactly one subarray $(1, 1)$ that suits us.

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.

In the third test case, all subarrays except $(1, 1)$ and $(3, 3)$ are suitable.

Output

题目大意:给定一个整数数组 a_1, a_2, \ldots, a_n,计算有多少个子数组 b = [a_l, a_{l+1}, \ldots, a_r](1 \leq l \leq r \leq n),满足以下条件:
- 子数组 b 在原数组 a 中作为子序列恰好出现一次。换句话说,恰好存在一种方式选择一组索引 1 \leq i_1 < i_2 < \ldots < i_{r - l + 1} \leq n,使得对于所有 1 \leq j \leq r - l + 1,都有 b_j = a_{i_j}。

输入数据格式:
- 每个测试包含多个测试用例。第一行包含一个整数 t (1 \leq t \leq 10^4) —— 测试用例的数量。接下来是它们的描述。
- 每个测试用例的第一行包含一个整数 n (1 \leq n \leq 10^5) —— 数组 a 的大小。
- 每个测试用例的第二行包含 n 个整数 a_1, a_2, \ldots, a_n (1 \leq a_i \leq 10^9)。
- 保证所有测试用例的 n 之和不超过 2 \cdot 10^5。

输出数据格式:
- 对于每个测试用例,输出符合条件的子数组的数量。

示例:
```
输入:
6
1
1
2
1 1
3
1 2 1
4
2 3 2 1
5
4 5 4 5 4
10
1 7 7 2 3 4 3 2 1 100

输出:
1
1
4
7
4
28
```

注意:
- 在第一个测试用例中,恰好有一个子数组 (1, 1) 符合条件。
- 在第二个测试用例中,恰好有一个子数组 (1, 2) 符合条件。子数组 (1, 1) 和 (2, 2) 不符合条件,因为子序列 [1] 在数组中出现了两次。
- 在第三个测试用例中,除了 (1, 1) 和 (3, 3) 之外的所有子数组都符合条件。题目大意:给定一个整数数组 a_1, a_2, \ldots, a_n,计算有多少个子数组 b = [a_l, a_{l+1}, \ldots, a_r](1 \leq l \leq r \leq n),满足以下条件: - 子数组 b 在原数组 a 中作为子序列恰好出现一次。换句话说,恰好存在一种方式选择一组索引 1 \leq i_1 < i_2 < \ldots < i_{r - l + 1} \leq n,使得对于所有 1 \leq j \leq r - l + 1,都有 b_j = a_{i_j}。 输入数据格式: - 每个测试包含多个测试用例。第一行包含一个整数 t (1 \leq t \leq 10^4) —— 测试用例的数量。接下来是它们的描述。 - 每个测试用例的第一行包含一个整数 n (1 \leq n \leq 10^5) —— 数组 a 的大小。 - 每个测试用例的第二行包含 n 个整数 a_1, a_2, \ldots, a_n (1 \leq a_i \leq 10^9)。 - 保证所有测试用例的 n 之和不超过 2 \cdot 10^5。 输出数据格式: - 对于每个测试用例,输出符合条件的子数组的数量。 示例: ``` 输入: 6 1 1 2 1 1 3 1 2 1 4 2 3 2 1 5 4 5 4 5 4 10 1 7 7 2 3 4 3 2 1 100 输出: 1 1 4 7 4 28 ``` 注意: - 在第一个测试用例中,恰好有一个子数组 (1, 1) 符合条件。 - 在第二个测试用例中,恰好有一个子数组 (1, 2) 符合条件。子数组 (1, 1) 和 (2, 2) 不符合条件,因为子序列 [1] 在数组中出现了两次。 - 在第三个测试用例中,除了 (1, 1) 和 (3, 3) 之外的所有子数组都符合条件。

加入题单

上一题 下一题 算法标签: