Submission #751349

#TimeUsernameProblemLanguageResultExecution timeMemory
751349Desh03Aliens (IOI16_aliens)C++17
Compilation error
0 ms0 KiB
#include "aliens.h" #include <bits/stdc++.h> using namespace std; const long long INF = 1e18; struct point { long long x, y; bool operator < (const point &p) const { return x == p.x ? y < p.y : x < p.x; } }; struct line { long long m, c, s; line(const long long &m_, const long long &c_, const long long &s_) : m(m_), c(c_), s(s_), left(NULL), right(NULL) { }; long long eval(long long x) { return 1LL * m * x + c; } line *left, *right; }; long long N, M; vector<point> r; vector<long long> dp; vector<long long> cnt; struct lichaotree { line* root; lichaotree() : root(new line(0, INF, 0)) { }; line* insert(line* v, long long l, long long r, long long m_, long long c_, long long s_) { if (v == NULL || l == r) return new line(m_, c_, s_); long long m = l + r >> 1; if (v->eval(m) > 1LL * m_ * m + c_) swap(v->m, m_), swap(v->c, c_), swap(v->s, s_); if (v->eval(l) > 1LL * m_ * l + c_) v->left = insert(v->left, l, m, m_, c_, s_); else v->right = insert(v->right, m + 1, r, m_, c_, s_); return v; } pair<long long, long long> qry(line* &v, long long l, long long r, long long x) { if (v == NULL) return {INF, 0}; if (l == r) return {v->eval(x), v->s}; long long m = l + r >> 1; if (x <= m) return min({v->eval(x), v->s}, qry(v->left, l, m, x)); return min({v->eval(x), v->s}, qry(v->right, m + 1, r, x)); } void insert(long long m, long long c, long long s) { insert(root, 0, M, m, c, s); } pair<long long, long long> qry(long long x) { return qry(root, 0, M, x); } }; long long sq(long long x) { return 1LL * x * x; } void aliens(long long lambda) { lichaotree lct; lct.insert(-2 * r[0].x, sq(r[0].x) + 1 - 2 * r[0].x, 0); for (long long i = 0; i < N; i++) { auto [mn, cnt_] = lct.qry(r[i].y); dp[i] = mn + sq(r[i].y) + 2 * r[i].y + lambda; cnt[i] = cnt_ + 1; if (i < N - 1) { lct.insert(-2 * r[i + 1].x, dp[i] + sq(r[i + 1].x) - 2 * r[i + 1].x + 1 - sq(max(0, r[i].y - r[i + 1].x + 1)), cnt[i]); } } } long long take_photos(long long n, long long m, long long k, vector<long long> R, vector<long long> C) { vector<point> f; r = vector<point> (), M = m; for (long long i = 0; i < n; i++) { if (R[i] > C[i]) swap(R[i], C[i]); f.push_back({R[i], C[i]}); } sort(f.begin(), f.end()); r.push_back(f[0]); for (long long i = 1; i < n; i++) { if (r.back().x == f[i].x) { r.pop_back(); r.push_back(f[i]); } else if (f[i].y > r.back().y) { r.push_back(f[i]); } } N = r.size(); dp = vector<long long> (N), cnt = vector<long long> (N); long long l_ = 0, r_ = 1e13; while (l_ <= r_) { long long m_ = l_ + r_ >> 1; aliens(m_); if (l_ == r_) break; if (cnt[N - 1] > k) l_ = m_ + 1; else r_ = m_; } return dp[N - 1] - l_ * cnt[N - 1]; }

Compilation message (stderr)

aliens.cpp: In member function 'line* lichaotree::insert(line*, long long int, long long int, long long int, long long int, long long int)':
aliens.cpp:33:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   33 |         long long m = l + r >> 1;
      |                       ~~^~~
aliens.cpp: In member function 'std::pair<long long int, long long int> lichaotree::qry(line*&, long long int, long long int, long long int)':
aliens.cpp:44:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   44 |         long long m = l + r >> 1;
      |                       ~~^~~
aliens.cpp:45:31: error: could not convert 'std::min<long long int, std::pair<long long int, long long int> >(std::initializer_list<long long int>{((const long long int*)(& const long long int [2]{v->line::eval(x), v->line::s})), 2}, ((lichaotree*)this)->lichaotree::qry(v->line::left, l, m, x))' from 'long long int' to 'std::pair<long long int, long long int>'
   45 |         if (x <= m) return min({v->eval(x), v->s}, qry(v->left, l, m, x));
      |                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                               |
      |                               long long int
aliens.cpp:46:19: error: could not convert 'std::min<long long int, std::pair<long long int, long long int> >(std::initializer_list<long long int>{((const long long int*)(& const long long int [2]{v->line::eval(x), v->line::s})), 2}, ((lichaotree*)this)->lichaotree::qry(v->line::right, (m + 1), r, x))' from 'long long int' to 'std::pair<long long int, long long int>'
   46 |         return min({v->eval(x), v->s}, qry(v->right, m + 1, r, x));
      |                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                   |
      |                   long long int
aliens.cpp: In function 'void aliens(long long int)':
aliens.cpp:68:120: error: no matching function for call to 'max(int, long long int)'
   68 |             lct.insert(-2 * r[i + 1].x, dp[i] + sq(r[i + 1].x) - 2 * r[i + 1].x + 1 - sq(max(0, r[i].y - r[i + 1].x + 1)), cnt[i]);
      |                                                                                                                        ^
In file included from /usr/include/c++/10/vector:60,
                 from aliens.h:3,
                 from aliens.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
aliens.cpp:68:120: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   68 |             lct.insert(-2 * r[i + 1].x, dp[i] + sq(r[i + 1].x) - 2 * r[i + 1].x + 1 - sq(max(0, r[i].y - r[i + 1].x + 1)), cnt[i]);
      |                                                                                                                        ^
In file included from /usr/include/c++/10/vector:60,
                 from aliens.h:3,
                 from aliens.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
aliens.cpp:68:120: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   68 |             lct.insert(-2 * r[i + 1].x, dp[i] + sq(r[i + 1].x) - 2 * r[i + 1].x + 1 - sq(max(0, r[i].y - r[i + 1].x + 1)), cnt[i]);
      |                                                                                                                        ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from aliens.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
aliens.cpp:68:120: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   68 |             lct.insert(-2 * r[i + 1].x, dp[i] + sq(r[i + 1].x) - 2 * r[i + 1].x + 1 - sq(max(0, r[i].y - r[i + 1].x + 1)), cnt[i]);
      |                                                                                                                        ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from aliens.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
aliens.cpp:68:120: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   68 |             lct.insert(-2 * r[i + 1].x, dp[i] + sq(r[i + 1].x) - 2 * r[i + 1].x + 1 - sq(max(0, r[i].y - r[i + 1].x + 1)), cnt[i]);
      |                                                                                                                        ^
aliens.cpp: In function 'long long int take_photos(long long int, long long int, long long int, std::vector<long long int>, std::vector<long long int>)':
aliens.cpp:94:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   94 |         long long m_ = l_ + r_ >> 1;
      |                        ~~~^~~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:71,
                 from /usr/include/c++/10/vector:60,
                 from aliens.h:3,
                 from aliens.cpp:1:
/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 = const long long int*; _Iterator2 = const long long int*; _Compare = std::pair<long long int, long long int>]':
/usr/include/c++/10/bits/stl_algo.h:5636:12:   required from 'constexpr _ForwardIterator std::__min_element(_ForwardIterator, _ForwardIterator, _Compare) [with _ForwardIterator = const long long int*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<std::pair<long long int, long long int> >]'
/usr/include/c++/10/bits/stl_algo.h:5687:43:   required from 'constexpr _FIter std::min_element(_FIter, _FIter, _Compare) [with _FIter = const long long int*; _Compare = std::pair<long long int, long long int>]'
/usr/include/c++/10/bits/stl_algo.h:3475:31:   required from 'constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare) [with _Tp = long long int; _Compare = std::pair<long long int, long long int>]'
aliens.cpp:45:73:   required from here
/usr/include/c++/10/bits/predefined_ops.h:156:30: error: no match for call to '(std::pair<long long int, long long int>) (const long long int&, const long long int&)'
  156 |         { return bool(_M_comp(*__it1, *__it2)); }
      |                       ~~~~~~~^~~~~~~~~~~~~~~~