9118: Non-Puzzle: Error Permutation

内存限制:128 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:0 通过:0

题目描述

You are given a permutation PPP of length nnn. Find the number of its subsegments [l…r][l\dots r][lr](l≤rl \le rlr) that satisfies the following condition:

  • ∀1≤i≤r−l+1\forall 1\le i \le r-l+11irl+1 , the iii-th element of this subsegment (that is, Pl+i−1P_{l+i-1}Pl+i1) is not the iii-th smallest element in this subsegment.

输入格式

There are multiple test cases.
The first line contains one integer TTT (1≤T≤10001\le T \le 10001T1000), representing the number of test cases.
For each test case, the first line contains a single integer nnn (1≤n≤50001\le n \le 50001n5000), representing the length of the permutation.
The following line contains nnn integers p1,p2…pnp_{1},p_{2} \dots p_{n}p1,p2pn, representing the permutation.
It is guaranteed that the sum of nnn does not exceed 500050005000.

输出格式

For each test case, output a line containing a single integer representing the answer.
示例1

输入样例 复制

4
5
2 4 1 5 3
5
1 4 5 3 2
2
2 1
6
2 5 4 3 6 1

输出样例 复制

5
4
1
6

分类标签