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;
  int n, m;
  const int maxN = 5e4 + 10;
  int tp[maxN];
  long long l[maxN], r[maxN];
  vector<pair<long long, long long>> segs;
  void rec(int bit, long long l, long long r) {
    long long all = (1LL << (bit + 1)) - 1;
    long long msk1 = l & all;
    long long msk2 = r & all;
    if (msk1 == 0 && msk2 == all) {
      segs.emplace_back(l, r);
      return;
    }
    if (msk1 >= (1LL << bit)) {
      rec(bit - 1, l, r);
    } else if (msk2 < (1LL << bit)) {
      rec(bit - 1, l, r);
    } else {
      long long f = l | ((1LL << bit) - 1);
      assert(l <= f && f + 1 <= r);
      rec(bit - 1, l, f);
      rec(bit - 1, f + 1, r);
    }
  }
  vector<pair<int, int>> to_add[maxN];
  const int maxK = 2e6;
  int p[maxK];
  int sz[maxK];
  int get(int x) {
    if (x == p[x]) return x;
    return p[x] = get(p[x]);
  }
  void unite(int a, int b) {
    a = get(a);
    b = get(b);
    if (a == b) return;
    if (sz[a] < sz[b]) swap(a, b);
    p[b] = a;
    sz[a] += sz[b];
  }
  bool ans[maxN];
  int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m;
    vector<pair<long long, long long>> f;
    for (int i = 1; i <= m; i++) {
      string s;
      cin >> s;
      if (s == "ask")
        tp[i] = 0;
      else
        tp[i] = 1;
      cin >> l[i] >> r[i];
      if (tp[i] == 1) f.emplace_back(l[i], r[i]);
    }
    sort(f.begin(), f.end());
    if (f.empty()) {
      f.emplace_back(0, (1LL << n) - 1);
    }
    vector<pair<long long, long long>> nf;
    if (f[0].first != 0) {
      nf.emplace_back(0, f[0].first - 1);
    }
    for (int i = 0; i < f.size(); i++) {
      nf.emplace_back(f[i]);
      if (i + 1 < f.size() && f[i].second + 1 <= f[i + 1].first - 1)
        nf.emplace_back(f[i].second + 1, f[i + 1].first - 1);
    }
    if (f.back().second + 1 <= (1LL << n) - 1) {
      nf.emplace_back(f.back().second + 1, (1LL << n) - 1);
    }
    for (auto& it : nf) {
      rec(n - 1, it.first, it.second);
    }
    vector<int> ti(segs.size(), -1);
    for (int i = 1; i <= m; i++) {
      if (tp[i] == 1) {
        int pos1 = lower_bound(segs.begin(), segs.end(), make_pair(l[i], -1LL)) -
                   segs.begin();
        int pos2 =
            lower_bound(segs.begin(), segs.end(), make_pair(r[i] + 1, -1LL)) -
            segs.begin();
        for (int z = pos1; z < pos2; z++) {
          ti[z] = i;
        }
      }
    }
    for (int i = 0; i < segs.size(); i++) {
      if (ti[i] == -1) {
        ti[i] = m;
      }
    }
    for (int bit = 0; bit < n; bit++) {
      vector<int> group[2];
      for (int id = 0; id < segs.size(); id++) {
        long long l = segs[id].first;
        long long r = segs[id].second;
        if (r - l + 1 <= (1LL << bit)) {
          assert((l & (1LL << bit)) == (r & (1LL << bit)));
          group[(l >> bit) & 1].emplace_back(id);
        }
      }
      for (int z = 0; z < 2; z++) {
        int ptr = 0;
        for (int p : group[z]) {
          long long f = segs[p].first ^ (1LL << bit);
          while (segs[ptr].second < f) ptr++;
          if (segs[ptr].second - segs[ptr].first >=
              segs[p].second - segs[p].first) {
            to_add[min(ti[ptr], ti[p])].emplace_back(ptr, p);
          }
        }
      }
    }
    assert(segs.size() < maxK);
    for (int i = 0; i < segs.size(); i++) {
      p[i] = i;
      sz[i] = 1;
    }
    for (int i = m; i >= 1; i--) {
      for (auto& it : to_add[i]) {
        unite(it.first, it.second);
      }
      if (tp[i] == 0) {
        int p1 =
            upper_bound(segs.begin(), segs.end(), make_pair(l[i] + 1, -1LL)) -
            segs.begin() - 1;
        int p2 =
            upper_bound(segs.begin(), segs.end(), make_pair(r[i] + 1, -1LL)) -
            segs.begin() - 1;
        if (get(p1) == get(p2)) {
          ans[i] = true;
        } else {
          ans[i] = false;
        }
      }
    }
    for (int i = 1; i <= m; i++) {
      if (tp[i] == 0) {
        cout << ans[i] << '\n';
      }
    }
    return 0;
  }
  