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;
  struct dsu {
    vector<int> id;
    dsu(int n) { id = vector<int>(n, -1); }
    inline int par(int a) const { return id[a] >= 0 ? id[a] : a; }
    int find(int a) {
      while (id[a] >= 0) {
        id[a] = par(par(a));
        a = id[a];
      }
      return a;
    }
    bool unite(int a, int b) {
      a = find(a);
      b = find(b);
      if (a == b) return false;
      if (id[a] > id[b]) {
        swap(a, b);
      }
      id[a] += id[b];
      id[b] = a;
      return true;
    }
  };
  struct tr {
    long long a, b;
    int t;
  };
  bool intersect(long long a, long long b, long long c, long long d) {
    return b >= c && d >= a;
  }
  vector<pair<long long, long long>> vertices;
  vector<pair<int, int>> edges;
  vector<tr> blocks;
  int add(long long from, long long to) {
    vertices.emplace_back(from, to);
    return (int)vertices.size() - 1;
  }
  pair<int, int> boo(int depth, int idL, int idR, long long from, long long to) {
    if (idL > idR) {
      int id = add(from, to);
      return {id, id};
    } else if (idL == idR) {
      const tr &in = blocks[idL];
      if (in.a <= from && to <= in.b) {
        int id = add(from, to);
        return {id, id};
      } else if (!intersect(from, to, in.a, in.b)) {
        int id = add(from, to);
        return {id, id};
      }
    }
    long long mid = (from + to) / 2;
    vector<int> left, right;
    int leftId = idL - 1;
    int rightId = idR + 1;
    for (int id = idL; id <= idR; id++) {
      const tr &bl = blocks[id];
      if (intersect(bl.a, bl.b, from, mid)) {
        leftId = id;
      }
      if (intersect(bl.a, bl.b, mid + 1, to)) {
        if (rightId == idR + 1) {
          rightId = id;
        }
      }
    }
    const pair<int, int> lv = boo(depth - 1, idL, leftId, from, mid);
    const pair<int, int> rv = boo(depth - 1, rightId, idR, mid + 1, to);
    int pl = lv.first, pr = rv.first;
    while (pl <= lv.second && pr <= rv.second) {
      long long rL = vertices[pr].first ^ (1LL << depth);
      long long rR = vertices[pr].second ^ (1LL << depth);
      if (intersect(rL, rR, vertices[pl].first, vertices[pl].second)) {
        edges.emplace_back(pl, pr);
      }
      if (vertices[pl].second <= rR) {
        pl++;
      } else {
        pr++;
      }
    }
    return make_pair(lv.first, rv.second);
  }
  void foo() {
    int n, m;
    cin >> n >> m;
    vector<tr> queries;
    blocks.clear();
    for (int time = 0; time < m; time++) {
      string type;
      cin >> type;
      long long x, y;
      cin >> x >> y;
      if (type == "ask") {
        queries.push_back({x, y, time});
      } else {
        blocks.push_back({x, y, time});
      }
    }
    vertices.clear();
    edges.clear();
    sort(blocks.begin(), blocks.end(),
         [&](const tr &b1, const tr &b2) { return b1.a < b2.a; });
    boo(n - 1, 0, (int)blocks.size() - 1, 0, (1LL << n) - 1);
    const int N = vertices.size();
    const int M = edges.size();
    vector<vector<int>> time_edge(m + 1);
    vector<int> time_ver(N, m);
    int ptr = 0;
    for (int i = 0; i < N; i++) {
      while (ptr < (int)blocks.size() && blocks[ptr].b < vertices[i].first) {
        ptr++;
      }
      if (ptr == (int)blocks.size()) {
        break;
      }
      if (blocks[ptr].a <= vertices[i].first &&
          vertices[i].first <= blocks[ptr].b) {
        time_ver[i] = blocks[ptr].t;
      }
    }
    for (int i = 0; i < M; i++) {
      int tm = min(time_ver[edges[i].first], time_ver[edges[i].second]);
      time_edge[tm].push_back(i);
    }
    auto get_ver = [&](long long x) -> int {
      int lo = 0, hi = N - 1;
      while (1) {
        int mid = lo + (hi - lo) / 2;
        const auto &v = vertices[mid];
        if (x < v.first) {
          hi = mid - 1;
        } else if (v.second < x) {
          lo = mid + 1;
        } else {
          return mid;
        }
      }
    };
    dsu g(N);
    const int Q = queries.size();
    vector<int> ans(Q, -1);
    int pq = Q - 1;
    for (int t = m; pq >= 0; t--) {
      auto &q = queries[pq];
      if (q.t == t) {
        int va = get_ver(q.a);
        int vb = get_ver(q.b);
        ans[pq] = (g.find(va) == g.find(vb));
        pq--;
      } else {
        for (int id : time_edge[t]) {
          g.unite(edges[id].first, edges[id].second);
        }
      }
    }
    for (int x : ans) {
      cout << x << '\n';
    }
  }
  int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    foo();
  }
  