Submission #359253

# Submission time Handle Problem Language Result Execution time Memory
359253 2021-01-26T14:19:18 Z Pety Rice Hub (IOI11_ricehub) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "ricehub.h"


using namespace std;

vector<long long>sum, v;

int cost (int l, int r) {
  int mij = (l + r) / 2;
  return 1ll * v[mij] * (mij - l + 1) - (sum[mij] - sum[l - 1]) + (sum[r] - sum[mij - 1]) - 1ll * (r - mij + 1) * v[mij];
}

int besthub (int n, int l, vector<int>x, long long b) {
  sum.resize(x.size());
  v = x;
  for (int i = 0; i < x.size(); i++)
    sum[i] = (i ? sum[i - 1] + x[i] : x[i]);
  int sol = 0;
  for (int i = 0; i < n; i++) {
    int st = i, dr = n - 1, ans = 0;
    while (st <= dr) {
      int mij = (st + dr) / 2;
      if (cost(st, mij) <= b) {
        ans = mij;
        st = mij + 1;
      }
      else
        dr = mij - 1;
    }
    sol = max(sol, ans - i + 1);
  }
  return sol;
}

/*int main () {
  cout << besthub(5, 20, {1, 2, 10, 12, 14}, 6);
  return 0;
}*/

Compilation message

ricehub.cpp: In function 'int besthub(int, int, std::vector<int>, long long int)':
ricehub.cpp:16:7: error: no match for 'operator=' (operand types are 'std::vector<long long int>' and 'std::vector<int>')
   16 |   v = x;
      |       ^
In file included from /usr/include/c++/9/vector:72,
                 from /usr/include/c++/9/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:86,
                 from ricehub.cpp:1:
/usr/include/c++/9/bits/vector.tcc:198:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  198 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/9/bits/vector.tcc:199:42: note:   no known conversion for argument 1 from 'std::vector<int>' to 'const std::vector<long long int>&'
  199 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/9/vector:67,
                 from /usr/include/c++/9/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:86,
                 from ricehub.cpp:1:
/usr/include/c++/9/bits/stl_vector.h:706:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  706 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:706:26: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::vector<long long int>&&'
  706 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/9/bits/stl_vector.h:727:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  727 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:727:46: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::initializer_list<long long int>'
  727 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
ricehub.cpp:17:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |   for (int i = 0; i < x.size(); i++)
      |                   ~~^~~~~~~~~~