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;
  long long read() {
    long long x = 0;
    bool f = 0;
    char ch = getchar();
    while (!isdigit(ch)) f |= ch == '-', ch = getchar();
    while (isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
    return f ? -x : x;
  }
  const int L = 1e7 + 10;
  const int N = 1e5 + 10;
  int n, m, val[L], ndn, ch[L][2], op[N], fa[L];
  long long x[N], y[N];
  bool ans[N];
  vector<pair<int, int> > G[N];
  long long tot;
  inline int newd(int v) { return val[++ndn] = v, ndn; }
  inline void pd(int x) {
    ch[x][0] = ch[x][0] ? ch[x][0] : newd(val[x]);
    ch[x][1] = ch[x][1] ? ch[x][1] : newd(val[x]);
    val[x] = 0;
  }
  void insert(int o, long long xl, long long xr, int v, long long l = 0,
              long long r = tot) {
    if (xl == l && xr == r) return val[o] = v, void();
    pd(o);
    long long mid = l + r >> 1;
    if (xr <= mid)
      insert(ch[o][0], xl, xr, v, l, mid);
    else if (xl > mid)
      insert(ch[o][1], xl, xr, v, mid + 1, r);
    else
      insert(ch[o][0], xl, mid, v, l, mid),
          insert(ch[o][1], mid + 1, xr, v, mid + 1, r);
  }
  void solve(int x, int y) {
    if (val[x] && val[y]) return G[min(val[x], val[y])].push_back({x, y}), void();
    if (val[x]) return solve(x, ch[y][0]), solve(x, ch[y][1]), void();
    if (val[y]) return solve(ch[x][0], y), solve(ch[x][1], y), void();
    return solve(ch[x][0], ch[y][0]), solve(ch[x][1], ch[y][1]);
  }
  int query(int o, long long pos, long long l = 0, long long r = tot) {
    if (val[o]) return o;
    long long mid = l + r >> 1;
    if (pos <= mid)
      return query(ch[o][0], pos, l, mid);
    else
      return query(ch[o][1], pos, mid + 1, r);
  }
  inline int gf(int x) { return fa[x] == x ? x : fa[x] = gf(fa[x]); }
  inline void merge(int x, int y) {
    x = gf(x);
    y = gf(y);
    fa[x] = y;
  }
  int main() {
    n = read(), m = read();
    tot = 1ll << n;
    tot--;
    for (int i = (1); i <= (m); i++) {
      static char s[7];
      scanf("%s", s);
      if (s[0] == 'a')
        op[i] = 1;
      else
        op[i] = 0;
      x[i] = read(), y[i] = read();
    }
    newd(m + 1);
    for (int i = (1); i <= (m); i++)
      if (op[i] == 0) insert(1, x[i], y[i], i);
    for (int x = (1); x <= (ndn); x++)
      if (ch[x][0] && ch[x][1]) solve(ch[x][0], ch[x][1]);
    for (int i = (1); i <= (ndn); i++) fa[i] = i;
    for (int i = (m); i >= (1); i--) {
      for (auto d : G[i + 1]) merge(d.first, d.second);
      if (op[i]) {
        ans[i] = gf(query(1, x[i])) == gf(query(1, y[i]));
      }
    }
    for (int i = (1); i <= (m); i++)
      if (op[i]) printf("%d\n", ans[i]);
    return 0;
  }
  