#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>
#include <iostream>

using namespace std;
typedef long long ll;

#define SIZE 500010

struct RMQ{
  int segn2;
  vector<int> data;

  RMQ(int n){
    for(segn2=1; segn2<n; segn2*=2);
    data.assign(segn2*2, 0);
  }

  int query(int a, int b, int l = 0, int r = -1, int k = 0){
    if(r == -1) r = segn2;
    if(a <= l && r <= b) return data[k];
    if(r <= a || b <= l) return 1000000000;
    return min(query(a, b, l, (l+r)/2, k*2+1), query(a, b, (l+r)/2, r, k*2+2));
  }

  void set(int k, int x){
    k += segn2-1;
    data[k] = x;
    while(k > 0){
      k = (k-1)/2;
      data[k] = min(data[k*2+1], data[k*2+2]);
    }
  };
};

struct RMaxQ{
  int segn2;
  vector<int> data;

  RMaxQ(int n){
    for(segn2=1; segn2<n; segn2*=2);
    data.assign(segn2*2, 0);
  }

  int query(int a, int b, int l = 0, int r = -1, int k = 0){
    if(r == -1) r = segn2;
    if(a <= l && r <= b) return data[k];
    if(r <= a || b <= l) return 0;
    return max(query(a, b, l, (l+r)/2, k*2+1), query(a, b, (l+r)/2, r, k*2+2));
  }

  void set(int k, int x){
    k += segn2-1;
    data[k] = x;
    while(k > 0){
      k = (k-1)/2;
      data[k] = max(data[k*2+1], data[k*2+2]);
    }
  };
};

int n, d[SIZE], d2[SIZE];
map<int,int> counter, dict;

int main(){

  scanf("%d", &n);

  for(int i=0;i<n;i++){
    scanf("%d", d+i);
    d2[i] = d[i];
    counter[d[i]]++;
  }

  sort(d2, d2+n, greater<int>());
  
  vector<int> vec;

  int t = 0;
  int cur = d2[n-1];
  
  for(int i=0;i<n;i++){
    if(i != 0 && d2[i-1] == d2[i]){
      t++;
    }else{
      vec.push_back(d2[i]);
      cur = d2[i];
      t++;
    }

    while(cur > 0 && (i == n-1 || cur-1 > d2[i+1]) && t > 2){
      cur--;
      t /= 2;
      vec.push_back(cur);
    }
  }

  if(vec[vec.size()-1] != 0) vec.push_back(0);
  
  reverse(vec.begin(), vec.end());
  
  for(int i=0;i<vec.size();i++){
    //cerr << vec[i] << endl;
    dict[vec[i]] = i; 
  }

  vector<int> arr(vec.size());
  RMQ rmq(vec.size());
  RMaxQ rmaxq(vec.size());
  
  for(int i=0;i<n;i++){
    int p = dict[d[i]];

    //cerr << rmaxq.query(p+1, vec.size()) << endl;
    //cerr << arr[0] << endl;
    
    if((!arr[0] && rmq.query(1, p+1) == 0) ||
       (!arr[0] && rmaxq.query(p+1, vec.size()) == 0)){
      puts("Yes");
    }else{
      puts("No");
      continue;
    }

    arr[p]++;
    rmq.set(p, arr[p]);
    rmaxq.set(p, arr[p]);

    while(arr[p] >= 2){
      arr[p--] -= 2;
      arr[p]++;
      rmq.set(p+1, arr[p+1]);
      rmaxq.set(p+1, arr[p+1]);
      rmq.set(p, arr[p]);
      rmaxq.set(p, arr[p]);
    }
  }

  return 0;
}


### Prompt

In Cpp, your task is to solve the following problem:

Example

Input

6
2
3
1
1
4
2


Output

Yes
Yes
Yes
No
Yes
No

### Response

```cpp
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>
#include <iostream>

using namespace std;
typedef long long ll;

#define SIZE 500010

struct RMQ{
  int segn2;
  vector<int> data;

  RMQ(int n){
    for(segn2=1; segn2<n; segn2*=2);
    data.assign(segn2*2, 0);
  }

  int query(int a, int b, int l = 0, int r = -1, int k = 0){
    if(r == -1) r = segn2;
    if(a <= l && r <= b) return data[k];
    if(r <= a || b <= l) return 1000000000;
    return min(query(a, b, l, (l+r)/2, k*2+1), query(a, b, (l+r)/2, r, k*2+2));
  }

  void set(int k, int x){
    k += segn2-1;
    data[k] = x;
    while(k > 0){
      k = (k-1)/2;
      data[k] = min(data[k*2+1], data[k*2+2]);
    }
  };
};

struct RMaxQ{
  int segn2;
  vector<int> data;

  RMaxQ(int n){
    for(segn2=1; segn2<n; segn2*=2);
    data.assign(segn2*2, 0);
  }

  int query(int a, int b, int l = 0, int r = -1, int k = 0){
    if(r == -1) r = segn2;
    if(a <= l && r <= b) return data[k];
    if(r <= a || b <= l) return 0;
    return max(query(a, b, l, (l+r)/2, k*2+1), query(a, b, (l+r)/2, r, k*2+2));
  }

  void set(int k, int x){
    k += segn2-1;
    data[k] = x;
    while(k > 0){
      k = (k-1)/2;
      data[k] = max(data[k*2+1], data[k*2+2]);
    }
  };
};

int n, d[SIZE], d2[SIZE];
map<int,int> counter, dict;

int main(){

  scanf("%d", &n);

  for(int i=0;i<n;i++){
    scanf("%d", d+i);
    d2[i] = d[i];
    counter[d[i]]++;
  }

  sort(d2, d2+n, greater<int>());
  
  vector<int> vec;

  int t = 0;
  int cur = d2[n-1];
  
  for(int i=0;i<n;i++){
    if(i != 0 && d2[i-1] == d2[i]){
      t++;
    }else{
      vec.push_back(d2[i]);
      cur = d2[i];
      t++;
    }

    while(cur > 0 && (i == n-1 || cur-1 > d2[i+1]) && t > 2){
      cur--;
      t /= 2;
      vec.push_back(cur);
    }
  }

  if(vec[vec.size()-1] != 0) vec.push_back(0);
  
  reverse(vec.begin(), vec.end());
  
  for(int i=0;i<vec.size();i++){
    //cerr << vec[i] << endl;
    dict[vec[i]] = i; 
  }

  vector<int> arr(vec.size());
  RMQ rmq(vec.size());
  RMaxQ rmaxq(vec.size());
  
  for(int i=0;i<n;i++){
    int p = dict[d[i]];

    //cerr << rmaxq.query(p+1, vec.size()) << endl;
    //cerr << arr[0] << endl;
    
    if((!arr[0] && rmq.query(1, p+1) == 0) ||
       (!arr[0] && rmaxq.query(p+1, vec.size()) == 0)){
      puts("Yes");
    }else{
      puts("No");
      continue;
    }

    arr[p]++;
    rmq.set(p, arr[p]);
    rmaxq.set(p, arr[p]);

    while(arr[p] >= 2){
      arr[p--] -= 2;
      arr[p]++;
      rmq.set(p+1, arr[p+1]);
      rmaxq.set(p+1, arr[p+1]);
      rmq.set(p, arr[p]);
      rmaxq.set(p, arr[p]);
    }
  }

  return 0;
}


```