Codeforces Round 997 (Div. 2)
D
Unique Median
Codeforces
2200
原题
← CE →
翻译中…

An array $b$ of $m$ integers is called good if, when it is sorted, $b_{\left\lfloor \frac{m + 1}{2} \right\rfloor} = b_{\left\lceil \frac{m + 1}{2} \right\rceil}$. In other words, $b$ is good if both of its medians are equal. In particular, $\left\lfloor \frac{m + 1}{2} \right\rfloor = \left\lceil \frac{m + 1}{2} \right\rceil$ when $m$ is odd, so $b$ is guaranteed to be good if it has an odd length.

翻译中…

You are given an array $a$ of $n$ integers. Calculate the number of good subarrays$^{\text{∗}}$ in $a$.

翻译中…

$^{\text{∗}}$An array $x$ is a subarray of an array $y$ if $x$ can be obtained from $y$ by the deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

翻译中…

Input

翻译中…

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.

翻译中…

The first line of each test case contains a single integer $n$ ($1 \le n \le 10^5$) — the length of the array.

翻译中…

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le \color{red}{\textbf{10}}$) — the given array.

翻译中…

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

翻译中…

Output

翻译中…

For each test case, output a single integer representing the number of good subarrays in $a$.

翻译中…

Note

翻译中…

In the first case, every subarray is good since all its elements are equal to $1$.

翻译中…

In the second case, an example of a good subarray is $b = [10, 2, 3, 3]$. When it is sorted, $b = [2, 3, 3, 10]$, so $b_{\left\lfloor \frac{4 + 1}{2} \right\rfloor} = b_{\left\lceil \frac{4 + 1}{2} \right\rceil} = b_2 = b_3 = 3$. Another example would be $b = [1, 10, 2]$. On the other hand, $b = [1, 10]$ is not good as its two medians are $1$ and $10$, which are not equal.

翻译中…

样例

Input #1
3
4
1 1 1 1
5
1 10 2 3 3
10
6 3 2 3 5 3 4 2 3 5
Output #1
10
11
42
InputCopy OutputCopy
题目信息
题号
2056D
时间限制
2 s
内存限制
512 MB
标签
二分
暴力
组合数学
数据结构
分治
动态规划

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。