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
#include <algorithm>
#include <bitset>
#include <iostream>
#include <limits>
#include <map>
#include <set>
#include <vector>

using namespace std;
#define ull unsigned long long

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> r(m);
    for (int i = 0; i < m; i++) {
        cin >> r[i].first >> r[i].second;
        r[i].first--;
        r[i].second--;
    }

    for (int i = 1; i <= n; i++) {
        map<int, set<ull>> pos;  // possible configurations
        for (int j = 0; j <= n - i; j++) {
            bitset<35> act;
            for (int k = 0; k < i; k++) {
                act.set(j + k);
            }
            for (int k = 0; k < i; k++) {
                pos[j + k].insert(act.to_ullong());
            }
        }

        for (int k = m - 1; k >= 0; k--) {
            auto& fromSet = pos[r[k].first];
            auto& toSet = pos[r[k].second];
            vector<ull> toDeleteTmp;
            set_difference(fromSet.begin(), fromSet.end(), toSet.begin(),
                           toSet.end(), back_inserter(toDeleteTmp));
            vector<ull> toAddTmp;
            set_difference(toSet.begin(), toSet.end(), fromSet.begin(),
                           fromSet.end(), back_inserter(toAddTmp));
            for (auto& add : toAddTmp) {
                add = add ^ (1ull << r[k].first) ^ (1ull << r[k].second);
            }

            vector<ull> toDelete;
            set_difference(toDeleteTmp.begin(), toDeleteTmp.end(),
                           toAddTmp.begin(), toAddTmp.end(),
                           back_inserter(toDelete));
            for (auto it : toDelete) {
                for (ull i = 0; i < 35; i++) {
                    if (it & (1ull << i)) {
                        pos[i].erase(it);
                    }
                }
            }

            vector<ull> toAdd;
            set_difference(toAddTmp.begin(), toAddTmp.end(),
                           toDeleteTmp.begin(), toDeleteTmp.end(),
                           back_inserter(toAdd));
            for (auto it : toAdd) {
                for (int i = 0; i < 35; i++) {
                    if (it & (1ull << i)) {
                        pos[i].insert(it);
                    }
                }
            }
        }

        set<ull> all;
        for (auto& [_, v] : pos) {
            all.insert(v.begin(), v.end());
        }

        cout << all.size() % 2 << ' ' << flush;
    }

    return 0;
}