description: <image>
  
  As mentioned previously William really likes playing video games. In one of his favorite games, the player character is in a universe where every planet is designated by a binary number from 0 to 2^n - 1. On each planet, there are gates that allow the player to move from planet i to planet j if the binary representations of i and j differ in exactly one bit.
  
  William wants to test you and see how you can handle processing the following queries in this game universe:
  
    * Destroy planets with numbers from l to r inclusively. These planets cannot be moved to anymore.
    * Figure out if it is possible to reach planet b from planet a using some number of planetary gates. It is guaranteed that the planets a and b are not destroyed. 
  
  Input
  
  The first line contains two integers n, m (1 ≤ n ≤ 50, 1 ≤ m ≤ 5 ⋅ 10^4), which are the number of bits in binary representation of each planets' designation and the number of queries, respectively.
  
  Each of the next m lines contains a query of two types:
  
  block l r — query for destruction of planets with numbers from l to r inclusively (0 ≤ l ≤ r < 2^n). It's guaranteed that no planet will be destroyed twice.
  
  ask a b — query for reachability between planets a and b (0 ≤ a, b < 2^n). It's guaranteed that planets a and b hasn't been destroyed yet.
  
  Output
  
  For each query of type ask you must output "1" in a new line, if it is possible to reach planet b from planet a and "0" otherwise (without quotation marks).
  
  Examples
  
  Input
  
  
  3 3
  ask 0 7
  block 3 6
  ask 0 7
  
  
  Output
  
  
  1
  0
  
  
  Input
  
  
  6 10
  block 12 26
  ask 44 63
  block 32 46
  ask 1 54
  block 27 30
  ask 10 31
  ask 11 31
  ask 49 31
  block 31 31
  ask 2 51
  
  
  Output
  
  
  1
  1
  0
  0
  1
  0
  
  Note
  
  The first example test can be visualized in the following way:
  
  <image>
  
  Response to a query ask 0 7 is positive.
  
  Next after query block 3 6 the graph will look the following way (destroyed vertices are highlighted):
  
  <image>
  
  Response to a query ask 0 7 is negative, since any path from vertex 0 to vertex 7 must go through one of the destroyed vertices.
solution: #include <bits/stdc++.h>
  using namespace std;
  int n, m, k = 0;
  long long b[200010];
  int fa[200010], ans[50010];
  vector<int> E[200010];
  bool ban[200010];
  char s[10];
  struct ask {
    int ty;
    long long l, r;
  } q[50010];
  int find(int u) { return u == fa[u] ? u : fa[u] = find(fa[u]); }
  void merge(int u, int v) { u = find(u), v = find(v), fa[u] = v; }
  void ins(int u) {
    for (int v : E[u])
      if (!ban[v]) merge(u, v);
  }
  int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) scanf("%d", &n);
    for (int i = 1; i <= m; i++) {
      scanf("%s%lld%lld", s + 1, &q[i].l, &q[i].r);
      q[i].ty = s[1] == 'a';
      if (!q[i].ty) b[++k] = q[i].l, b[++k] = q[i].r + 1;
    }
    b[++k] = 1ll << n, b[++k] = 0;
    sort(b + 1, b + k + 1);
    int o = k;
    for (int i = 1; i < o; i++) {
      long long l = b[i], r = b[i + 1] - 1,
                x = 1ll << (63 - __builtin_clzll(l ^ r));
      if (l >= r) continue;
      b[++k] = ((l / x) * x) | x;
    }
    sort(b + 1, b + k + 1);
    k = unique(b + 1, b + k + 1) - b - 2;
    for (int i = 0; i < n; i++)
      for (int p = 0; p < 2; p++)
        for (int j = 1, l = 1; j <= k; j++) {
          if (((b[j] >> i) & 1) == p) {
            while ((b[j] ^ (1ll << i)) >= b[l + 1]) l++;
            if (l != j) E[l].push_back(j), E[j].push_back(l);
          }
        }
    for (int i = 1; i <= m; i++) {
      q[i].l = upper_bound(b + 1, b + k + 1, q[i].l) - b - 1;
      q[i].r = upper_bound(b + 1, b + k + 1, q[i].r) - b - 1;
      if (!q[i].ty)
        for (int j = q[i].l; j <= q[i].r; j++) ban[j] = 1;
    }
    iota(fa + 1, fa + k + 1, 1);
    for (int i = 1; i <= k; i++)
      if (!ban[i]) ins(i);
    for (int i = m; i >= 1; i--) {
      if (!q[i].ty)
        for (int j = q[i].l; j <= q[i].r; j++) ban[j] = 0, ins(j);
      else
        ans[i] = find(q[i].l) == find(q[i].r);
    }
    for (int i = 1; i <= m; i++)
      if (q[i].ty) printf("%d\n", ans[i]);
  }
  