#P10885. 【MX-S3-T1】「FeOI Round 1」野心

【MX-S3-T1】「FeOI Round 1」野心

Background

Original link: https://oier.team/problems/S3A


Problem Description

Given a permutation pp of 1n1 \sim n, ask how many indices ii (1i<n1 \le i < n) satisfy that after sorting, both [p1,p2,,pi][p_1,p_2,\cdots,p_i] and [pi+1,pi+2,,pn][p_{i+1},p_{i+2},\cdots,p_n] are arithmetic progressions.

Input Format

This problem contains multiple test cases in a single test file.

The first line contains an integer TT, the number of test cases.

Then for each test case, the format is:

The first line contains an integer nn, the length of the permutation.

The next line contains nn integers, the permutation pp.

Output Format

For each test case, output one line containing one integer, the answer to the query.

2
4
1 3 2 4
5
1 5 3 2 4
3
3
4
6
2 1 4 3 6 5
6
1 2 3 4 5 6
3
1 3 2
1
1
2
5
2
0
6
2
1 2
20
16 2 10 18 4 6 8 20 14 12 3 9 17 13 1 15 7 11 19 5
9
3 4 1 5 2 6 7 8 9
10
1 3 2 4 7 6 5 8 10 9
13
5 7 3 11 1 9 13 6 10 4 2 8 12
5
1 2 3 4 5
1
1
4
5
1
4

Hint

[Sample Explanation #1]

Test case 1: There are three splits: [1,3,2][4][1,3,2][4], [1,3][2,4][1,3][2,4], [1][3,2,4][1][3,2,4].

Test case 2: There are three splits: [1][5,3,2,4][1][5,3,2,4], [1,5][3,2,4][1,5][3,2,4], [1,5,3][2,4][1,5,3][2,4].

[Sample Explanation #2]

Test case 1: There are two splits: [2,1][4,3,6,5][2,1][4,3,6,5], [2,1,4,3][6,5][2,1,4,3][6,5].

Test case 2: Every split is valid.

Test case 3: Every split is valid.

Test case 4: There is no split, so no split is valid.

[Constraints]

This problem uses bundled tests.

Let n\sum n be the sum of all nn within a single test file.

For 100%100\% of the data, 1T1051 \le T \le 10^5, 1n1061 \le n \le 10^6, 1n2×1061 \le \sum n \le 2 \times 10^6. It is guaranteed that pp is a permutation and 1pin1 \le p_i \le n.

Subtask ID nn n\sum n Score
11 103\le 10^3 5×103\le 5\times 10^3 3030
22 105\le 10^5 5×105\le 5\times 10^5
33 106\le 10^6 2×106\le 2\times 10^6 4040

Please use fast input/output.

A new subtask 4 is added as hack testdata, with a score of 0\boldsymbol{0}.

Translated by ChatGPT 5