Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #define all(x) begin(x), end(x)
- using namespace std;
- using namespace __gnu_pbds;
- using ll = long long;
- template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
- void solve() {
- int n;
- cin >> n;
- bool flag = false;
- ordered_set<int> cur;
- for (int i = 0; i < n; ++i) {
- int x;
- cin >> x;
- if (flag) {
- cout << "No\n";
- continue;
- }
- auto it = cur.find(x);
- if (it == cur.end()) {
- cur.insert(x);
- cout << "Yes\n";
- continue;
- }
- if (cur.order_of_key(x) + 1 == x && cur.size() > x) {
- cout << "No\n";
- continue;
- }
- while (*it == x) {
- x--;
- if (it == cur.begin()) {
- cur.erase(it);
- break;
- } else {
- auto pre = *prev(it);
- cur.erase(it);
- it = cur.find(pre);
- }
- }
- flag = x == 0;
- cur.insert(x);
- cout << "Yes\n";
- }
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement