1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e5;
int l[maxn], r[maxn], ans[maxn], n, m;
map<int, set<long long> > mp;

void brute() {
    vector<int> a(n);
    for (int mask = 1; mask < (1 << n); ++mask) {
        int sum = 0;
        for (int i = 0; i < n; ++i) {
            int cur = mask & (1 << i);
            if (cur > 0) a[i] = 1; else a[i] = 0;
            sum += a[i];
        }
        for (int i = 1; i <= m; ++i) {
            if (a[l[i]] == 1 && a[r[i]] == 0) swap(a[l[i]], a[r[i]]);
        }
        int l = -1, r = -1;
        for (int i = 0; i < n; ++i) {
            if (a[i] == 1) {
                if (l == -1) l = i;
                r = i;
            }
        }
        if (r - l + 1 == sum) {
            ++ans[sum];
        }
    }
    for (int i = 1; i <= n; ++i) cout << ans[i] % 2 << " "; cout << endl;
}

int main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    for (int i = 1; i <= m; ++i) {
        cin >> l[i] >> r[i];
        --l[i], --r[i];
    }
    if (n <= 17) {
        brute();
        return 0;
    }
    vector<int> a(n);
    vector<long long> start, finish;
    for (int i = 0; i < n; ++i) {
        for (int j = i; j < n; ++j) {
            for (int k = 0; k < n; ++k) {
                if (k >= i && k <= j) a[k] = 1; else a[k] = 0;
            }
            long long cur = 0;
            for (int k = 0; k < n; ++k) cur = cur * 2 + a[k];
            start.push_back(cur);
        }
    }

    for (int it = m; it >= 1; --it) {
        finish.clear();
        for (const auto& x : start) {
            auto cur = x;
            long long L = x & (1ll << l[it]);
            long long R = x & (1ll << r[it]);
            if (L > 0) L = 1;
            if (R > 0) R = 1;
            if (L == 1 && R == 0) continue;
            finish.push_back(x);
            if (L == 0 && R == 1) {
                cur += (1ll << l[it]);
                cur -= (1ll << r[it]);
                finish.push_back(cur);
            }
        }
        sort(finish.begin(), finish.end());
        if (finish.empty()) {
            start = finish;
            break;
        }
        int cnt = 1;
        for (int i = 1; i < finish.size(); ++i) {
            if (finish[cnt - 1] == finish[i]) continue; else {
                ++cnt;
                finish[cnt - 1] = finish[i];
            }
        }
        while (finish.size() > cnt) finish.pop_back();
        start = finish;
    }
    vector<int> ans(n + 1, 0);
    for (const auto& x : start) {
        int cnt = 0;
        long long cur = x;
        while (cur) {
            cnt += cur % 2;
            cur /= 2;
        }
        ++ans[cnt];
    }
    for (int i = 1; i <= n; ++i) {
        if (i != 1) cout << " ";
        cout << ans[i] % 2;
    }
    cout << endl;
    return 0;
}