Submission #1358871

#TimeUsernameProblemLanguageResultExecution timeMemory
1358871lyra_g13Radio Towers (IOI22_towers)C++20
Compilation error
0 ms0 KiB
#include "towers.h"
#include <bits/stdc++.h>
using ll = long long;
using namespace std;

#include <bits/stdc++.h>
using ll = long long;

class segtree {
public:
  std::vector<ll> seg;
  ll n;
  segtree() : n(0) {}
  segtree(ll n) : n(n), seg(4 * n) {}

  void set(ll v, ll l, ll r, ll idx, ll del) {
    if (idx < l or idx > r) {
      return;
    }
    if (l == r) {
      seg[v] = del;
      return;
    }
    ll m = l + (r - l) / 2;
    set(2 * v, l, m, idx, del);
    set(2 * v + 1, m + 1, r, idx, del);
    seg[v] = max(seg[2 * v], seg[2 * v + 1]);
  }
  void set(ll idx, ll del) {
    set(1, 0, n - 1, idx, del);
  }

  ll q(ll v, ll l, ll r, ll ql, ll qr) {
    if (qr < l or ql > r) {
      return 0;
    }
    if (ql <= l and r <= qr) {
      return seg[v];
    }
    ll m = l + (r - l) / 2;
    return max(q(2 * v, l, m, ql, qr), q(2 * v + 1, m + 1, r, ql, qr));
  }
  ll q(ll ql, ll qr) {
    return q(1, 0, n - 1, ql, qr);
  }
};

int n;
vector<pair<ll, ll>> h;
vector<ll> buff;
vector<ll> count;
segtree st;
segtree counted;

void init(int N, vector<int> H) {
  n = N;
  set<ll> s;
  st = segtree(n);
  counted = segtree(n);

  count.resize(n);

  for (int i = 0; i < H.size(); i++) {
    h.push_back({H[i], i});
    count[h[i].first]++;
    s.insert(h[i].first);
  }
  buff.assign(s.begin(), s.end());

  sort(h.begin(), h.end());
  sort(buff.begin(), buff.end());
};

int max_towers(int l, int r, int d) {

  auto find = [&](ll u) {
    return lower_bound(buff.begin(), buff.end(), u) - buff.begin();
  };
  for (int i = l; i <= r; i++) {
    st.set(find(h[i].first), h[i].first);
  }

  ll c = 0;
  ll ans = 1;
  for (int i = 0; i < n; i++) {
    if (!(h[i].second >= l and h[i].second <= r))
      continue;
    if (c == 0) {
      count[h[i].first]--;
      if (count[h[i].first] == 0)
        st.set(find(h[i].first), 0);
      counted.set(h[i].second, 1);
      c++;
    } else {
      ll left = 0;
      ll right = 0;
      ll check = 0;

      ll lll = l, rr = h[i].second - 1;
      if (rr < 0)
        check = 1;

      while (lll <= rr and check == 0) {
        ll mid = lll + (rr - lll) / 2;
        if (st.q(mid, rr) >= h[i].first + d) {
          lll = mid + 1;
        } else {
          rr = mid - 1;
        }
      }

      left = lll;

      lll = h[i].second + 1, rr = n - 1;

      while (lll <= rr and check == 0) {
        ll mid = lll + (rr - lll) / 2;
        if (st.q(lll, mid) >= h[i].first + d) {
          rr = mid - 1;
        } else {
          lll = mid + 1;
        }
      }
      right = lll;

      if (check == 0 and counted.q(left, right) == 0) {
        count[find(h[i].first)]--;
        if (count[find(h[i].first)] == 0)
          st.set(find(h[i].first), 0);
        counted.set(h[i].second, 1);
        ans++;
      }
    }
  }
  return ans;
};

Compilation message (stderr)

towers.cpp: In function 'void init(int, std::vector<int>)':
towers.cpp:61:3: error: reference to 'count' is ambiguous
   61 |   count.resize(n);
      |   ^~~~~
In file included from /usr/include/c++/13/algorithm:73,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from towers.cpp:2:
/usr/include/c++/13/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
In file included from /usr/include/c++/13/algorithm:61:
/usr/include/c++/13/bits/stl_algo.h:4072:5: note:                 'template<class _IIter, class _Tp> constexpr typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
 4072 |     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
      |     ^~~~~
towers.cpp:51:12: note:                 'std::vector<long long int> count'
   51 | vector<ll> count;
      |            ^~~~~
towers.cpp:65:5: error: reference to 'count' is ambiguous
   65 |     count[h[i].first]++;
      |     ^~~~~
/usr/include/c++/13/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
/usr/include/c++/13/bits/stl_algo.h:4072:5: note:                 'template<class _IIter, class _Tp> constexpr typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
 4072 |     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
      |     ^~~~~
towers.cpp:51:12: note:                 'std::vector<long long int> count'
   51 | vector<ll> count;
      |            ^~~~~
towers.cpp: In function 'int max_towers(int, int, int)':
towers.cpp:89:7: error: reference to 'count' is ambiguous
   89 |       count[h[i].first]--;
      |       ^~~~~
/usr/include/c++/13/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
/usr/include/c++/13/bits/stl_algo.h:4072:5: note:                 'template<class _IIter, class _Tp> constexpr typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
 4072 |     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
      |     ^~~~~
towers.cpp:51:12: note:                 'std::vector<long long int> count'
   51 | vector<ll> count;
      |            ^~~~~
towers.cpp:90:11: error: reference to 'count' is ambiguous
   90 |       if (count[h[i].first] == 0)
      |           ^~~~~
/usr/include/c++/13/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
/usr/include/c++/13/bits/stl_algo.h:4072:5: note:                 'template<class _IIter, class _Tp> constexpr typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
 4072 |     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
      |     ^~~~~
towers.cpp:51:12: note:                 'std::vector<long long int> count'
   51 | vector<ll> count;
      |            ^~~~~
towers.cpp:127:9: error: reference to 'count' is ambiguous
  127 |         count[find(h[i].first)]--;
      |         ^~~~~
/usr/include/c++/13/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
/usr/include/c++/13/bits/stl_algo.h:4072:5: note:                 'template<class _IIter, class _Tp> constexpr typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
 4072 |     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
      |     ^~~~~
towers.cpp:51:12: note:                 'std::vector<long long int> count'
   51 | vector<ll> count;
      |            ^~~~~
towers.cpp:128:13: error: reference to 'count' is ambiguous
  128 |         if (count[find(h[i].first)] == 0)
      |             ^~~~~
/usr/include/c++/13/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
/usr/include/c++/13/bits/stl_algo.h:4072:5: note:                 'template<class _IIter, class _Tp> constexpr typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
 4072 |     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
      |     ^~~~~
towers.cpp:51:12: note:                 'std::vector<long long int> count'
   51 | vector<ll> count;
      |            ^~~~~