Submission #1161505

#TimeUsernameProblemLanguageResultExecution timeMemory
1161505RiverFlowThe Big Prize (IOI17_prize)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> // #define LOCAL #ifndef LOCAL #include "prize.h" #endif #define nl "\n" #define no "NO" #define yes "YES" #define fi first #define se second #define vec vector #define task "main" #define _mp make_pair #define ii pair<int, int> #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define evoid(val) return void(std::cout << val) #define FOR(i, a, b) for(int i = (a); i <= (b); ++i) #define FOD(i, b, a) for(int i = (b); i >= (a); --i) #define unq(x) sort(all(x)); x.resize(unique(all(x)) - x.begin()) using namespace std; template<typename U, typename V> bool maxi(U &a, V b) { if (a < b) { a = b; return 1; } return 0; } template<typename U, typename V> bool mini(U &a, V b) { if (a > b) { a = b; return 1; } return 0; } const int N = (int)2e5 + 9; const int mod = (int)1e9 + 7; void prepare(); void main_code(); #ifdef LOCAL int n, a[N]; array<int, 2> ask(int i) { int x = 0, y = 0; for(int j = i - 1; j >= 0; --j) x += a[i] > a[j]; for(int j = i + 1; j < n; ++j) y += a[i] > a[j]; return {x, y}; } #endif array<int, 2> d[N]; int find_best(int n) { srand(time(NULL)); vector<int> b(n); iota(all(b), 0); random_shuffle(all(b)); FOR(i, 0, n - 1) d[i] = {-1, -1}; int mx = 0, luu = -1; for(int i = 0; i < min(n, 500); ++i) { d[ b[i] ] = ask(b[i]); int x = d[b[i]][0] + d[b[i]][1]; if (x == 0) return b[i]; if (x > mx) { mx = x, luu = b[i]; } } //chi can y ma tang len int x=d[luu][0], y=d[luu][1]; int tx=x, ty=y; for(int i = luu; x>0; ){ //tim vi tri tiep theo y thay doi int lb = 0, rb=i-1, pos=-1; while(lb<=rb){ int mid=(lb+rb)>>1; if (d[mid][0]==-1)d[mid]=ask(mid); int v = d[mid][0] + d[mid][1]; if (v == 0) return mid; if (v == mx) { if (d[mid][1] - y - (mx - (x + y)) > 0) { rb=mid+1; }else{ lb=mid-1; } }else{ pos=mid, lb=mid+1; } } i=pos; --x; } x=tx, y=ty; for(int i = luu; y>0; ){ //tim vi tri tiep theo y thay doi int lb = i+1, rb=n-1, pos=-1; while(lb<=rb){ int mid=(lb+rb)>>1; if (d[mid][0]==-1)d[mid]=ask(mid); int v = d[mid][0] + d[mid][1]; if (v == 0) return mid; if (v == mx) { if (d[mid][0] - x - (mx - (x + y)) > 0) { lb=mid-1; }else{ rb=mid+1; } }else{ pos=mid, rb=mid-1; } } i=pos; --y; } return 0; } #ifdef LOCAL int main() { freopen("main.inp", "r", stdin); cin >> n; for(int i = 0; i < n; ++i) cin >> a[i]; int x = find_best(n); cout << x << nl; } #endif /* Let the river flows naturally */

Compilation message (stderr)

prize.cpp: In function 'int find_best(int)':
prize.cpp:62:29: error: no match for 'operator=' (operand types are 'std::array<int, 2>' and 'std::vector<int>')
   62 |         d[ b[i] ] = ask(b[i]);
      |                             ^
In file included from /usr/include/c++/11/tuple:39,
                 from /usr/include/c++/11/functional:54,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from prize.cpp:1:
/usr/include/c++/11/array:95:12: note: candidate: 'constexpr std::array<int, 2>& std::array<int, 2>::operator=(const std::array<int, 2>&)'
   95 |     struct array
      |            ^~~~~
/usr/include/c++/11/array:95:12: note:   no known conversion for argument 1 from 'std::vector<int>' to 'const std::array<int, 2>&'
/usr/include/c++/11/array:95:12: note: candidate: 'constexpr std::array<int, 2>& std::array<int, 2>::operator=(std::array<int, 2>&&)'
/usr/include/c++/11/array:95:12: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::array<int, 2>&&'
prize.cpp:78:45: error: no match for 'operator=' (operand types are 'std::array<int, 2>' and 'std::vector<int>')
   78 |             if (d[mid][0]==-1)d[mid]=ask(mid);
      |                                             ^
In file included from /usr/include/c++/11/tuple:39,
                 from /usr/include/c++/11/functional:54,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from prize.cpp:1:
/usr/include/c++/11/array:95:12: note: candidate: 'constexpr std::array<int, 2>& std::array<int, 2>::operator=(const std::array<int, 2>&)'
   95 |     struct array
      |            ^~~~~
/usr/include/c++/11/array:95:12: note:   no known conversion for argument 1 from 'std::vector<int>' to 'const std::array<int, 2>&'
/usr/include/c++/11/array:95:12: note: candidate: 'constexpr std::array<int, 2>& std::array<int, 2>::operator=(std::array<int, 2>&&)'
/usr/include/c++/11/array:95:12: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::array<int, 2>&&'
prize.cpp:100:45: error: no match for 'operator=' (operand types are 'std::array<int, 2>' and 'std::vector<int>')
  100 |             if (d[mid][0]==-1)d[mid]=ask(mid);
      |                                             ^
In file included from /usr/include/c++/11/tuple:39,
                 from /usr/include/c++/11/functional:54,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from prize.cpp:1:
/usr/include/c++/11/array:95:12: note: candidate: 'constexpr std::array<int, 2>& std::array<int, 2>::operator=(const std::array<int, 2>&)'
   95 |     struct array
      |            ^~~~~
/usr/include/c++/11/array:95:12: note:   no known conversion for argument 1 from 'std::vector<int>' to 'const std::array<int, 2>&'
/usr/include/c++/11/array:95:12: note: candidate: 'constexpr std::array<int, 2>& std::array<int, 2>::operator=(std::array<int, 2>&&)'
/usr/include/c++/11/array:95:12: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::array<int, 2>&&'