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
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

char s[1<<17][35];

int main() {
	int n,m;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; i++)
		s[0][i] = '.';
	//s[0][n] = 0;
	int w = 1;
	for (int mi = 0; mi < m; mi++) {
		int a,b;
		scanf("%d %d", &a, &b);
		a--; b--;
		const int ww = w;
		for (int i = 0; i < ww; i++) {
			if (s[i][a] == '0' || s[i][b] == '1') 
				continue;
			if (s[i][a] == '.' && s[i][b] == '.') {
				for(int j = 0; j < n; j++)
					s[w][j] = s[i][j];
				s[i][a] = s[i][b] = '0';
				s[w][a] = s[w][b] = '1';
				w++;
			} else {
				swap(s[i][a], s[i][b]);
			}
		}
	  //for (int i = 0; i < w; i++) puts(s[i]); puts("=");
	}
	vector<int> ret(n+1), zer(n+1);
	for (int i = 0; i < w; i++) {
		for (int j = 0; j < n; j++) 
			zer[j+1] = zer[j] + (s[i][j] == '0' ? 1 : 0);
		for (int a = 0; a < n; a++) {
			for (int b = n-1; b >= a; b--) {
				if (zer[b+1] == zer[a]) ret[b-a+1]++;
				if (s[i][b] == '1') break;
			}
			if (s[i][a] == '1') break;
		}
	}
	for (int i = 1; i <= n; i++) printf("%d ", ret[i] % 2); printf("\n");
	return 0;
}