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>
  long long n, m;
  long long que[50001][3], L[200010], top;
  std::vector<long long> con[200010];
  bool vis[200010], vis2[200010];
  char str[11];
  long long f(long long x) {
    if (!(x & (x - 1))) return x;
    return f(x & (x - 1));
  }
  long long fa[200010];
  long long find(long long x) { return fa[x] ? fa[x] = find(fa[x]) : x; }
  void add(long long x) {
    vis2[x] = 1;
    for (long long i = 0; i < con[x].size(); ++i) {
      if (!vis2[con[x][i]]) continue;
      long long u = find(x), v = find(con[x][i]);
      if (u != v) fa[u] = v;
    }
  }
  long long ans[50001], at;
  signed main() {
    scanf("%lld%lld", &n, &m);
    L[++top] = 0;
    for (long long i = 1; i <= m; ++i) {
      scanf("%s%lld%lld", str + 1, &que[i][1], &que[i][2]);
      que[i][0] = str[1] == 'b';
      if (que[i][0]) {
        L[++top] = que[i][1];
        L[++top] = que[i][2] + 1;
      }
    }
    std::sort(L + 1, L + top + 1);
    long long now = top;
    L[++top] = 1ll << n;
    for (long long i = 1; i <= now; ++i) {
      long long l = L[i], r = L[i + 1] - 1, x = f(l ^ r);
      if (l == r || (!(l & (x - 1)))) continue;
      L[++top] = (l ^ (l & (x - 1))) | x;
    }
    std::sort(L + 1, L + top + 1);
    --top;
    for (long long i = 0; i < n; ++i)
      for (long long j = 0; j < 2; ++j) {
        for (long long k = 1, now = 1; k <= top; ++k) {
          long long l = L[k], r = L[k + 1] - 1, v;
          if (((l >> i) & 1) == j)
            v = l;
          else
            v = r + 1;
          if (v <= r) {
            v ^= 1ll << i;
            while (v >= L[now + 1]) ++now;
            con[k].push_back(now);
            con[now].push_back(k);
          }
        }
      }
    for (long long i = m; i; --i)
      if (que[i][0]) {
        long long l = que[i][1], r = que[i][2] + 1;
        long long p = std::lower_bound(L + 1, L + top + 1, r) - L - 1;
        for (; p && L[p] >= l; --p) vis[p] = 1;
      }
    for (long long i = 1; i <= top; ++i)
      if (!vis[i]) add(i);
    for (long long i = m; i; --i)
      if (que[i][0]) {
        long long l = que[i][1], r = que[i][2] + 1;
        long long p = std::lower_bound(L + 1, L + top + 1, r) - L - 1;
        for (; p && L[p] >= l; --p) add(p);
      } else {
        long long a = std::upper_bound(L + 1, L + top + 1, que[i][1]) - L - 1,
                  b = std::upper_bound(L + 1, L + top + 1, que[i][2]) - L - 1;
        ans[++at] = find(a) == find(b);
      }
    for (long long i = at; i; --i) printf("%d\n", ans[i]);
  }
  