Submission #891991

# Submission time Handle Problem Language Result Execution time Memory
891991 2023-12-24T15:09:32 Z MilosMilutinovic Bulldozer (JOI17_bulldozer) C++14
Compilation error
0 ms 0 KB
// todo
#include <bits/stdc++.h>
 
using namespace std;
 
struct pt {
  int x, y;
};

bool same(int x1, int y1, int x2, int y2) {
  // y1 / x1 = y2 / x2
  return x1 * 1LL * y2 == y1 * 1LL * x2;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> x(n), y(n), w(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i] >> w[i];
  }
  vector<int> order(n);
  iota(order.begin(), order.end(), 0);
  sort(order.begin(), order.end(), [&](int i, int j) {
    if (y[i] != y[j]) {
      return y[i] > y[j];
    } else {
      return x[i] > x[j];
    }
  });
  vector<int> pos(n);
  for (int i = 0; i < n; i++) {
    pos[order[i]] = i;
  }
  vector<long long> mx(4 * n);
  vector<long long> sum(4 * n);
  vector<long long> pref(4 * n);
  vector<long long> suff(4 * n);
  auto Pull = [&](int x) {
    sum[x] = sum[x << 1] + sum[x << 1 | 1];
    mx[x] = max({mx[x << 1], mx[x << 1 | 1], suff[x << 1] + pref[x << 1 | 1]});
    pref[x] = max(pref[x << 1], sum[x << 1] + pref[x << 1 | 1]);
    suff[x] = max(suff[x << 1 | 1], sum[x << 1 | 1] + suff[x << 1]);
  };
  function<void(int, int, int)> Build = [&](int x, int l, int r) {
    if (l == r) {
      sum[x] = w[order[l]];
      mx[x] = max(0LL, sum[x]);
      pref[x] = max(0LL, sum[x]);
      suff[x] = max(0LL, sum[x]);
      return;
    }
    int mid = l + r >> 1;
    Build(x << 1, l, mid);
    Build(x << 1 | 1, mid + 1, r);
    Pull(x);
  };
  function<void(int, int, int, int)> Update = [&](int x, int l, int r, int p) {
    if (l == r) {
      sum[x] = w[order[l]];
      mx[x] = max(0LL, sum[x]);
      pref[x] = max(0LL, sum[x]);
      suff[x] = max(0LL, sum[x]);
      return;
    }
    int mid = l + r >> 1;
    if (p <= mid) {
      Update(x << 1, l, mid, p);
    } else {
      Update(x << 1 | 1, mid + 1, r, p);
    }
    Pull(x);
  };
  Build(1, 0, n - 1);
  vector<array<int, 4>> qs;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int fx = x[j] - x[i];
      int fy = y[j] - y[i];
      if (fy < 0) {
        fx = -fx;
        fy = -fy;
      }
      qs.push_back({fx, fy, i, j});
    }
  }
  sort(qs.begin(), qs.end(), [&](array<int, 4> a, array<int, 4> b) {
    
  });
  int sz = (int) qs.size();
  for (int i = 0; i < sz; i++) {
    int ptr = i;
    while (ptr + 1 < sz && same(qs[i][0], qs[i][1], qs[ptr + 1][0], qs[ptr + 1][1])) {
      ptr += 1;
      swap(order[pos[qs[ptr][2]]], order[pos[qs[ptr][3]]]);
      swap(pos[qs[ptr][2]], pos[qs[ptr][3]]);
      Update(1, 0, n - 1, pos[qs[ptr][2]]);
      Update(1, 0, n - 1, pos[qs[ptr][3]]);
    }
  }
  long long ans = mx[1];
  cout << ans << '\n';
  return 0;
}

Compilation message

bulldozer.cpp: In lambda function:
bulldozer.cpp:55:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   55 |     int mid = l + r >> 1;
      |               ~~^~~
bulldozer.cpp: In lambda function:
bulldozer.cpp:68:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   68 |     int mid = l + r >> 1;
      |               ~~^~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:71,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from bulldozer.cpp:2:
/usr/include/c++/10/bits/predefined_ops.h: In instantiation of 'constexpr bool __gnu_cxx::__ops::_Iter_comp_iter<_Compare>::operator()(_Iterator1, _Iterator2) [with _Iterator1 = __gnu_cxx::__normal_iterator<std::array<int, 4>*, std::vector<std::array<int, 4> > >; _Iterator2 = __gnu_cxx::__normal_iterator<std::array<int, 4>*, std::vector<std::array<int, 4> > >; _Compare = main()::<lambda(std::array<int, 4>, std::array<int, 4>)>]':
/usr/include/c++/10/bits/stl_algo.h:82:17:   required from 'void std::__move_median_to_first(_Iterator, _Iterator, _Iterator, _Iterator, _Compare) [with _Iterator = __gnu_cxx::__normal_iterator<std::array<int, 4>*, std::vector<std::array<int, 4> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(std::array<int, 4>, std::array<int, 4>)> >]'
/usr/include/c++/10/bits/stl_algo.h:1924:34:   required from '_RandomAccessIterator std::__unguarded_partition_pivot(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::array<int, 4>*, std::vector<std::array<int, 4> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(std::array<int, 4>, std::array<int, 4>)> >]'
/usr/include/c++/10/bits/stl_algo.h:1958:38:   required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::array<int, 4>*, std::vector<std::array<int, 4> > >; _Size = long int; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(std::array<int, 4>, std::array<int, 4>)> >]'
/usr/include/c++/10/bits/stl_algo.h:1974:25:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::array<int, 4>*, std::vector<std::array<int, 4> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(std::array<int, 4>, std::array<int, 4>)> >]'
/usr/include/c++/10/bits/stl_algo.h:4892:18:   required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<std::array<int, 4>*, std::vector<std::array<int, 4> > >; _Compare = main()::<lambda(std::array<int, 4>, std::array<int, 4>)>]'
bulldozer.cpp:91:4:   required from here
/usr/include/c++/10/bits/predefined_ops.h:156:30: error: void value not ignored as it ought to be
  156 |         { return bool(_M_comp(*__it1, *__it2)); }
      |                       ~~~~~~~^~~~~~~~~~~~~~~~
/usr/include/c++/10/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Val_comp_iter<_Compare>::operator()(_Value&, _Iterator) [with _Value = std::array<int, 4>; _Iterator = __gnu_cxx::__normal_iterator<std::array<int, 4>*, std::vector<std::array<int, 4> > >; _Compare = main()::<lambda(std::array<int, 4>, std::array<int, 4>)>]':
/usr/include/c++/10/bits/stl_algo.h:1826:20:   required from 'void std::__unguarded_linear_insert(_RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::array<int, 4>*, std::vector<std::array<int, 4> > >; _Compare = __gnu_cxx::__ops::_Val_comp_iter<main()::<lambda(std::array<int, 4>, std::array<int, 4>)> >]'
/usr/include/c++/10/bits/stl_algo.h:1854:36:   required from 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::array<int, 4>*, std::vector<std::array<int, 4> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(std::array<int, 4>, std::array<int, 4>)> >]'
/usr/include/c++/10/bits/stl_algo.h:1886:25:   required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::array<int, 4>*, std::vector<std::array<int, 4> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(std::array<int, 4>, std::array<int, 4>)> >]'
/usr/include/c++/10/bits/stl_algo.h:1977:31:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::array<int, 4>*, std::vector<std::array<int, 4> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(std::array<int, 4>, std::array<int, 4>)> >]'
/usr/include/c++/10/bits/stl_algo.h:4892:18:   required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<std::array<int, 4>*, std::vector<std::array<int, 4> > >; _Compare = main()::<lambda(std::array<int, 4>, std::array<int, 4>)>]'
bulldozer.cpp:91:4:   required from here
/usr/include/c++/10/bits/predefined_ops.h:238:23: error: void value not ignored as it ought to be
  238 |  { return bool(_M_comp(__val, *__it)); }
      |                ~~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/10/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Iter_comp_val<_Compare>::operator()(_Iterator, _Value&) [with _Iterator = __gnu_cxx::__normal_iterator<std::array<int, 4>*, std::vector<std::array<int, 4> > >; _Value = std::array<int, 4>; _Compare = main()::<lambda(std::array<int, 4>, std::array<int, 4>)>]':
/usr/include/c++/10/bits/stl_heap.h:139:48:   required from 'void std::__push_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare&) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::array<int, 4>*, std::vector<std::array<int, 4> > >; _Distance = long int; _Tp = std::array<int, 4>; _Compare = __gnu_cxx::__ops::_Iter_comp_val<main()::<lambda(std::array<int, 4>, std::array<int, 4>)> >]'
/usr/include/c++/10/bits/stl_heap.h:246:23:   required from 'void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::array<int, 4>*, std::vector<std::array<int, 4> > >; _Distance = long int; _Tp = std::array<int, 4>; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(std::array<int, 4>, std::array<int, 4>)> >]'
/usr/include/c++/10/bits/stl_heap.h:355:22:   required from 'void std::__make_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare&) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::array<int, 4>*, std::vector<std::array<int, 4> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(std::array<int, 4>, std::array<int, 4>)> >]'
/usr/include/c++/10/bits/stl_algo.h:1666:23:   required from 'void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::array<int, 4>*, std::vector<std::array<int, 4> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(std::array<int, 4>, std::array<int, 4>)> >]'
/usr/include/c++/10/bits/stl_algo.h:1937:25:   required from 'void std::__partial_sort(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::array<int, 4>*, std::vector<std::array<int, 4> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(std::array<int, 4>, std::array<int, 4>)> >]'
/usr/include/c++/10/bits/stl_algo.h:1953:27:   required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::array<int, 4>*, std::vector<std::array<int, 4> > >; _Size = long int; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(std::array<int, 4>, std::array<int, 4>)> >]'
/usr/include/c++/10/bits/stl_algo.h:1974:25:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::array<int, 4>*, std::vector<std::array<int, 4> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(std::array<int, 4>, std::array<int, 4>)> >]'
/usr/include/c++/10/bits/stl_algo.h:4892:18:   required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<std::array<int, 4>*, std::vector<std::array<int, 4> > >; _Compare = main()::<lambda(std::array<int, 4>, std::array<int, 4>)>]'
bulldozer.cpp:91:4:   required from here
/usr/include/c++/10/bits/predefined_ops.h:194:23: error: void value not ignored as it ought to be
  194 |  { return bool(_M_comp(*__it, __val)); }
      |                ~~~~~~~^~~~~~~~~~~~~~