fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6. typedef pair<int, int> ii;
  7.  
  8. const int INF = 1e9;
  9. const ll LINF = 1e18;
  10.  
  11. const int N = 2e5 + 5;
  12.  
  13. int n, x;
  14. int p[N];
  15.  
  16. int main() {
  17. ios::sync_with_stdio(false);
  18. cin.tie(nullptr);
  19. cin >> x >> n;
  20. for (int i = 1; i <= n; i++) cin >> p[i];
  21.  
  22. set<int> pos{0, x};
  23. multiset<int> gap{x};
  24.  
  25. for (int i = 1; i <= n; i++) {
  26. pos.insert(p[i]);
  27. auto it = pos.find(p[i]);
  28. int prv = *prev(it), nxt = *next(it);
  29. gap.erase(gap.find(nxt - prv));
  30. gap.insert(p[i] - prv);
  31. gap.insert(nxt - p[i]);
  32. cout << *gap.rbegin() << ' ';
  33. }
  34. }
Success #stdin #stdout 0.01s 5280KB
stdin
8 3
3 6 2
stdout
5 3 3