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;
  const int M = 1e5 + 5, N = 105;
  struct edge {
    int x, y;
  };
  vector<edge> e[M];
  namespace SGT {
  int lp[M * N], rp[M * N], tim[M * N], tot = 1;
  inline bool leaf(int rt) { return !lp[rt] && !rp[rt]; }
  inline void dn(int rt) {
    if (!lp[rt]) lp[rt] = ++tot;
    if (!rp[rt]) rp[rt] = ++tot;
    if (tim[rt]) tim[lp[rt]] = tim[rp[rt]] = tim[rt], tim[rt] = 0;
  }
  void update(int rt, long long l, long long r, long long ql, long long qr,
              int t) {
    if (ql <= l && r <= qr) return tim[rt] = t, void();
    dn(rt);
    long long mid = (l + r) >> 1;
    if (ql <= mid) update(lp[rt], l, mid, ql, qr, t);
    if (mid < qr) update(rp[rt], mid + 1, r, ql, qr, t);
  }
  void adde(int x, int y) {
    if (leaf(x) && leaf(y)) return e[min(tim[x], tim[y])].push_back({x, y});
    if (leaf(x)) return adde(x, lp[y]), adde(x, rp[y]);
    if (leaf(y)) return adde(lp[x], y), adde(rp[x], y);
    adde(lp[x], lp[y]), adde(rp[x], rp[y]);
  }
  int pos(int rt, long long l, long long r, long long p) {
    if (leaf(rt)) return rt;
    long long mid = (l + r) >> 1;
    return p <= mid ? pos(lp[rt], l, mid, p) : pos(rp[rt], mid + 1, r, p);
  }
  }  // namespace SGT
  struct quy {
    bool opt;
    long long l, r;
  } q[M];
  int n, m, fa[M * N];
  bool ans[M];
  char ch[10];
  int fd(int x) { return fa[x] == x ? x : fa[x] = fd(fa[x]); }
  inline void mge(int x, int y) {
    x = fd(x), y = fd(y);
    fa[x] = y;
  }
  int main() {
    scanf("%d%d", &n, &m);
    long long mx = 1ll << n;
    SGT::tim[1] = m + 1;
    for (int i = 1; i <= m; ++i) {
      long long x, y;
      scanf("%s%lld%lld", ch, &x, &y);
      if (ch[0] == 'a')
        q[i] = {1, x, y};
      else
        SGT::update(1, 0, mx - 1, x, y, i), q[i].opt = 0;
    }
    for (int i = 1; i <= SGT::tot; ++i) {
      if (!SGT::leaf(i)) SGT::adde(SGT::lp[i], SGT::rp[i]);
      fa[i] = i;
    }
    for (auto c : e[m + 1]) mge(c.x, c.y);
    for (int i = m; i; --i) {
      for (auto c : e[i]) mge(c.x, c.y);
      if (q[i].opt)
        ans[i] = (fd(SGT::pos(1, 0, mx - 1, q[i].l)) ==
                  fd(SGT::pos(1, 0, mx - 1, q[i].r)));
    }
    for (int i = 1; i <= m; ++i)
      if (q[i].opt) puts(ans[i] ? "1" : "0");
    return 0;
  }
  