fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. struct traffic_lights: set<int> {
  5. void closest(int p, int &l, int& r) {
  6. auto ip = upper_bound(p);
  7. r = *ip--, l = *ip; } };
  8.  
  9. struct segments: map<int,int> {
  10. void remove(int x) {
  11. const auto it = find(x);
  12. auto& count = it->second;
  13. if (--count == 0)
  14. erase(it); }
  15. int max_length() const { return crbegin()->first; } };
  16.  
  17. int main() {
  18. int x, n; traffic_lights s; segments q;
  19. cin.tie(nullptr)->sync_with_stdio(false),
  20. cin >> x >> n, s.insert(0), s.insert(x), q[x] = 1;
  21. for (int p, l, r; n--; s.insert(p), cout << q.max_length() << ' ')
  22. cin >> p, s.closest(p,l,r), q.remove(r-l), ++q[p-l], ++q[r-p]; }
  23.  
Success #stdin #stdout 0s 4804KB
stdin
8 3
3 6 2
stdout
5 3 3