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 long long mod = 1e9 + 7;
  const int N = 2e5 + 555;
  int n, m, q, z;
  pair<long long, int> a[N];
  int qt[N];
  long long ql[N], qr[N];
  long long ans[N];
  vector<pair<int, int> > ed[N];
  long long bl[N], br[N], arin[N];
  int f[N * 20];
  const int iu = 18;
  int lg[N * 2];
  long long st[N][iu], nid[N][iu];
  long long sh[N][iu];
  void adde(int u, int v, int t) { ed[t].push_back({u, v}); }
  void add(int id, int l, int r) {
    int duh = lg[r - l + 1];
    int e = r - (1 << duh) + 1;
    st[l][duh] = max(st[l][duh], min(arin[id], sh[l][duh]));
    st[e][duh] = max(st[e][duh], min(arin[id], sh[e][duh]));
    adde(id, nid[l][duh], min(arin[id], sh[l][duh]));
    adde(id, nid[e][duh], min(arin[id], sh[e][duh]));
  }
  int find(int x) {
    if (f[x] != x) f[x] = find(f[x]);
    return f[x];
  }
  void join(int x, int y) {
    x = find(x);
    y = find(y);
    f[x] = y;
  }
  int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> q;
    for (int i = 2; i < 262144; i++) lg[i] = lg[i / 2] + 1;
    a[++m] = {-1, -q - 1};
    a[++m] = {1LL << n, q + 1};
    for (int i = 1; i <= q; i++) {
      string s;
      cin >> s >> ql[i] >> qr[i];
      if (s[0] == 'b')
        qt[i] = 1;
      else
        qt[i] = 2;
      if (qt[i] == 1) {
        a[++m] = {ql[i], -i};
        a[++m] = {qr[i], i};
      }
    }
    sort(a + 1, a + m + 1);
    for (int i = 1; i < m; i++) {
      long long cl = a[i].first + (i % 2);
      long long cr = a[i + 1].first - (i % 2);
      int cc;
      if (i % 2 == 1)
        cc = q + 1;
      else
        cc = -a[i].second;
      if (cl > cr) continue;
      if (cl == cr) {
        bl[++z] = cl;
        br[z] = cr;
        arin[z] = cc;
      } else {
        long long fk = cl ^ cr;
        while (fk != (fk & -fk)) fk ^= fk & -fk;
        long long mid = cl | (fk - 1);
        bl[++z] = cl;
        br[z] = mid;
        arin[z] = cc;
        bl[++z] = mid + 1;
        br[z] = cr;
        arin[z] = cc;
      }
    }
    int ptr = z;
    for (int j = 0; j < iu; j++) {
      for (int i = 1; i <= z; i++) {
        nid[i][j] = ++ptr;
        if (j == 0)
          sh[i][j] = arin[i];
        else if (i + (1 << (j - 1)) <= z) {
          sh[i][j] = max(sh[i][j - 1], sh[i + (1 << (j - 1))][j - 1]);
        }
      }
    }
    for (int i = 1; i <= z; i++) {
      for (int k = n - 1; k >= 0; k--) {
        long long cl, cr;
        bool die = false;
        if (br[i] - bl[i] + 1 > (1LL << k)) {
          cr = bl[i] | ((1LL << (k + 1)) - 1);
          cl = cr ^ ((1LL << (k + 1)) - 1);
          die = true;
        } else {
          cl = bl[i] ^ (1LL << k);
          cr = br[i] ^ (1LL << k);
        }
        int zl = lower_bound(br + 1, br + z + 1, cl) - br;
        int zr = lower_bound(bl + 1, bl + z + 1, cr + 1) - bl - 1;
        add(i, zl, zr);
        if (die) break;
      }
      adde(i, nid[i][0], arin[i]);
    }
    for (int j = iu - 2; j >= 0; j--) {
      for (int i = 1; i <= z; i++) {
        st[i][j] = max(st[i][j], st[i][j + 1]);
        adde(nid[i][j], nid[i][j + 1], min(st[i][j + 1], sh[i][j]));
        if (i > (1 << j)) {
          st[i][j] = max(st[i][j], st[i - (1 << j)][j + 1]);
          adde(nid[i][j], nid[i - (1 << j)][j + 1],
               min(st[i - (1 << j)][j + 1], sh[i][j]));
        }
      }
    }
    for (int i = 1; i <= ptr; i++) f[i] = i;
    for (int i = q + 1; i >= 1; i--) {
      for (auto c : ed[i]) join(c.first, c.second);
      if (qt[i] == 2) {
        int cl = lower_bound(br + 1, br + z + 1, ql[i]) - br;
        int cr = lower_bound(br + 1, br + z + 1, qr[i]) - br;
        ans[i] = find(cl) == find(cr);
      }
    }
    for (int i = 1; i <= q; i++) {
      if (qt[i] == 2) cout << ans[i] << '\n';
    }
  }
  