#P11282. 「GFOI Round 2」Colors

    ID: 10650 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>洛谷原创O2优化洛谷月赛分类讨论

「GFOI Round 2」Colors

Description

There are nn balls arranged in a row, numbered from 11 to nn from left to right. Initially, each ball is red. The initial weight of the ii-th ball is pip_i. It is guaranteed that n\bm{n} is an odd number and that p\bm{p} is a permutation of 1n\bm{1 \sim n}.

You need to perform exactly n12\frac{n - 1}{2} operations. In one operation, you must:

  • Choose a red ball ii such that there is at least one red ball in the range 1i11 \sim i - 1 and at least one red ball in the range i+1ni + 1 \sim n.
  • Let jj be the largest integer such that j<ij < i and the ball at position jj is red, and let kk be the smallest integer such that k>ik > i and the ball at position kk is red. You will paint both balls ii and kk blue.
  • Then, perform exactly one of the following two operations:
    • Modify pjp_j (the weight of ball jj) to max(pi,pj,pk)\max(p_i, p_j, p_k);
    • Modify pjp_j (the weight of ball jj) to min(pi,pj,pk)\min(p_i, p_j, p_k).

After performing n12\frac{n - 1}{2} operations, there will be exactly one red ball left.

You need to determine for each positive integer xx in the range 11 to nn whether it is possible to perform the operations in such a way that the weight of the remaining red ball is xx.

Input Format

This problem has multiple test cases in a single test.

The first line contains a positive integer TT, indicating the number of test cases.

For each test case:

  • The first line contains a positive integer nn.
  • The second line contains nn positive integers p1,p2,,pnp_1, p_2, \ldots, p_n.

Output Format

For each test case, output a line containing a 0101 string. For each positive integer ii in the range 1n1 \sim n, if it is possible to perform the operations in such a way that the weight of the remaining red ball is ii, then the ii-th position of this 0101 string will be 11; otherwise, it will be 00.

4
3
3 2 1
5
1 3 5 2 4
5
5 4 3 1 2
9
4 7 3 6 1 2 5 8 9
101
11111
11101
111111101

Hint

Sample Explanation

For the first test case, the initial state of the balls (color and weight) is 3 2 1\color{red}{3\ 2\ 1}.

You need to perform 11 operation. In this operation, you can only choose ball 22 and paint both balls 22 and 33 blue.

  • If you choose to modify p1p_1 to max(p1,p2,p3)\max(p_1, p_2, p_3), then after the operation, the state of the balls will be 3 2 1\color{red}{3}\ \color{blue}{2\ 1}, and the weight of the remaining red ball will be 33;
  • If you choose to modify p1p_1 to min(p1,p2,p3)\min(p_1, p_2, p_3), then after the operation, the state of the balls will be 1 2 1\color{red}{1}\ \color{blue}{2\ 1}, and the weight of the remaining red ball will be 11.

Thus, you will output a 0101 string that has 11s at the 11st and 33rd positions, and 00s in the other positions.

For the second test case, it can be easily proven that the weight of the remaining red ball can take all positive integers from 11 to nn. Here is an example of a sequence of operations that results in the remaining red ball having a weight of 22:

  • The initial state of the balls is 1 3 5 2 4\color{red}{1\ 3\ 5\ 2\ 4}.
  • Choose ball 22, paint both balls 22 and 33 blue, and set p1p_1 to max(p1,p2,p3)=5\max(p_1, p_2, p_3) = 5. After this operation, the state of the balls becomes $\color{red}{5}\ \color{blue}{3\ 5}\ \color{red}{2\ 4}$.
  • Choose ball 44, paint both balls 44 and 55 blue, and set p1p_1 to min(p1,p4,p5)=2\min(p_1, p_4, p_5) = 2. After this operation, the state of the balls becomes 2 3 5 2 4\color{red}{2}\ \color{blue}{3\ 5\ 2\ 4}.

Subtasks and Constraints

Subtask ID nn \le n\sum n \le Special Properties Score
11 55 10410^4 No 1616
22 1919 1919
33 9999 10610^6
44 106110^6 - 1 A 33
55 No 4343
  • Special Property A: pi=ip_i = i.

For all tests, it is guaranteed that:

  • 1T1051 \le T \le 10^5;
  • 3n10613 \le n \le 10^6 - 1 and nn is an odd number;
  • n106\sum n \le 10^6;
  • pp is a permutation of 1n1 \sim n.