#include <bits/stdc++.h>
using namespace std;

template <typename T>
class SegmentTree {
	using func_t = function<T(T, T)>;
	const int n;
	const T id;
	func_t merge;
	vector<T> data;
	int size(int n) {
		int res;
		for (res = 1; res < n; res <<= 1);
		return res;
	}
	T sub(int l, int r, int node, int lb, int ub) {
		if (ub <= l || r <= lb) return id;
		if (l <= lb && ub <= r) return data[node];
		return merge(sub(l, r, node * 2, lb, (lb + ub) / 2), sub(l, r, node * 2 + 1, (lb + ub) / 2, ub));
	}
public:
	SegmentTree(int n_, T id_, func_t merge_) :
		n(size(n_)), id(id_), merge(merge_), data(size(n_) * 2, id_) {}
	void Update(int p, T val) {
		p += n;
		data[p] = val;
		while (p >>= 1) data[p] = merge(data[p * 2], data[p * 2 + 1]);
	}
	void Add(int p, T val) {
		p += n;
		data[p] += val;
		while (p >>= 1) data[p] = merge(data[p * 2], data[p * 2 + 1]);
	}
	T Find(int i) {
		return data[i + n];
	}
	T Find(int l, int r) {
		return sub(l, r + 1, 1, 0, n);
	}
};

int main()
{
	cin.sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> x(n), xs(1);
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	xs.reserve(n * 32);
	for (int i = 0; i < n; i++) {
		for (int j = max(1, x[i] - 32); j <= x[i] + 1; j++) {
			xs.push_back(j);
		}
	}
	sort(xs.begin(), xs.end());
	xs.erase(unique(xs.begin(), xs.end()), xs.end());
	SegmentTree<int> st((int)xs.size(), 0, [](int l, int r) { return l + r; });
	for (int i = 0; i < n; i++) {
		int id = lower_bound(xs.begin(), xs.end(), x[i]) - xs.begin();
		if (id != x[i]) {
			puts("Yes");
			st.Add(id, 1);
		}
		else if (st.Find(0) == 0 && (st.Find(id) == 0 || st.Find(1, id) < id || st.Find(id + 1, (int)xs.size() - 1) == 0)) {
			puts("Yes");
			while (st.Find(id)) {
				st.Update(id, 0);
				id--;
			}
			st.Add(id, 1);
		}
		else {
			puts("No");
		}
	}
	return 0;
}
### Prompt

Please provide a Cpp coded solution to the problem described below:

Example

Input

6
2
3
1
1
4
2


Output

Yes
Yes
Yes
No
Yes
No

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;

template <typename T>
class SegmentTree {
	using func_t = function<T(T, T)>;
	const int n;
	const T id;
	func_t merge;
	vector<T> data;
	int size(int n) {
		int res;
		for (res = 1; res < n; res <<= 1);
		return res;
	}
	T sub(int l, int r, int node, int lb, int ub) {
		if (ub <= l || r <= lb) return id;
		if (l <= lb && ub <= r) return data[node];
		return merge(sub(l, r, node * 2, lb, (lb + ub) / 2), sub(l, r, node * 2 + 1, (lb + ub) / 2, ub));
	}
public:
	SegmentTree(int n_, T id_, func_t merge_) :
		n(size(n_)), id(id_), merge(merge_), data(size(n_) * 2, id_) {}
	void Update(int p, T val) {
		p += n;
		data[p] = val;
		while (p >>= 1) data[p] = merge(data[p * 2], data[p * 2 + 1]);
	}
	void Add(int p, T val) {
		p += n;
		data[p] += val;
		while (p >>= 1) data[p] = merge(data[p * 2], data[p * 2 + 1]);
	}
	T Find(int i) {
		return data[i + n];
	}
	T Find(int l, int r) {
		return sub(l, r + 1, 1, 0, n);
	}
};

int main()
{
	cin.sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> x(n), xs(1);
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	xs.reserve(n * 32);
	for (int i = 0; i < n; i++) {
		for (int j = max(1, x[i] - 32); j <= x[i] + 1; j++) {
			xs.push_back(j);
		}
	}
	sort(xs.begin(), xs.end());
	xs.erase(unique(xs.begin(), xs.end()), xs.end());
	SegmentTree<int> st((int)xs.size(), 0, [](int l, int r) { return l + r; });
	for (int i = 0; i < n; i++) {
		int id = lower_bound(xs.begin(), xs.end(), x[i]) - xs.begin();
		if (id != x[i]) {
			puts("Yes");
			st.Add(id, 1);
		}
		else if (st.Find(0) == 0 && (st.Find(id) == 0 || st.Find(1, id) < id || st.Find(id + 1, (int)xs.size() - 1) == 0)) {
			puts("Yes");
			while (st.Find(id)) {
				st.Update(id, 0);
				id--;
			}
			st.Add(id, 1);
		}
		else {
			puts("No");
		}
	}
	return 0;
}
```