#P12608. 骷髅打金服

    ID: 11657 远端评测题 1000~3000ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>洛谷原创分治哈希 hashing随机化洛谷月赛哈希表

骷髅打金服

Description

You are given an integer sequence of size nn.

A non-empty contiguous subsequence of aa is called beautiful if and only if every element appearing in it occurs the same number of times.

Your task is to compute the number of beautiful contiguous subsequences. The same beautiful subsequence appearing at different positions is counted multiple times.

Input Format

The first line contains a single integer tt — the number of test cases.

For each test case, the first line contains an integer nn.

The second line contains nn integers a1,a2,,ana_1,a_2,\dots,a_n.

Output Format

For each test case, print a single integer — the number of beautiful contiguous subsequences in that test case.

5
9
1 1 1 2 2 2 3 3 3
4
1 1 2 2
5
1 1 2 2 1
10
1 2 2 1 1 2 3 2 3 3
12
1 1 2 3 3 2 1 2 3 3 2 1
25
8
11
26
34

Hint

Sample Explanation

In the third example, the intervals representing all beautiful subsequences are:

  • [1,1][1,1]
  • [1,2][1,2]
  • [1,4][1,4]
  • [2,2][2,2]
  • [2,3][2,3]
  • [2,5][2,5]
  • [3,3][3,3]
  • [3,4][3,4]
  • [4,4][4,4]
  • [4,5][4,5]
  • [5,5][5,5]

Data Range

The problem uses subtask dependencies: failing a prerequisite subtask will result in a score of zero for any subtask.

It is guaranteed that for all testcases, T1,1n,n106,1ainT\ge 1,1\le n,\sum n\le 10^6,1\le a_i\le n

# nn\le n \sum n\le\ Special Constraints Points Time Limit Depends On
11 100100 10001000 - 1010 1s
22 80008000 4×1044\times 10^4 11
33 - 2×1052\times 10^5 1ai41\le a_i \le 4 2020
44 all aia_is are generated uniformly random from [1,n][1,n] 1010
55 1ai141\le a_i\le 14 2020 33
66 - 1010 151\sim 5
77 5×1055\times 10^5 2s 161\sim 6
88 10610^6 3s 171\sim 7