379 传统题

[CF2289C] 唯一最小值子段计数 (Problem from Ust-Katav)

时间限制
2000ms
内存限制
256MiB
登顶 / 尝试
1/ 1
难度
4

[CF2289C] 唯一最小值子段计数 (Problem from Ust-Katav)

Problem Statement

You are given a permutation of integers p1,p2,…,pnp_1, p_2, \dots, p_n.

A subarray pl,pl+1,…,prp_l, p_{l+1}, \dots, p_r is called good if there does not exist another subarray of the same length with the same value of the minimum element in pp.

Find the number of good subarrays of the permutation pp.

Input

First line: tt (1≤t≤1041 \le t \le 10^4). Each test case: nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) and permutation p1,…,pnp_1, \dots, p_n. Sum of n≤2⋅105n \le 2 \cdot 10^5.

Output

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

样例

4
1
1
2
1 2
4
3 2 4 1
7
3 7 5 1 6 4 2
1
3
8
14