Problem:
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Problem G
Placing Medals on a Binary Tree

You have drawn a chart of a perfect binary tree, like one shown in Figure G.1. The figure shows a finite tree, but, if needed, you can add more nodes beneath the leaves, making the tree arbitrarily deeper.

Figure G.1. A Perfect Binary Tree Chart

Tree nodes are associated with their depths, defined recursively. The root has the depth of zero, and the child nodes of a node of depth d have their depths $d + 1$.

You also have a pile of a certain number of medals, each engraved with some number. You want to know whether the medals can be placed on the tree chart satisfying the following conditions.

A medal engraved with $d$ should be on a node of depth $d$.

One tree node can accommodate at most one medal.

The path to the root from a node with a medal should not pass through another node with a medal.

You have to place medals satisfying the above conditions, one by one, starting from the top of the pile down to its bottom. If there exists no placement of a medal satisfying the conditions, you have to throw it away and simply proceed to the next medal.

You may have choices to place medals on different nodes. You want to find the best placement. When there are two or more placements satisfying the rule, one that places a medal upper in the pile is better. For example, when there are two placements of four medal, one that places only the top and the 2nd medal, and the other that places the top, the 3rd, and the 4th medal, the former is better.

In Sample Input 1, you have a pile of six medals engraved with 2, 3, 1, 1, 4, and 2 again respectively, from top to bottom.

The first medal engraved with 2 can be placed, as shown in Figure G.2 (A).

Then the second medal engraved with 3 may be placed , as shown in Figure G.2 (B).

The third medal engraved with 1 cannot be placed if the second medal were placed as stated above, because both of the two nodes of depth 1 are along the path to the root from nodes already with a medal. Replacing the second medal satisfying the placement conditions, however, enables a placement shown in Figure G.2 (C).

The fourth medal, again engraved with 1, cannot be placed with any replacements of the three medals already placed satisfying the conditions. This medal is thus thrown away.

The fifth medal engraved with 4 can be placed as shown in of Figure G.2 (D).

The last medal engraved with 2 cannot be placed on any of the nodes with whatever replacements.

Figure G.2. Medal Placements

Input

The input consists of a single test case in the format below.

$n$

$x_1$

.

.

.

$x_n$

The first line has $n$, an integer representing the number of medals ($1 \leq n \leq 5 \times 10^5$). The following $n$ lines represent the positive integers engraved on the medals. The $i$-th line of which has an integer $x_i$ ($1 \leq x_i \leq 10^9$) engraved on the $i$-th medal of the pile from the top.

Output

When the best placement is chosen, for each i from 1 through n, output Yes in a line if the i-th medal is placed; otherwise, output No in a line.

Sample Input 1

6
2
3
1
1
4
2

Sample Output 1

Yes
Yes
Yes
No
Yes
No

Sample Input 2

10
4
4
4
4
4
4
4
4
1
4

Sample Output 2

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No

Solution in C (judge verdict: Accepted)

// AOJ 1373: Placing Medals on a Binary Tree
// 2018.1.7 bal4u@uu

#include <stdio.h>

#define N 500000
int bit[500003];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

void add(int i, int v)
{
    while (i <= N) bit[i] += v, i |= i+1;
}
 
int sum(int i)
{
    int s = 0;
    while (i) s += bit[i-1], i &= i-1;
    return s;
}

#define sub(a,b) (sum(a)-sum(b))

int main()
{
	int n, i, x, k, ans;

	k = 0;
	n = in(); while (n--) {
		x = in();
		ans = 1;
		if (sub(1, 0) == 1) ans = 0;
		else if (x >= N) k = 1;
		else if (sub(x+1, 0) < x) {
			for (i = x; sub(i+1, i); i--) add(i, -1); add(i, 1);
		} else if (sub(x+1, 0) == x) {
			if (k || sub(N, x+1)) ans = 0;
			else { for (i = 1; i <= x; i++) add(i, -1); add(0, 1); }
		}
		puts(ans? "Yes": "No");
	}
	return 0;
}