#pragma GCC optimize ("Ofast") #define _USE_MATH_DEFINES #include <bits/stdc++.h> #define FOR(i, a, b) for (auto i=(a); i<(b); i++) #define FORD(i, a, b) for (int i=(a); i>(b); i--) #define SZ(x) ((int)(x).size()) #define ALL(x) (x).begin(), (x).end() #define PPC(x) __builtin_popcountll(x) #define MSB(x) (63 - __builtin_clzll(x)) #define LSB(x) __builtin_ctzll(x) #define ARG(x, i) (get<i>(x)) #define ithBit(m, i) ((m) >> (i) & 1) #define pb push_back #define ft first #define sd second #define kw(a) ((a) * (a)) #define CLR(x) x.clear(), x.shrink_to_fit() #ifdef DEBUG #include "debug.h" #else #define dbg(...) 0 #endif using namespace std; template <typename T1, typename T2> inline void remin(T1& a, T2 b) { a = min(a, (T1)b); } template <typename T1, typename T2> inline void remax(T1& a, T2 b) { a = max(a, (T1)b); } const int maxN = 37, maxK = 1 << 10; int res[maxN]; pair <int, int> ord[maxK]; namespace NN_SMALL { int maskFirst[maxK], maskSecond[maxK], maskBoth[maxK]; void trans(int& mask, int i) { if ((mask & maskFirst[i]) and (~mask & maskSecond[i])) mask ^= maskBoth[i]; } void go(int n, int k) { cerr << "NN\n"; FOR(i, 0, k) { auto& [a, b] = ord[i]; maskFirst[i] = 1 << a; maskSecond[i] = 1 << b; maskBoth[i] = maskFirst[i] | maskSecond[i]; } FOR(i, 1, 1<<n) { int mask = i; FOR(j, 0, k) trans(mask, j); int count = PPC(mask), first = LSB(mask), last = MSB(mask); if (last - first + 1 == count) res[count] ^= 1; } } } namespace MM_SMALL { set <long long> same[maxN][maxN], diff[maxN][maxN]; vector <long long> toAdd, toErs; int n, k; void upd(long long m, bool insert) { FOR(i, 1, n) FOR(j, 0, i) { auto& S = (ithBit(m, i) == ithBit(m, j) ? same : diff)[i][j]; if (insert) S.insert(m); else S.erase(m); } } int symulation(long long source) { upd(source, true); FORD(i, k-1, -1) { auto& [a, b] = ord[i]; long long mask = (1ll << a) | (1ll << b); auto& S = diff[max(a, b)][min(a, b)]; for (auto& m : S) { long long w = m ^ mask; if (S.count(w)) continue; if (ithBit(m, b)) toAdd.pb(w); else toErs.pb(m); } for (auto& m : toErs) upd(m, false); for (auto& m : toAdd) upd(m, true); toErs.clear(), toAdd.clear(); } int ret = (SZ(same[1][0]) ^ SZ(diff[1][0])) & 1; FOR(i, 1, n) FOR(j, 0, i) same[i][j].clear(), diff[i][j].clear(); return ret; } void go(int _n, int _k) { cerr << "MMM\n"; n = _n, k = _k; FOR(s, 1, n+1) { long long mask = (1ll << s) - 1; FOR(_, 0, n-s+1) { res[s] ^= symulation(mask); mask <<= 1; } } } } void solve() { int n, k; scanf ("%d%d", &n, &k); FOR(i, 0, k) { int a, b; scanf ("%d%d", &a, &b); a--, b--; ord[i] = {a, b}; } if (k <= 20) MM_SMALL::go(n, k); else if (n < 24) NN_SMALL::go(n, k); else MM_SMALL::go(n, k); FOR(i, 1, n+1) printf("%d ", res[i]); printf("\n"); } int main() { int t = 1; // scanf ("%d", &t); FOR(tid, 1, t+1) { //printf("Case #%d: ", tid); solve(); } return 0; }
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 | #pragma GCC optimize ("Ofast") #define _USE_MATH_DEFINES #include <bits/stdc++.h> #define FOR(i, a, b) for (auto i=(a); i<(b); i++) #define FORD(i, a, b) for (int i=(a); i>(b); i--) #define SZ(x) ((int)(x).size()) #define ALL(x) (x).begin(), (x).end() #define PPC(x) __builtin_popcountll(x) #define MSB(x) (63 - __builtin_clzll(x)) #define LSB(x) __builtin_ctzll(x) #define ARG(x, i) (get<i>(x)) #define ithBit(m, i) ((m) >> (i) & 1) #define pb push_back #define ft first #define sd second #define kw(a) ((a) * (a)) #define CLR(x) x.clear(), x.shrink_to_fit() #ifdef DEBUG #include "debug.h" #else #define dbg(...) 0 #endif using namespace std; template <typename T1, typename T2> inline void remin(T1& a, T2 b) { a = min(a, (T1)b); } template <typename T1, typename T2> inline void remax(T1& a, T2 b) { a = max(a, (T1)b); } const int maxN = 37, maxK = 1 << 10; int res[maxN]; pair <int, int> ord[maxK]; namespace NN_SMALL { int maskFirst[maxK], maskSecond[maxK], maskBoth[maxK]; void trans(int& mask, int i) { if ((mask & maskFirst[i]) and (~mask & maskSecond[i])) mask ^= maskBoth[i]; } void go(int n, int k) { cerr << "NN\n"; FOR(i, 0, k) { auto& [a, b] = ord[i]; maskFirst[i] = 1 << a; maskSecond[i] = 1 << b; maskBoth[i] = maskFirst[i] | maskSecond[i]; } FOR(i, 1, 1<<n) { int mask = i; FOR(j, 0, k) trans(mask, j); int count = PPC(mask), first = LSB(mask), last = MSB(mask); if (last - first + 1 == count) res[count] ^= 1; } } } namespace MM_SMALL { set <long long> same[maxN][maxN], diff[maxN][maxN]; vector <long long> toAdd, toErs; int n, k; void upd(long long m, bool insert) { FOR(i, 1, n) FOR(j, 0, i) { auto& S = (ithBit(m, i) == ithBit(m, j) ? same : diff)[i][j]; if (insert) S.insert(m); else S.erase(m); } } int symulation(long long source) { upd(source, true); FORD(i, k-1, -1) { auto& [a, b] = ord[i]; long long mask = (1ll << a) | (1ll << b); auto& S = diff[max(a, b)][min(a, b)]; for (auto& m : S) { long long w = m ^ mask; if (S.count(w)) continue; if (ithBit(m, b)) toAdd.pb(w); else toErs.pb(m); } for (auto& m : toErs) upd(m, false); for (auto& m : toAdd) upd(m, true); toErs.clear(), toAdd.clear(); } int ret = (SZ(same[1][0]) ^ SZ(diff[1][0])) & 1; FOR(i, 1, n) FOR(j, 0, i) same[i][j].clear(), diff[i][j].clear(); return ret; } void go(int _n, int _k) { cerr << "MMM\n"; n = _n, k = _k; FOR(s, 1, n+1) { long long mask = (1ll << s) - 1; FOR(_, 0, n-s+1) { res[s] ^= symulation(mask); mask <<= 1; } } } } void solve() { int n, k; scanf ("%d%d", &n, &k); FOR(i, 0, k) { int a, b; scanf ("%d%d", &a, &b); a--, b--; ord[i] = {a, b}; } if (k <= 20) MM_SMALL::go(n, k); else if (n < 24) NN_SMALL::go(n, k); else MM_SMALL::go(n, k); FOR(i, 1, n+1) printf("%d ", res[i]); printf("\n"); } int main() { int t = 1; // scanf ("%d", &t); FOR(tid, 1, t+1) { //printf("Case #%d: ", tid); solve(); } return 0; } |