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
#if defined(EMBE_DEBUG) && !defined(NDEBUG)
#include "embe-debug.hpp"
#else
#define LOG_INDENT(...) do {} while (false)
#define LOG(...) do {} while (false)
#define DUMP(...) do {} while (false)
#endif

#include <algorithm>
#include <iostream>
#include <optional>
#include <ranges>
#include <vector>
#include <cassert>
using namespace std;

namespace {

int count(int n, vector<int> const& state, int x, int y)
{
  auto value = [&](int q) {
    if (q < x || q >= y) return -1;
    return 1;
  };
  vector<int> values(n + 2);
  values[1] = 1;
  for (int i = 0; i < n; ++i) {
    int v = value(i);
    if (state[i] > 0) {
      if (values[state[i]] == 0) {
        values[state[i]] = v;
      } else if (values[state[i]] != v) {
        return 0;
      }
    } else {
      if (values[-state[i]] == 0) {
        values[-state[i]] = -v;
      } else if (values[-state[i]] != -v) {
        return 0;
      }
    }
  }
  return 1;
}

void finish(vector<int>& res, int n, vector<int> const& state)
{
  for (int x = 0; x < n; ++x) {
    for (int y = x + 1; y <= n; ++y) {
      res[y - x - 1] ^= count(n, state, x, y);
    }
  }
}

void solve(vector<int>& res, int n, span<pair<int, int> const> orders, vector<int>& state);

void change(vector<int>& state, int from, int to)
{
  assert(from != 1);
  assert(from != -1);
  for (int& x: state) {
    if (x == from) x = to;
    else if (x == -from) x = -to;
  }
}

void try_equal(vector<int>& res, int n, span<pair<int, int> const> orders, vector<int>& state, int a, int b)
{
  if (state[a] == -state[b]) return;

  if (state[a] != state[b]) {
    if (state[a] == 1 || state[a] == -1) change(state, state[b], state[a]);
    else change(state, state[a], state[b]);
  }
  assert(state[a] == state[b]);
  solve(res, n, orders, state);
}

void try_unequal(vector<int>& res, int n, span<pair<int, int> const> orders, vector<int>& state, int a, int b)
{
  if (state[a] == state[b]) return;

  if (state[a] != -state[b]) {
    if (state[a] == 1 || state[a] == -1) change(state, state[b], -state[a]);
    else change(state, state[a], -state[b]);
  }
  assert(state[a] == -state[b]);
  int old = abs(state[a]);
  state[a] = -1;
  state[b] = 1;
  if (ranges::none_of(span(state).first(n), [&](int x) { return abs(x) == old; })) return;

  assert(state[a] == -state[b]);
  solve(res, n, orders, state);
}

void solve(vector<int>& res, int n, span<pair<int, int> const> orders, vector<int>& state)
{
  if (orders.empty()) {
    finish(res, n, state);
    return;
  }
  auto const& [a, b] = orders.front();
  orders = orders.subspan(1);
  auto state2 = state;
  try_equal(res, n, orders, state, a, b);
  try_unequal(res, n, orders, state2, a, b);
}

void solve(vector<int>& res, int n, span<pair<int, int> const> orders)
{
  vector<int> state(n);
  for (int i = 0; i < n; ++i) {
    state[i] = i + 2;
  }
  solve(res, n, orders, state);
}

}

int main()
{
  iostream::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, m;
  cin >> n >> m;

  vector<pair<int, int>> orders;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    orders.emplace_back(a - 1, b - 1);
  }

  vector<int> res(n);
  solve(res, n, orders);

  bool first = true;
  for (auto const& x: res) {
    if (first) first = false;
    else cout << ' ';
    cout << x;
  }
  cout << endl;

  return 0;
}