#include <bits/stdc++.h> using namespace std; namespace std { template<class Fun> class y_combinator_result { Fun fun_; public: template<class T> explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {} template<class ...Args> decltype(auto) operator()(Args &&...args) { return fun_(std::ref(*this), std::forward<Args>(args)...); } }; template<class Fun> decltype(auto) y_combinator(Fun &&fun) { return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); } } // namespace std int main(){ ios_base::sync_with_stdio(false), cin.tie(nullptr); int N, M; cin >> N >> M; vector<pair<int,int> > ops(M); for(int i = 0; i < M; i++){ cin >> ops[i].first >> ops[i].second; ops[i].first--; ops[i].second--; } using state_t = array<char, 35>; state_t empty; for(int i = 0; i < 35; i++) empty[i] = 1; vector<int> ans(N+1, 0); y_combinator( [&](auto self, int st, state_t a) -> void { for(int cur = st; cur < M; cur++){ auto [x, y] = ops[cur]; if(a[x] == 1 && a[y] == 1){ a[x] = 0; a[y] = 0; self(cur+1, a); a[x] = 2; a[y] = 2; self(cur+1, a); return; } if(a[x] > a[y]) swap(a[x], a[y]); } int min2 = N-1; int max2 = 0; for(int i = 0; i < N; i++){ if(a[i] == 2){ min2 = min(min2, i); max2 = max(max2, i); } } for(int l = 0; l <= min2; l++){ int r = l; while(r < N){ if(a[r] == 0) break; if(l <= min2 && r >= max2) ans[r-l+1] ^= 1; r++; } } } )(0, empty); for(int i = 1; i <= N; i++){ cout << ans[i] << " \n"[i == N]; } }
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 | #include <bits/stdc++.h> using namespace std; namespace std { template<class Fun> class y_combinator_result { Fun fun_; public: template<class T> explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {} template<class ...Args> decltype(auto) operator()(Args &&...args) { return fun_(std::ref(*this), std::forward<Args>(args)...); } }; template<class Fun> decltype(auto) y_combinator(Fun &&fun) { return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); } } // namespace std int main(){ ios_base::sync_with_stdio(false), cin.tie(nullptr); int N, M; cin >> N >> M; vector<pair<int,int> > ops(M); for(int i = 0; i < M; i++){ cin >> ops[i].first >> ops[i].second; ops[i].first--; ops[i].second--; } using state_t = array<char, 35>; state_t empty; for(int i = 0; i < 35; i++) empty[i] = 1; vector<int> ans(N+1, 0); y_combinator( [&](auto self, int st, state_t a) -> void { for(int cur = st; cur < M; cur++){ auto [x, y] = ops[cur]; if(a[x] == 1 && a[y] == 1){ a[x] = 0; a[y] = 0; self(cur+1, a); a[x] = 2; a[y] = 2; self(cur+1, a); return; } if(a[x] > a[y]) swap(a[x], a[y]); } int min2 = N-1; int max2 = 0; for(int i = 0; i < N; i++){ if(a[i] == 2){ min2 = min(min2, i); max2 = max(max2, i); } } for(int l = 0; l <= min2; l++){ int r = l; while(r < N){ if(a[r] == 0) break; if(l <= min2 && r >= max2) ans[r-l+1] ^= 1; r++; } } } )(0, empty); for(int i = 1; i <= N; i++){ cout << ans[i] << " \n"[i == N]; } } |