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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/* -----------------------
Autor: Tomasz Boguslawski
-------------------------- */
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
#include<sstream>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include <fstream>
#include<math.h>

#define LL long long
#define FOR(x, b, e) for(LL x = b; x <= (e); x++)
#define FORS(x, b, e, s) for(LL x = b; x <= (e); x+=s)
#define FORD(x, b, e) for(LL x = b; x >= (e); x--)
#define VAR(v, n) __typeof(n) v = (n)
#define ALL(c) (c).begin(), (c).end()
#define FOREACH(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define DEBUG if (debug)
#define MIN(a,b) ((a>b)?b:a)
#define MAX(a,b) ((a>b)?a:b)

#include<chrono>

using namespace std;

LL pot2[40];
LL pot2p[40];
LL bits[524288];

// 2 ^ 18
#define NN 14
#define N 16384

class MySet
{
    public:
    set<LL> sets[N];
    void clear() { FOR(i,0,N-1) sets[i].clear(); }
    void insert(LL x)
    {
        sets[x%N].insert(x);
    }
    void erase(LL x)
    {
        sets[x%N].erase(x);
    }
    LL size()
    {
        LL si = 0;
        FOR(i,0,N-1) si+=sets[i].size();
        return si;
    }
};

MySet s1;

LL n,m;
LL a[2024];
LL b[2024];
LL aa[2024];
LL bb[2024];

LL buildRange(LL k1, LL k2)
{
    LL r = 0;
    FOR(i,k1,k2) r+=pot2[i-1];
    return r;
}

void buildInitialSet(LL k)
{
    LL first=1; LL last=first+k-1;
    while (last<=n)
    {
        s1.insert(buildRange(first,last));
        first++; last++;
    }
}

void showDecoded(LL p)
{
    FOR(i,1,n) if (pot2[i-1]&p) cout << "x"; else cout << ".";
    cout << "\n";
}

void show(unordered_set<LL>* s)
{
    cout << "Possibilities:\n";
    FOREACH(it,*s) showDecoded(*it);
}

LL maxSize;
LL handled;

LL countBits(LL p)
{
    LL bs = bits[p&524287];
    p = p / 524288;
    bs += bits[p&524287];
    return bs;
}

LL remC; LL toRemove[30000000];
LL addC; LL toAdd[30000000];

void calculate()
{
    //LL timeClear=0;
    //s1->clear();
    FOR(k,1,n) buildInitialSet(k);
    //LL p;
    FORD(r,m,1)
    {
        // handling order "r":
        LL delta = - pot2[b[r]-1] + pot2[a[r]-1];
        if ((a[r]<=NN)&&(b[r]<=NN))
        {
            // handle it quicker
            // phase 1:
            FOR(num,0,N-1) if ((aa[r]&num)&&((bb[r]&num)==0)) s1.sets[num].clear();
            // phase 2:
            FOR(num,0,N-1) if (((aa[r]&num)==0)&&((bb[r]&num)))
            {
                LL num2 = num + delta;
                FOREACH(p,s1.sets[num]) s1.sets[num2].insert(*p + delta);
            }
        }
        else
        {
            // handle it in a classic manner:
            LL p;
            remC=0; addC=0;
            FOR(num,0,N-1)
            FOREACH(p1,s1.sets[num])
            {
                //handled++;
                p=*p1;
                bool is_a=(aa[r]&p)!=0;
                bool is_b=(bb[r]&p)!=0;
                if (is_a)
                {
                    if (!is_b) toRemove[++remC]=p;
                }
                else
                {
                    if (is_b) toAdd[++addC] = (p + delta);
                }
            }
            FOR(i,1,remC) s1.erase(toRemove[i]);
            FOR(i,1,addC) s1.insert(toAdd[i]);
        }
    }
    LL ile[40];
    FOR(i,1,n) ile[i]=0;
    FOR(num,0,N-1) FOREACH(p1,s1.sets[num]) ile[countBits(*p1)]++;
    FOR(i,1,n) cout << ile[i]%2 << ' '; cout << '\n';
}

void readData()
{
    cin >> n; cin >> m;
    FOR(i,1,m) { cin >> a[i]; cin >> b[i]; }
    FOR(i,1,m) { aa[i]=pot2[a[i]-1]; bb[i]=pot2[b[i]-1]; };
}

/// MAIN
int main(int argc, char* argv[])
{
    // magic formula, which makes streams work faster:
	ios_base::sync_with_stdio(0);
	pot2[0]=1; FOR(i,1,39) pot2[i]=pot2[i-1]*2;
	pot2p[0]=1; FOR(i,1,39) pot2p[i]=pot2[i]+pot2p[i-1];
	bits[0]=0;
	FOR(i,1,524287) bits[i]=i%2 + bits[i/2];

	//s1 = new MySet;

	readData();
	//chrono::steady_clock::time_point tm0 = chrono::steady_clock::now();
    calculate();
	//chrono::steady_clock::time_point tm3 = chrono::steady_clock::now();
	//LL timeMsTotal=chrono::duration_cast<chrono::microseconds>(tm3 - tm0).count();
    //cout << "Total time = " << timeMsTotal / 1000000.0 << "\n";
	return 0;
}