fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct segtree {
  5. int lb, rb;
  6. int sum = 0;
  7. segtree *l = 0, *r = 0;
  8. segtree (int _lb, int _rb) {
  9. lb = _lb, rb = _rb;
  10. }
  11. void extend () {
  12. int t = (lb + rb) / 2;
  13. if (!l) {
  14. l = new segtree(lb, t);
  15. r = new segtree(t+1, rb);
  16. }
  17. }
  18. void add (int k, int x) {
  19. sum += x;
  20. if (lb != rb) {
  21. extend();
  22. int t = (lb + rb) / 2;
  23. if (k <= t) l->add(k, x);
  24. else r->add(k, x);
  25. }
  26. }
  27. int get_sum (int lq, int rq) {
  28. if (lb >= lq && rb <= rq) return sum;
  29. if (lb > rq || rb < lq) return 0;
  30. extend();
  31. return l->get_sum(lq, rq) + r->get_sum(lq, rq);
  32. }
  33. };
  34. int main() {
  35. int n;
  36. cin >> n;
  37. int ans = 0;
  38. segtree tree(0, 1e9);
  39. const int k = 1e9 / n / 2;
  40. for (int i = 0; i < n; ++i) {
  41. ans += tree.get_sum(k * i, k * i + 1e9 / 2);
  42. }
  43. cout << ans << endl;
  44. return 0;
  45. }
  46.  
  47.  
  48.  
Success #stdin #stdout 0.36s 424272KB
stdin
200000
stdout
0