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 = 55555;
  int n, m, rt, tot, cnt, ty[M], ans[M], p[M * 100], ls[M * 100], rs[M * 100],
      a[M * 100], fa[M * 100];
  long long N = 1, ql[M], qr[M];
  vector<long long> v;
  vector<int> e[M * 100], g[M];
  void modify(int &x, long long L, long long R, long long l = 0,
              long long r = N - 1) {
    if (!x) x = ++tot;
    if (L <= l && r <= R) {
      a[x] = ++cnt;
      return;
    }
    long long mid = (l + r) >> 1;
    if (mid >= L) modify(ls[x], L, R, l, mid);
    if (mid < R) modify(rs[x], L, R, mid + 1, r);
  }
  void dfs(int k1, int k2, int d, int D) {
    if (d > D) {
      if (a[k1]) return;
      dfs(ls[k1], ls[k2], d - 1, D);
      dfs(rs[k1], rs[k2], d - 1, D);
      return;
    }
    if (d == D) {
      if (a[k1]) return;
      dfs(ls[k1], rs[k2], d - 1, D);
      return;
    }
    if (a[k1] && a[k2]) {
      e[a[k1]].push_back(a[k2]);
      e[a[k2]].push_back(a[k1]);
      return;
    }
    if (a[k1]) {
      dfs(k1, ls[k2], d - 1, D);
      dfs(k1, rs[k2], d - 1, D);
      return;
    }
    if (a[k2]) {
      dfs(ls[k1], k2, d - 1, D);
      dfs(rs[k1], k2, d - 1, D);
      return;
    }
    dfs(ls[k1], ls[k2], d - 1, D);
    dfs(rs[k1], rs[k2], d - 1, D);
  }
  void query(int k, long long L, long long R, int i, long long l = 0,
             long long r = N - 1) {
    if (L <= l && r <= R) {
      p[a[k]] = i;
      g[i].push_back(a[k]);
      return;
    }
    long long mid = (l + r) >> 1;
    if (L <= mid) query(ls[k], L, R, i, l, mid);
    if (mid < R) query(rs[k], L, R, i, mid + 1, r);
  }
  int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
  void ins(int x) {
    fa[x] = x;
    for (int i : e[x])
      if (fa[i]) fa[find(x)] = find(i);
  }
  int get(int k, long long x) {
    for (int i = n - 1; i >= 0; i--) {
      if ((x >> i) & 1)
        k = rs[k];
      else
        k = ls[k];
      if (a[k]) return a[k];
    }
  }
  signed main() {
    int i;
    cin >> n >> m;
    for (i = 1; i <= n; i++) N *= 2;
    for (i = 1; i <= m; i++) {
      string s;
      cin >> s >> ql[i] >> qr[i];
      if (s[0] == 'a')
        ty[i] = 1;
      else {
        v.push_back(ql[i] - 1);
        v.push_back(qr[i]);
      }
    }
    v.push_back(-1);
    v.push_back(N - 1);
    sort(v.begin(), v.end());
    v.resize(unique(v.begin(), v.end()) - v.begin());
    for (i = 1; i < v.size(); i++) modify(rt, v[i - 1] + 1, v[i]);
    for (i = 0; i < n; i++) dfs(rt, rt, n - 1, i);
    for (i = 1; i <= m; i++)
      if (!ty[i]) query(rt, ql[i], qr[i], i);
    for (i = 1; i <= cnt; i++)
      if (!p[i]) ins(i);
    for (i = m; i; i--)
      if (!ty[i])
        for (int l : g[i]) ins(l);
      else {
        ql[i] = get(rt, ql[i]);
        qr[i] = get(rt, qr[i]);
        if (find(ql[i]) == find(qr[i])) ans[i] = 1;
      }
    for (i = 1; i <= m; i++)
      if (ty[i]) printf("%d\n", ans[i]);
    return 0;
  }
  