/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author Ildar */ #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; const int N = 4e5 + 7; ll h[N]; struct tree { tree *l, *r; ll h0, h1; int sw; tree(tree *l, tree *r, ll h0, ll h1, int sw) : l(l), r(r), h0(h0), h1(h1), sw(sw) {} tree() {} }; tree *push(tree *t) { if (!t->sw) { return t; } tree *r1, *r2; if (t->l) { r1 = new tree(t->l->l, t->l->r, t->l->h1, t->l->h0, t->l->sw ^ 1); } else { r1 = t->l; } if (t->r) { r2 = new tree(t->r->l, t->r->r, t->r->h1, t->r->h0, t->r->sw ^ 1); } else { r2 = t->r; } return new tree(r1, r2, t->h0, t->h1, 0); } tree *upd(tree *t, int l, int r, int tl, int tr) { if (tl >= r || tr <= l) { return t; } if (tl >= l && tr <= r) { return new tree(t->l, t->r, t->h1, t->h0, t->sw ^ 1); } else { int tm = (tl + tr) / 2; tree *x = push(t); auto a = upd(x->l, l, r, tl, tm); auto b = upd(x->r, l, r, tm, tr); return new tree(a, b, a->h0 ^ b->h0, a->h1 ^ b->h1, x->sw); } } bool sml(tree *a, tree *b, int tl, int tr) { if (tr - tl == 1) { return (a->h0 && b->h1); } else { int tm = (tl + tr) / 2; a = push(a), b = push(b); if (a->l->h0 == b->l->h0) { return sml(a->r, b->r, tm, tr); } else { return sml(a->l, b->l, tl, tm); } } } tree *build(int l, int r) { if (r - l == 1) { return new tree(0, 0, h[l], 0, 0); } else { int m = (l + r) / 2; auto a = build(l, m); auto b = build(m, r); return new tree(a, b, a->h0 ^ b->h0, a->h1 ^ b->h1, 0); } } vector ind; void dfs(tree *t, int l, int r) { if (r - l == 1) { ind.push_back(bool(t->h1)); } else { int m = (l + r) / 2; t = push(t); dfs(t->l, l, m); dfs(t->r, m, r); } } tree *rt[N]; int n; class Main { public: void solve(std::istream &in, std::ostream &out) { mt19937 Rand(2281488); for (int i = 0; i < N; i++) { rt[i] = 0; h[i] = Rand(); while (h[i] == 0) { h[i] = Rand(); } } ind.clear(); int n, q; in >> n >> q; rt[0] = build(0, n); int cur = 0; for (int i = 1; i <= q; i++) { int l, r; in >> l >> r; l--, r--; rt[i] = upd(rt[i - 1], l, r + 1, 0, n); if (sml(rt[cur], rt[i], 0, n)) { cur = i; } } dfs(rt[cur], 0, n); for (int c : ind) { out << c; } out << '\n'; } }; int main() { ios::sync_with_stdio(0); Main solver; std::istream &in(std::cin); std::ostream &out(std::cout); solver.solve(in, out); return 0; }