Advertisement
a53

segmax

a53
May 12th, 2022
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ULL unsigned long long
  3. using namespace std;
  4. int N;
  5. ULL L, x2;
  6. vector<ULL>v;
  7. set<ULL>s;
  8. set<ULL>::iterator up1, up2;
  9. multiset<ULL>ms;
  10. int main()
  11. {
  12. ios::sync_with_stdio(0);
  13. cin.tie(0);
  14. cout.tie(0);
  15. int i=0, j;
  16. ULL a, b;
  17. cin>>L>>N;
  18. if(N<=1000)
  19. {
  20. v.push_back(0);
  21. v.push_back(L);
  22. for(i=1; i<=N; ++i)
  23. {
  24. cin>>x2;
  25. v.push_back(x2);
  26. sort(v.begin(), v.end());
  27. ULL maxl=0, diff;
  28. for(j=1; j<(int)v.size(); ++j)
  29. {
  30. diff=v[j]-v[j-1]+1;
  31. if(diff > maxl)
  32. maxl=diff;
  33. }
  34. cout<<maxl<<'\n';
  35. }
  36. return 0;
  37. }
  38. s.insert(0);
  39. s.insert(L);
  40. for(i=1; i<=N; ++i)
  41. {
  42. cin>>x2;
  43. s.insert(x2);
  44. up1 = s.lower_bound(x2);
  45. if(*up1==x2)
  46. --up1;
  47. a=(*up1);
  48. up2 = s.upper_bound(x2);
  49. if(*up2==x2)
  50. ++up2;
  51. b=(*up2);
  52. ULL seg=(b-a+1);
  53. ms.emplace(x2-a+1);
  54. ms.emplace(b-x2+1);
  55. auto itr=ms.find(seg);
  56. if(*itr==seg)
  57. ms.erase(itr);
  58. cout<<*(ms.rbegin())<<'\n';
  59. }
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement