#P15457. 【MX-X25-T1】『FeOI-5』序列变换

    ID: 17426 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度普及 上传者: 标签>模拟O2优化双指针 two-pointer梦熊比赛

【MX-X25-T1】『FeOI-5』序列变换

Problem Description

Given a sequence aa of length nn, repeatedly perform the following operations:

  1. ∀i∈[1,n]\forall i\in[1,n], let bib_i be the mex\text{mex} (the smallest non-negative integer that does not appear) of the set {a1,a2,a3,…,ai}\{a_1,a_2,a_3,\dots,a_i\};
  2. ∀i∈[1,n]\forall i\in[1,n], update aia_i to bib_i.

Find how many different sequences aa will be generated during this process (including the original sequence, i.e., the sequence after round 00). Two sequences a,ba,b of length nn are different if and only if ∃i∈[1,n]\exist i\in[1,n] such that ai≠bia_i\not=b_i.

Input Format

The first line contains two integers c,Tc,T, representing the subtask index of the test points (the samples guarantee that c=0c=0) and the number of test cases.

For each test case, the input consists of two lines:

  • The first line contains one integer nn;
  • The second line contains nn integers describing the sequence aa.

Output Format

For each test case, output one line with one integer, representing the answer.

0 1
5
3 2 1 1 4
3
0 1
12
1 0 3 2 2 1 4 5 6 8 7 9
4

Hint

[Sample 1 Explanation]

These are the results after the first few rounds of operations:

3 2 1 1 4
0 0 0 0 0
1 1 1 1 1
0 0 0 0 0

It is easy to see that afterwards, the sequence aa will keep alternating between the all-11 sequence and the all-00 sequence. Therefore, a total of 33 sequences aa will be generated, so the answer is 33.

[Sample 2 Explanation]

These are the results after the first few rounds of operations:

1 0 3 2 2 1 4 5 6 8 7 9
0 2 2 4 4 4 5 6 7 7 9 10
1 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1 1 1

[Constraints]

For all testdata, 1≤n,∑n≤1061\le n,\sum n\le 10^6, 0≤ai≤n0\le a_i\le n, 1≤T≤1001\le T\le 100.

Subtask Index ∑n\sum n Special Property Score
11 ≤5\le 5 None 55
22 ≤10\le 10 1010
33 ≤106\le 10^6 ai∈{0,1}a_i\in\{0,1\}
44 ≤5000\le 5000 None 2020
55 ≤106\le 10^6 5555

Translated by ChatGPT 5