#include using namespace std; using ll = long long; #ifdef MY_DEBUG #define dbg(var) debug_out(#var, "=", var) #define dbgm(...) debug_out(__VA_ARGS__) #else #define dbg(...) #define dbgm(...) #endif void debug_out(); template void debug_out(Head, Tail...); template bool chmax(T &, const T &); template bool chmin(T &, const T &); template T pwr(T, ll); template T squ(T x) { return x * x; } ll fact(ll); ll comb(ll, ll); ll ctoll(char); char lltoc(ll); bool flg(ll b, ll i) { return ((b) >> (i)) & 1LL; } // flg(0b010, 1LL) -> true const ll LINF = (ll)4e18 + 7; const double EPS = 1e-9; const int MAX_DUBUG_SIZE = 10; void solve([[maybe_unused]] int test) { ll n, m; cin >> n >> m; vector a(m); for (ll i = 0; i < m; i++) { cin >> a[i]; } reverse(a.begin(), a.end()); map mp; mp[0] = LINF; mp[1] = 0; mp[n] = n - 1; mp[n + 1] = LINF; auto add = [&](ll k) { if (mp.count(k)) return; mp[k] = 0; auto [pre_id, pre_vl] = *prev(mp.find(k)); auto [nxt_id, nxt_vl] = *next(mp.find(k)); assert(pre_vl != LINF and nxt_vl != LINF); if (pre_vl == nxt_vl) mp[k] = pre_vl; else if (pre_vl < nxt_vl) { mp[k] = pre_vl + (k - pre_id); } else { mp[k] = pre_vl - (k - pre_id); } assert(mp[k] >= 0); }; for (ll i = 0; i < m; i++) { ll x = a[i]; add(x); add(x + 1); // dbg(x); // dbg(mp); if (mp[x] == mp[x + 1]) continue; else if (mp[x] < mp[x + 1]) { while (true) { auto nxt_x_plus_1 = next(mp.find(x + 1)); if (nxt_x_plus_1->first >= n) break; auto nnxt_x_plus_1 = next(mp.find(x + 1), 2); if (nxt_x_plus_1->second - mp[x + 1] <= 0 or nxt_x_plus_1->second - mp[x + 1] != nxt_x_plus_1->first - (x + 1)) break; if (nnxt_x_plus_1->second - mp[x + 1] <= 0 or nnxt_x_plus_1->second - mp[x + 1] != nnxt_x_plus_1->first - (x + 1)) break; mp.erase(nxt_x_plus_1); } add(x - 1); if (mp[x] - mp[x - 1] != 1) mp[x]++; auto &&nxt_x_plus_1 = next(mp.find(x + 1)); if (nxt_x_plus_1->second - mp[x + 1] > 0 and nxt_x_plus_1->second - mp[x + 1] == nxt_x_plus_1->first - (x + 1)) nxt_x_plus_1->second--; mp[x + 1]--; } else { while (true) { auto prv_x = prev(mp.find(x)); if (prv_x->first <= 1) break; auto pprv_x = prev(mp.find(x), 2); if (prv_x->second - mp[x] <= 0 or prv_x->second - mp[x] != prv_x->first - (x)) break; if (pprv_x->second - mp[x] <= 0 or pprv_x->second - mp[x] != pprv_x->first - (x)) break; mp.erase(prv_x); } // dbg(mp); add(x + 2); if (mp[x + 1] - mp[x + 2] != 1) mp[x + 1]++; auto &&prv_x = prev(mp.find(x)); if (prv_x->second - mp[x] > 0 and prv_x->second - mp[x] == prv_x->first - (x)) prv_x->second--; mp[x]--; } // dbg(mp); } for (ll i = 2; i <= n; i++) { add(i); cout << mp[i]; if (i != n) cout << ' '; } cout << '\n'; } int main() { cin.tie(nullptr), ios::sync_with_stdio(false); cout << fixed << setprecision(12), cerr << fixed << setprecision(12); int testcase_size = 1; // cin >> testcase_size; for (int _t = 0; _t < testcase_size; _t++) { solve(_t); } } /* -----------------------------------MY_FUNCTIONS------------------------------------ */ template ostream &operator<<(ostream &os, const pair &pp); template ostream &operator<<(ostream &os, const vector &V); template ostream &operator<<(ostream &os, const vector> &VV); template ostream &operator<<(ostream &os, const vector>> &VVV); template ostream &operator<<(ostream &os, const set &SS); template ostream &operator<<(ostream &os, const map &MM); void debug_out(); void debug_out_vl(vector V); void debug_out_vvl(vector> VV); template void debug_out(Head H, Tail... T); template ostream &operator<<(ostream &os, const pair &pp) { return os << "{" << pp.first << "," << pp.second << "}"; } template ostream &operator<<(ostream &os, const vector &V) { if (V.empty()) return os << "[]"; os << "["; for (ll i = 0; i < (ll)V.size(); i++) { os << V[i] << (i == int(V.size() - 1) ? "]" : ","); } return os; } template ostream &operator<<(ostream &os, const vector> &VV) { if (VV.empty()) return os << "[[]]"; os << "[" << endl; for (auto &&V : VV) { os << V << endl; } os << "]"; return os; } template ostream &operator<<(ostream &os, const vector>> &VVV) { if (VVV.empty()) return os << "[[[]]]"; os << "[" << endl; int cnt = 0; for (auto &&VV : VVV) { os << cnt++ << VV << endl << endl; } os << "]"; return os; } template ostream &operator<<(ostream &os, const set &SS) { if (SS.empty()) return os << "[]"; os << "["; auto ii = SS.begin(); for (; ii != SS.end(); ii++) os << *ii << (ii == prev(SS.end()) ? "]" : ","); return os; } template ostream &operator<<(ostream &os, const map &MM) { if (MM.empty()) return os << "[{:}]"; os << "["; auto ii = MM.begin(); for (; ii != MM.end(); ii++) os << "{" << ii->first << ":" << ii->second << "}" << (ii == prev(MM.end()) ? "]" : ","); return os; } void debug_out() { cerr << endl; } void debug_out_vl(vector V) { const int MAX_SIZE = min((int)V.size(), MAX_DUBUG_SIZE); cerr << "\033[33m"; if (V.empty()) { cerr << "[]" << endl; return; } cerr << "["; for (int i = 0; i < MAX_SIZE; i++) { if (V[i] == LINF) cerr << "INF"; else cerr << V[i]; if (i == (int)V.size() - 1) cerr << "]" << endl; else if (i == MAX_DUBUG_SIZE - 1) cerr << ",..." << endl; else cerr << ","; } return; } void debug_out_vvl(vector> VV) { cerr << "\033[33m"; if (VV.empty()) { cerr << "[[]]" << endl; return; } cerr << "[" << endl; int MAX_ROW = min((int)VV.size(), MAX_DUBUG_SIZE); for (int i = 0; i < MAX_ROW; i++) { const int MAX_COLUMN = min((int)VV[i].size(), MAX_DUBUG_SIZE); if (VV[i].empty()) { cerr << "[]" << endl; continue; } cerr << "["; for (int j = 0; j < MAX_COLUMN; j++) { if (VV[i][j] == LINF) cerr << "INF"; else cerr << VV[i][j]; if (j == (int)VV[i].size() - 1) cerr << "]" << endl; else if (j == MAX_DUBUG_SIZE - 1) cerr << ",..." << endl; else cerr << ","; } if (i != (int)VV.size() - 1 and i == MAX_DUBUG_SIZE - 1) { cerr << ":\n:\033[m" << endl; return; } } cerr << "]\033[m" << endl; return; } template void debug_out(Head H, Tail... T) { if constexpr (std::is_same_v>) { debug_out_vl(H); } else if constexpr (std::is_same_v>>) { debug_out_vvl(H); } else { cerr << "\033[33m" << H << "\033[m "; } debug_out(T...); } template bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } template T pwr(T x, ll n) { T res = 1; for (int i = 0; i < n; i++) { res *= x; } return res; } ll fact(ll n) { ll res = 1; for (ll i = 1; i <= n; i++) res *= i; return res; } ll comb(ll n, ll r) { // comb(60, 30)までオーバーフローなし ll res = 1; for (int i = 1; i <= r; i++) { res *= n--; res /= i; } return res; } ll ctoll(char c) { if (c < '0' or '9' < c) { cerr << "\n\033[33m ctoll に '0'~'9' 以外の文字が入りました.\033[m\n" << endl; } return ll(c - '0'); } char lltoc(ll n) { if (n < 0 or 9 < n) { cerr << "\n\033[33m lltoc に 0 ~ 9 以外の数字が入りました.\033[m\n" << endl; } return char(n + '0'); }