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>
  void sc(int &x) { scanf("%d", &x); }
  void sc(int &x, int &y) { scanf("%d%d", &x, &y); }
  void sc(int &x, int &y, int &z) { scanf("%d%d%d", &x, &y, &z); }
  void sc(long long &x) { scanf("%lld", &x); }
  void sc(long long &x, long long &y) { scanf("%lld%lld", &x, &y); }
  void sc(long long &x, long long &y, long long &z) {
    scanf("%lld%lld%lld", &x, &y, &z);
  }
  void sc(char *x) { scanf("%s", x); }
  void sc(char *x, char *y) { scanf("%s%s", x, y); }
  void sc(char *x, char *y, char *z) { scanf("%s%s%s", x, y, z); }
  void out(int x) { printf("%d\n", x); }
  void out(long long x) { printf("%lld\n", x); }
  void out(int x, int y) { printf("%d %d\n", x, y); }
  void out(long long x, long long y) { printf("%lld %lld\n", x, y); }
  void out(int x, int y, int z) { printf("%d %d %d\n", x, y, z); }
  void out(long long x, long long y, long long z) {
    printf("%lld %lld %lld\n", x, y, z);
  }
  void ast(long long x, long long l, long long r) { assert(x >= l && x <= r); }
  using namespace std;
  const int N = 1e5 + 5, mod = 1e9 + 7;
  int n, m, id, tot, rt, t[N * 50], tim[N * 50], ls[N * 50], rs[N * 50],
      f[N * 50];
  string op[N];
  long long up, A[N], B[N];
  int getf(int x) { return f[x] == x ? x : f[x] = getf(f[x]); }
  void ins(long long l, long long r, long long x, long long y, int &now,
           int tim) {
    if (r < x || l > y) return;
    if (!now) now = ++tot;
    if (l >= x && r <= y) {
      t[now] = tim;
      return;
    }
    long long m = (l + r) >> 1;
    ins(l, m, x, y, ls[now], tim);
    ins(m + 1, r, x, y, rs[now], tim);
    t[now] = -1;
  }
  struct node {
    long long l, r;
    int id;
  };
  vector<pair<int, int>> e[N];
  bool jiao(long long l1, long long r1, long long l2, long long r2) {
    return max(l1, l2) <= min(r1, r2);
  }
  vector<node> build(long long l, long long r, int now) {
    vector<node> ans;
    if (!now) {
      ans.push_back({l, r, ++id});
      tim[id] = 0;
      return ans;
    }
    if (t[now] != -1) {
      ans.push_back({l, r, ++id});
      tim[id] = t[now];
      return ans;
    }
    long long m = (l + r) >> 1;
    ans = build(l, m, ls[now]);
    vector<node> res = build(m + 1, r, rs[now]);
    int i = 0, j = 0;
    long long len = m - l + 1;
    assert(ans[0].l == res[0].l - len);
    assert(ans.back().r == res.back().r - len);
    while (i < ans.size() && j < res.size()) {
      if (jiao(ans[i].l, ans[i].r, res[j].l - len, res[j].r - len))
        e[max(tim[ans[i].id], tim[res[j].id])].push_back({ans[i].id, res[j].id});
      if (ans[i].r < res[j].r - len)
        i++;
      else
        j++;
    }
    ans.insert(ans.end(), res.begin(), res.end());
    return ans;
  }
  void sol(int cas) {
    cin >> n >> m;
    up = (1ll << n) - 1;
    for (int i = 1; i <= m; i++) cin >> op[i] >> A[i] >> B[i];
    for (int i = 1; i <= m; i++)
      if (op[i] == "block") ins(0, up, A[i], B[i], rt, m - i + 1);
    vector<node> vc = build(0, up, rt);
    vector<long long> g;
    for (node &x : vc) g.push_back(x.r);
    for (int i = 1; i <= id; i++) f[i] = i;
    for (pair<int, int> x : e[0]) f[getf(x.first)] = getf(x.second);
    vector<int> ans;
    for (int i = m; i >= 1; i--)
      if (op[i] == "ask") {
        A[i] = lower_bound(g.begin(), g.end(), A[i]) - g.begin();
        B[i] = lower_bound(g.begin(), g.end(), B[i]) - g.begin();
        A[i] = vc[A[i]].id;
        B[i] = vc[B[i]].id;
        ans.push_back(getf(A[i]) == getf(B[i]));
      } else {
        for (pair<int, int> x : e[m - i + 1]) f[getf(x.first)] = getf(x.second);
      }
    reverse(ans.begin(), ans.end());
    for (int i = 0; i < ans.size(); i++) out(ans[i]);
  }
  int main() {
    srand(time(0));
    int t = 1, cas = 0;
    while (t--) {
      sol(++cas);
    }
  }
  