CF2040B.Paint a Strip

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Paint a Strip

You have an array of zeros a1,a2,,ana_1, a_2, \ldots, a_n of length nn.

You can perform two types of operations on it:

  1. Choose an index ii such that 1in1 \le i \le n and ai=0a_i = 0, and assign 11 to aia_i;
  2. Choose a pair of indices ll and rr such that 1lrn1 \le l \le r \le n, al=1a_l = 1, ar=1a_r = 1, $a_l + \ldots + a_r \ge \lceil\frac{r - l + 1}{2}\rceil$, and assign 11 to aia_i for all lirl \le i \le r.

What is the minimum number of operations of the first type needed to make all elements of the array equal to one?

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1041 \le t \le 10^4). The description of the test cases follows.

The only line of each test case contains one integer nn (1n1051 \le n \le 10^5) — the length of the array.

Note that there is no limit on the sum of nn over all test cases.

Output

For each test case, print one integer — the minimum number of needed operations of first type.

Note

In the first test case, you can perform an operation of the 11st type with i=1i = 1.

In the second test case, you can perform the following sequence of operations:

  1. Operation of 11st type, i=1i = 1. After performing this operation, the array will look like this: [1,0][1, 0].
  2. Operation of 11st type, i=2i = 2. After performing this operation, the array will look like this: [1,1][1, 1].

The sequence of operations in the second test case

In the third test case, you can perform the following sequence of operations:

  1. Operation of 11st type, i=1i = 1. After performing this operation, the array will look like this: [1,0,0,0][1, 0, 0, 0].
  2. Operation of 11st type, i=4i = 4. After performing this operation, the array will look like this: [1,0,0,1][1, 0, 0, 1].
  3. Operation of 22nd type, l=1l = 1, r=4r = 4. On this segment, al++ar=a1+a2+a3+a4=2a_l + \ldots + a_r = a_1 + a_2 + a_3 + a_4 = 2, which is not less than rl+12=2\lceil\frac{r - l + 1}{2}\rceil = 2. After performing this operation, the array will look like this: [1,1,1,1][1, 1, 1, 1].

The sequence of operations in the third test case

Samples

4
1
2
4
20
1
2
2
4

在线编程 IDE

建议全屏模式获得最佳体验