#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(x) x.begin(), x.end()

using namespace std;
typedef pair<int,int> pii;

const int INF = 1e9+7;

int main(){
	int n, x[500005];
	cin >> n;
	rep(i,n) cin >> x[i];

	set<pii> st;
	st.emplace(-1, -1);
	st.emplace(INF, INF+1);
	int f = INF;
	rep(i,n){
		//for(auto t: st) cout << "(" << t.first << "," << t.second << ")"; cout << endl;
		if( f <= x[i] ){
			cout << "No" << endl;
			continue;
		}
		auto it = st.lower_bound( pii(x[i], 0) );
		if( it->first == x[i] ){
			if( it->first == 1 ){
				int sc = it->second;
				it++;
				if( sc == x[i]+1 && it->second > INF ){
					cout << "Yes" << endl;
					f = 1;
				}else{
					cout << "No" << endl;
				}
				continue;
			}else{
				cout << "Yes" << endl;
			}
			int fs = it->first+1;
			int sc = it->second;
			st.erase(it);
			if( fs != sc ) st.emplace(fs, sc);
			auto pit = st.lower_bound( pii(x[i], 0) ); pit--;
			if( pit->second == x[i]-1 ){
				int fs = pit->first;
				int sc = pit->second+1;
				st.erase(pit);
				st.emplace( fs, sc );
			}else{
				st.emplace( x[i]-1, x[i] );
			}
			continue;
		}
		it--;
		if( it->second == x[i] ){
			cout << "Yes" << endl;
			int fs = it->first;
			int sc = it->second+1;
			st.erase(it);
			auto nit = st.lower_bound( pii(sc, 0) );
			if( nit->first == sc ){
				sc = nit->second;
				st.erase(nit);
			}
			st.emplace( fs, sc );
		}else if( it->second > x[i] ){
			if( it->first == 1 ){
				int fs = it->first;
				int sc = it->second;
				it++;
				if( sc == x[i]+1 && it->second > INF ){
					cout << "Yes" << endl;
					f = fs;
				}else{
					cout << "No" << endl;
				}
				continue;
			}else{
				cout << "Yes" << endl;
			}
			int tmp = it->first;
			int fs = x[i]+1;
			int sc = it->second;
			st.erase(it);
			if( fs != sc ) st.emplace( fs, sc );
			fs = tmp-1;
			sc = tmp;
			auto pit = st.lower_bound( pii(fs, 0) ); pit--;
			if( pit->second == fs ){
				fs = pit->first;
				st.erase(pit);
			}
			st.emplace( fs, sc );
		}else{
			cout << "Yes" << endl;
			it++;
			int tmp = x[i]+1;
			if( tmp == it->first ){
				tmp = it->second;
				st.erase(it);
			}
			st.emplace( x[i], tmp );
		}
	}
	return 0;
}
### Prompt

Please create a solution in Cpp to the following problem:

Example

Input

6
2
3
1
1
4
2


Output

Yes
Yes
Yes
No
Yes
No

### Response

```cpp
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(x) x.begin(), x.end()

using namespace std;
typedef pair<int,int> pii;

const int INF = 1e9+7;

int main(){
	int n, x[500005];
	cin >> n;
	rep(i,n) cin >> x[i];

	set<pii> st;
	st.emplace(-1, -1);
	st.emplace(INF, INF+1);
	int f = INF;
	rep(i,n){
		//for(auto t: st) cout << "(" << t.first << "," << t.second << ")"; cout << endl;
		if( f <= x[i] ){
			cout << "No" << endl;
			continue;
		}
		auto it = st.lower_bound( pii(x[i], 0) );
		if( it->first == x[i] ){
			if( it->first == 1 ){
				int sc = it->second;
				it++;
				if( sc == x[i]+1 && it->second > INF ){
					cout << "Yes" << endl;
					f = 1;
				}else{
					cout << "No" << endl;
				}
				continue;
			}else{
				cout << "Yes" << endl;
			}
			int fs = it->first+1;
			int sc = it->second;
			st.erase(it);
			if( fs != sc ) st.emplace(fs, sc);
			auto pit = st.lower_bound( pii(x[i], 0) ); pit--;
			if( pit->second == x[i]-1 ){
				int fs = pit->first;
				int sc = pit->second+1;
				st.erase(pit);
				st.emplace( fs, sc );
			}else{
				st.emplace( x[i]-1, x[i] );
			}
			continue;
		}
		it--;
		if( it->second == x[i] ){
			cout << "Yes" << endl;
			int fs = it->first;
			int sc = it->second+1;
			st.erase(it);
			auto nit = st.lower_bound( pii(sc, 0) );
			if( nit->first == sc ){
				sc = nit->second;
				st.erase(nit);
			}
			st.emplace( fs, sc );
		}else if( it->second > x[i] ){
			if( it->first == 1 ){
				int fs = it->first;
				int sc = it->second;
				it++;
				if( sc == x[i]+1 && it->second > INF ){
					cout << "Yes" << endl;
					f = fs;
				}else{
					cout << "No" << endl;
				}
				continue;
			}else{
				cout << "Yes" << endl;
			}
			int tmp = it->first;
			int fs = x[i]+1;
			int sc = it->second;
			st.erase(it);
			if( fs != sc ) st.emplace( fs, sc );
			fs = tmp-1;
			sc = tmp;
			auto pit = st.lower_bound( pii(fs, 0) ); pit--;
			if( pit->second == fs ){
				fs = pit->first;
				st.erase(pit);
			}
			st.emplace( fs, sc );
		}else{
			cout << "Yes" << endl;
			it++;
			int tmp = x[i]+1;
			if( tmp == it->first ){
				tmp = it->second;
				st.erase(it);
			}
			st.emplace( x[i], tmp );
		}
	}
	return 0;
}
```