Submission #852356

#TimeUsernameProblemLanguageResultExecution timeMemory
852356adaawfHoliday (IOI14_holiday)C++14
Compilation error
0 ms0 KiB
#include <iostream> #include <vector> #include <algorithm> #include "holiday.h" using namespace std; pair<int, int> a[100005]; long long f[100005], g[100005], res = 0; int d; struct DAY { long long int res, c; }; DAY t[400005]; void update(int v, int x) { v += 100005; if (res < 0) t[v].c = 0; else t[v].c = 1; t[v].res += x; v /= 2; while (v > 0) { t[v].c = t[v * 2].c + t[v * 2 + 1].c; t[v].res = t[v * 2].res + t[v * 2 + 1].res; v /= 2; } } long long int sum(int v, int l, int r, int x) { if (t[v].c == 0 || x <= 0) return 0; if (t[v].c <= x) return t[v].res; int mid = (l + r) / 2; if (t[v * 2 + 1].c >= x) return sum(v * 2 + 1, mid + 1, r, x); return t[v * 2 + 1].res + sum(v * 2, l, mid, x - t[v * 2 + 1].c); } int ll = 0, rr = -1; void trya(int x, int y) { while (ll > x) { ll--; update(a[ll].second, a[ll].first); } while (rr < y) { rr++; update(a[rr].second, a[rr].first); } while (ll < x) { update(a[ll].second, -a[ll].first); ll++; } while (rr > y) { update(a[rr].second, -a[rr].first); rr--; } } void dnc(int l, int r, int x, int y, int k) { if (l > r) return; int mid = (l + r) / 2; trya(x, mid); int h = x; for (int i = x; i <= min(mid, y) && i <= k; i++) { int c = (k - i) + (mid - i); if (d - c > 0) { long long int k = sum(1, 0, 100004, d - c); if (f[mid] <= k) { f[mid] = k; res = max(res, k); h = i; } } update(a[i].second, -a[i].first); ll++; } dnc(l, mid - 1, x, h, k); dnc(mid + 1, r, h, y, k); } void dnc2(int l, int r, int x, int y, int k) { if (l > r) return; int mid = (l + r) / 2; trya(mid, y); int h = y; for (int i = y; i >= max(mid, x) && i >= k; i--) { int c = (i - k) + (i - mid); if (d - c > 0) { long long k = sum(1, 0, 100004, d - c); if (g[mid] <= k) { g[mid] = k; res = max(res, k); h = i; } } update(a[i].second, -a[i].first); rr--; } dnc2(l, mid - 1, x, h, k); dnc2(mid + 1, r, h, y, k); } long long int findMaxAttraction(int n, int k, int dd, int attraction[]) { vector<pair<int, int>> v; for (int i = 0; i < n; i++) { v.push_back({attraction[i], i}); } sort(v.begin(), v.end()); for (int i = 0; i < n; i++) { a[v[i].second] = {v[i].first, id}; } d = dd; dnc(k, n - 1, 0, n - 1, k); dnc2(0, k, 0, n - 1, k); return res; }

Compilation message (stderr)

holiday.cpp: In function 'long long int findMaxAttraction(int, int, int, int*)':
holiday.cpp:100:33: error: 'id' was not declared in this scope; did you mean 'i'?
  100 |   a[v[i].second] = {v[i].first, id};
      |                                 ^~
      |                                 i
holiday.cpp:100:35: error: no match for 'operator=' (operand types are 'std::pair<int, int>' and '<brace-enclosed initializer list>')
  100 |   a[v[i].second] = {v[i].first, id};
      |                                   ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from holiday.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:390:7: note: candidate: 'std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(typename std::conditional<std::__and_<std::is_copy_assignable<_T1>, std::is_copy_assignable<_T2> >::value, const std::pair<_T1, _T2>&, const std::__nonesuch&>::type) [with _T1 = int; _T2 = int; typename std::conditional<std::__and_<std::is_copy_assignable<_T1>, std::is_copy_assignable<_T2> >::value, const std::pair<_T1, _T2>&, const std::__nonesuch&>::type = const std::pair<int, int>&]'
  390 |       operator=(typename conditional<
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_pair.h:393:41: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::conditional<true, const std::pair<int, int>&, const std::__nonesuch&>::type' {aka 'const std::pair<int, int>&'}
  390 |       operator=(typename conditional<
      |                 ~~~~~~~~~~~~~~~~~~~~~    
  391 |   __and_<is_copy_assignable<_T1>,
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~        
  392 |          is_copy_assignable<_T2>>::value,
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  393 |   const pair&, const __nonesuch&>::type __p)
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_pair.h:401:7: note: candidate: 'std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(typename std::conditional<std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value, std::pair<_T1, _T2>&&, std::__nonesuch&&>::type) [with _T1 = int; _T2 = int; typename std::conditional<std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value, std::pair<_T1, _T2>&&, std::__nonesuch&&>::type = std::pair<int, int>&&]'
  401 |       operator=(typename conditional<
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_pair.h:404:31: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::conditional<true, std::pair<int, int>&&, std::__nonesuch&&>::type' {aka 'std::pair<int, int>&&'}
  401 |       operator=(typename conditional<
      |                 ~~~~~~~~~~~~~~~~~~~~~
  402 |   __and_<is_move_assignable<_T1>,
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  403 |          is_move_assignable<_T2>>::value,
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  404 |   pair&&, __nonesuch&&>::type __p)
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_pair.h:418:2: note: candidate: 'template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<_T1&, const _U1&>, std::is_assignable<_T2&, const _U2&> >::value, std::pair<_T1, _T2>&>::type std::pair<_T1, _T2>::operator=(const std::pair<_U1, _U2>&) [with _U1 = _U1; _U2 = _U2; _T1 = int; _T2 = int]'
  418 |  operator=(const pair<_U1, _U2>& __p)
      |  ^~~~~~~~
/usr/include/c++/10/bits/stl_pair.h:418:2: note:   template argument deduction/substitution failed:
holiday.cpp:100:35: note:   couldn't deduce template parameter '_U1'
  100 |   a[v[i].second] = {v[i].first, id};
      |                                   ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from holiday.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:430:2: note: candidate: 'template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<_T1&, _U1&&>, std::is_assignable<_T2&, _U2&&> >::value, std::pair<_T1, _T2>&>::type std::pair<_T1, _T2>::operator=(std::pair<_U1, _U2>&&) [with _U1 = _U1; _U2 = _U2; _T1 = int; _T2 = int]'
  430 |  operator=(pair<_U1, _U2>&& __p)
      |  ^~~~~~~~
/usr/include/c++/10/bits/stl_pair.h:430:2: note:   template argument deduction/substitution failed:
holiday.cpp:100:35: note:   couldn't deduce template parameter '_U1'
  100 |   a[v[i].second] = {v[i].first, id};
      |                                   ^