Submission #945998

#TimeUsernameProblemLanguageResultExecution timeMemory
945998itslqRoad Construction (JOI21_road_construction)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include <unordered_map> using namespace std; #define int long long int N, K, X, Y; vector<int> x(3e5), y(3e5); unordered_map<int, unordered_map<int, int>> fenwick; void update(int i, int j1, bool b) { for (; i <= X; i += i & -i) { for (int j = j1; j <= Y; j += j & -j) { if (b) fenwick[i][j]++; else fenwick[i][j]--; } } } int query(int i, int j1) { int S = 0; for (; i > 0; i -= i & -i) { for (int j = j1; j > 0; j -= j & -j) { S += fenwick[i][j]; } } return S; } bool check(int d) { int x1, y1, S = 0, ia, ib, ic, id; vector<int> xdisc, ydisc; for (int i = 0; i < N; i++) { x1 = x[i]; y1 = y[i]; xdisc.push_back(x1 - y1 - d); xdisc.push_back(x1 - y1); xdisc.push_back(x1 - y1 + d); ydisc.push_back(x1 + y1 - d); ydisc.push_back(x1 + y1); ydisc.push_back(x1 + y1 + d); } sort(xdisc.begin(), xdisc.end()); sort(ydisc.begin(), ydisc.end()); xdisc.erase(unique(xdisc.begin(), xdisc.end()), xdisc.end()); ydisc.erase(unique(ydisc.begin(), ydisc.end()), ydisc.end()); X = xdisc.size(); Y = ydisc.size(); fenwick = map<int, map<int, int>>(); for (int i = 0; i < N; i++) { x1 = x[i]; y1 = y[i]; ia = lower_bound(xdisc.begin(), xdisc.end(), x1 - y1) - xdisc.begin() + 1; ib = lower_bound(ydisc.begin(), ydisc.end(), x1 + y1) - ydisc.begin() + 1; if ((S += query(ia, ib)) >= K) return true; ia = lower_bound(xdisc.begin(), xdisc.end(), x1 - y1 - d) - xdisc.begin() + 1; ib = lower_bound(xdisc.begin(), xdisc.end(), x1 - y1 + d) - xdisc.begin() + 1; ic = lower_bound(ydisc.begin(), ydisc.end(), x1 + y1 - d) - ydisc.begin() + 1; id = lower_bound(ydisc.begin(), ydisc.end(), x1 + y1 + d) - ydisc.begin() + 1; update(ia, ic, 1); update(ib + 1, ic, 0); update(ia, id + 1, 0); update(ib + 1, id + 1, 1); } return false; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> N >> K; x.resize(N); y.resize(N); for (int i = 0; i < N; i++) cin >> x[i] >> y[i]; int l = 0, r = 4e9, m, ans; while (l <= r) { m = (l + r) >> 1; if (check(m)) { ans = m; r = --m; } else { l = ++m; } } cout << ans; return 0; }

Compilation message (stderr)

road_construction.cpp: In function 'bool check(long long int)':
road_construction.cpp:55:39: error: no match for 'operator=' (operand types are 'std::unordered_map<long long int, std::unordered_map<long long int, long long int> >' and 'std::map<long long int, std::map<long long int, long long int> >')
   55 |     fenwick = map<int, map<int, int>>();
      |                                       ^
In file included from /usr/include/c++/10/unordered_map:47,
                 from /usr/include/c++/10/functional:61,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from road_construction.cpp:1:
/usr/include/c++/10/bits/unordered_map.h:271:7: note: candidate: 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(const std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&) [with _Key = long long int; _Tp = std::unordered_map<long long int, long long int>; _Hash = std::hash<long long int>; _Pred = std::equal_to<long long int>; _Alloc = std::allocator<std::pair<const long long int, std::unordered_map<long long int, long long int> > >]'
  271 |       operator=(const unordered_map&) = default;
      |       ^~~~~~~~
/usr/include/c++/10/bits/unordered_map.h:271:17: note:   no known conversion for argument 1 from 'std::map<long long int, std::map<long long int, long long int> >' to 'const std::unordered_map<long long int, std::unordered_map<long long int, long long int> >&'
  271 |       operator=(const unordered_map&) = default;
      |                 ^~~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/bits/unordered_map.h:275:7: note: candidate: 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&&) [with _Key = long long int; _Tp = std::unordered_map<long long int, long long int>; _Hash = std::hash<long long int>; _Pred = std::equal_to<long long int>; _Alloc = std::allocator<std::pair<const long long int, std::unordered_map<long long int, long long int> > >]'
  275 |       operator=(unordered_map&&) = default;
      |       ^~~~~~~~
/usr/include/c++/10/bits/unordered_map.h:275:17: note:   no known conversion for argument 1 from 'std::map<long long int, std::map<long long int, long long int> >' to 'std::unordered_map<long long int, std::unordered_map<long long int, long long int> >&&'
  275 |       operator=(unordered_map&&) = default;
      |                 ^~~~~~~~~~~~~~~
/usr/include/c++/10/bits/unordered_map.h:289:7: note: candidate: 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(std::initializer_list<typename std::_Hashtable<_Key, std::pair<const _Key, _Tp>, _Alloc, std::__detail::_Select1st, _Pred, _Hash, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<std::__not_<std::__and_<std::__is_fast_hash<_Hash>, std::__is_nothrow_invocable<const _Hash&, const _Key&> > >::value, false, true> >::value_type>) [with _Key = long long int; _Tp = std::unordered_map<long long int, long long int>; _Hash = std::hash<long long int>; _Pred = std::equal_to<long long int>; _Alloc = std::allocator<std::pair<const long long int, std::unordered_map<long long int, long long int> > >; typename std::_Hashtable<_Key, std::pair<const _Key, _Tp>, _Alloc, std::__detail::_Select1st, _Pred, _Hash, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<std::__not_<std::__and_<std::__is_fast_hash<_Hash>, std::__is_nothrow_invocable<const _Hash&, const _Key&> > >::value, false, true> >::value_type = std::pair<const long long int, std::unordered_map<long long int, long long int> >]'
  289 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/10/bits/unordered_map.h:289:46: note:   no known conversion for argument 1 from 'std::map<long long int, std::map<long long int, long long int> >' to 'std::initializer_list<std::pair<const long long int, std::unordered_map<long long int, long long int> > >'
  289 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~