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;
  template <typename T>
  inline void read(T &x) {
    x = 0;
    char c = getchar(), f = 0;
    for (; c < 48 || c > 57; c = getchar())
      if (!(c ^ 45)) f = 1;
    for (; c >= 48 && c <= 57; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
    f ? x = -x : x;
  }
  template <typename T, typename... L>
  inline void read(T &x, L &...l) {
    read(x), read(l...);
  }
  struct segm {
    int ls, rs, lz;
  } T[5000005];
  int tt, m;
  long long n;
  struct qwq {
    char ch[6];
    long long l, r;
  } q[50005];
  int fa[5000005];
  vector<pair<int, int> > e[5000005];
  char rs[50005];
  inline int getf(int x) { return fa[x] == x ? x : fa[x] = getf(fa[x]); }
  inline void mrg(int x, int y) {
    x = getf(x), y = getf(y);
    if (x ^ y) fa[x] = y;
  }
  inline char chk(int x, int y) { return getf(x) == getf(y); }
  inline void pushdw(int x) {
    int v = T[x].lz;
    if (!T[x].lz)
      return;
    else
      T[x].lz = 0;
    T[T[x].ls ? T[x].ls : T[x].ls = ++tt].lz = v;
    T[T[x].rs ? T[x].rs : T[x].rs = ++tt].lz = v;
  }
  inline void modif(int x, long long l, long long r, long long dl, long long dr,
                    int dv) {
    if (l > dr || dl > r)
      return;
    else if (dl <= l && r <= dr)
      return T[x].lz = dv, void();
    pushdw(x), modif(T[x].ls, l, (l + r) >> 1, dl, dr, dv),
        modif(T[x].rs, ((l + r) >> 1) + 1, r, dl, dr, dv);
  }
  inline void solve(int x, int y) {
    if (T[x].lz && T[y].lz)
      return e[min(T[x].lz, T[y].lz)].push_back(make_pair(x, y)), void();
    if (T[x].lz) return solve(x, T[y].ls), solve(x, T[y].rs);
    if (T[y].lz) return solve(T[x].ls, y), solve(T[x].rs, y);
    return solve(T[x].ls, T[y].ls), solve(T[x].rs, T[y].rs);
  }
  inline int fnd(int x, long long l, long long r, long long dw) {
    if (T[x].lz) return x;
    if (dw <= ((l + r) >> 1))
      return fnd(T[x].ls, l, (l + r) >> 1, dw);
    else
      return fnd(T[x].rs, ((l + r) >> 1) + 1, r, dw);
  }
  int main() {
    read(n, m), n = 1ll << n, n--, ++tt, T[1].lz = m + 1;
    for (int i = 1; i <= m; i++) scanf("%s", q[i].ch), read(q[i].l), read(q[i].r);
    for (int i = 1; i <= m; i++)
      if (*q[i].ch == 'b') modif(1, 0, n, q[i].l, q[i].r, i);
    for (int i = 1; i <= tt; i++)
      if (T[i].ls && T[i].rs) solve(T[i].ls, T[i].rs);
    for (int i = 1; i <= tt; i++) fa[i] = i;
    for (int i = m; i >= 1; i--) {
      for (auto x : e[i + 1]) mrg(x.first, x.second);
      if (*q[i].ch == 'a')
        rs[i] = chk(fnd(1, 0, n, q[i].l), fnd(1, 0, n, q[i].r));
    }
    for (int i = 1; i <= m; i++)
      if (*q[i].ch == 'a') printf("%d\n", rs[i]);
    return 0;
  }
  