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 f[5000000];
  int F(int x) { return f[x] == x ? x : f[x] = F(f[x]); }
  long long N;
  int n, m;
  bool ans[50004];
  int op[50004], tot = 1;
  long long l[50004], r[50004];
  int s[2][5000000], rec[5000000];
  vector<pair<int, int> > g[50004];
  bool leaf(int x) { return !s[0][x] && !s[1][x]; }
  void ins(long long l, long long r, int id, long long a, long long b, int t) {
    if (r < a || b < l) return;
    if (a <= l && r <= b) {
      rec[id] = t;
      return;
    }
    long long mid = (l + r) >> 1;
    if (!s[0][id]) s[0][id] = ++tot, rec[s[0][id]] = m + 1;
    ins(l, mid, s[0][id], a, b, t);
    if (!s[1][id]) s[1][id] = ++tot, rec[s[1][id]] = m + 1;
    ins(mid + 1, r, s[1][id], a, b, t);
  }
  void merge(int x, int y) {
    if (leaf(x) && leaf(y)) {
      int p = min(rec[x], rec[y]);
      if (p == m + 1)
        f[F(x)] = F(y);
      else
        g[p].push_back(make_pair(x, y));
    } else if (leaf(x))
      merge(x, s[0][y]), merge(x, s[1][y]);
    else if (leaf(y))
      merge(s[0][x], y), merge(s[1][x], y);
    else
      merge(s[0][x], s[0][y]), merge(s[1][x], s[1][y]);
  }
  int findf(long long l, long long r, int id, long long p) {
    if (leaf(id)) return id;
    long long mid = (l + r) >> 1;
    if (p <= mid) return findf(l, mid, s[0][id], p);
    return findf(mid + 1, r, s[1][id], p);
  }
  int main() {
    scanf("%d%d", &n, &m), N = (1ll << n);
    for (int i = 1; i <= m; i++) {
      char buf[10];
      scanf("%s%I64d%I64d", buf, &l[i], &r[i]);
      if (*buf == 'a')
        op[i] = 1;
      else
        ins(0, N - 1, 1, l[i], r[i], i);
    }
    for (int i = 1; i <= tot; i++) f[i] = i;
    for (int i = 1; i <= tot; i++)
      if (!leaf(i)) merge(s[0][i], s[1][i]);
    for (int i = m; i; i--) {
      for (auto x : g[i]) f[F(x.first)] = F(x.second);
      if (op[i] == 1)
        ans[i] = F(findf(0, N - 1, 1, l[i])) == F(findf(0, N - 1, 1, r[i]));
    }
    for (int i = 1; i <= m; i++)
      if (op[i] == 1) putchar('0' + ans[i]), puts("");
  }
  