제출 #577458

#제출 시각아이디문제언어결과실행 시간메모리
577458Theo830커다란 상품 (IOI17_prize)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
const ll INF = 1e9+7;
const ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ll,ii>
#define ull unsigned int
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<ll> distr;
ll rnd(ll a, ll b){return distr(rng)%(b-a+1)+a;}
//int find_best(int n);
//std::vector<int> ask(int i);
#include "prize.h"
ll maxi = 0;
vector<int> ans[2000005];
ll Ask(ll x){
    if(ans[x].empty()){
        ans[x] = ask(x);
    }
    return ans[x];
}
ll solve(ll l,ll r,ll L,ll R){
    if(l > r){
        return -1;
    }
    ll mid = (l+r)/2;
    vector<int>res = Ask(mid);
    if(res[0] == 0 && res[1] == 0){
        return mid;
    }
    if(l == r){
        return -1;
    }
    ll ans = -1;
    ll left = mid,right = mid;
    ll cur = 0;
    while(res[0] + res[1] < maxi){
        if(cur == 0){
            left--;
            if(left >= l){
                res = Ask(left);
                if(res[0] == 0 && res[1] == 0){
                    return left;
                }
            }
        }
        else{
            right++;
            if(right <= r){
                res = Ask(right);
                if(res[0] == 0 && res[1] == 0){
                    return right;
                }
            }
        }
        if(left < l && right > r){
            break;
        }
        cur ^= 1;
    }
    if((res[0] + res[1]) == maxi){
        if(res[0] != L){
            ans = solve(l,left - 1,L,res[1]);
        }
        if(res[1] != R && ans == -1){
            ans = solve(right + 1,r,res[0],R);
        }
    }
    return ans;
}
int find_best(int n){
    ll k = 500;
    while(k--){
        vector<int> res = ask(rnd(0,n-1));
        maxi = max(maxi,res[0] + res[1]);
        if(res[0] + res[1] > 30){
            break;
        }
    }
    return solve(0,n-1,0,0);
}
/*
static const int max_q = 10000;
static int n;
static int query_count = 0;
vector<int> g;
static vector<vector<int> > rank_count;

vector<int> ask(int i) {
    //cout<<i<<endl;
    query_count++;
    if(query_count > max_q) {
        cerr << "Query limit exceeded" << endl;
        exit(0);
    }

    if(i < 0 || i >= n) {
        cerr << "Bad index: " << i << endl;
        exit(0);
    }

    vector<int> res(2);
    res[0] = rank_count[g[i] - 1][i + 1];
    res[1] = rank_count[g[i] - 1][n] - res[0];
    return res;
}

int main() {
    n = 1 + 2 + 5 + 30 + 200000;
    g.pb(1);
    g.pb(2);
    g.pb(2);
    f(k,0,5){
        g.pb(3);
    }
    f(k,0,30){
        g.pb(4);
    }
    f(k,0,200000){
        g.pb(5);
    }
    random_shuffle(all(g));
    int max_rank = *max_element(g.begin(), g.end());

    rank_count.resize(max_rank + 1, vector<int>(n + 1, 0));
    for(int r = 0; r <= max_rank; r++) {
        for(int i = 1; i <= n; i++) {
            rank_count[r][i] = rank_count[r][i - 1];
            if(g[i - 1] == r)
              rank_count[r][i]++;
        }
    }

    for(int i = 0; i <= n; i++)
        for(int r = 1; r <= max_rank; r++)
            rank_count[r][i] += rank_count[r - 1][i];
    int res = find_best(n);
    assert(g[res] == 1);
    cout << res << endl << "Query count: " << query_count << endl;

    return 0;
}
*/

컴파일 시 표준 에러 (stderr) 메시지

prize.cpp: In function 'll Ask(ll)':
prize.cpp:38:17: error: cannot convert 'std::vector<int>' to 'll' {aka 'int'} in return
   38 |     return ans[x];
      |            ~~~~~^
      |                 |
      |                 std::vector<int>
prize.cpp: In function 'll solve(ll, ll, ll, ll)':
prize.cpp:45:25: error: conversion from 'll' {aka 'int'} to non-scalar type 'std::vector<int>' requested
   45 |     vector<int>res = Ask(mid);
      |                      ~~~^~~~~
prize.cpp:59:31: error: no match for 'operator=' (operand types are 'std::vector<int>' and 'll' {aka 'int'})
   59 |                 res = Ask(left);
      |                               ^
In file included from /usr/include/c++/10/vector:72,
                 from /usr/include/c++/10/functional:62,
                 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 prize.cpp:1:
/usr/include/c++/10/bits/vector.tcc:198:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]'
  198 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/bits/vector.tcc:199:42: note:   no known conversion for argument 1 from 'll' {aka 'int'} to 'const std::vector<int>&'
  199 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 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 prize.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:709:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = int; _Alloc = std::allocator<int>]'
  709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:709:26: note:   no known conversion for argument 1 from 'll' {aka 'int'} to 'std::vector<int>&&'
  709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:730:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>]'
  730 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:730:46: note:   no known conversion for argument 1 from 'll' {aka 'int'} to 'std::initializer_list<int>'
  730 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
prize.cpp:68:32: error: no match for 'operator=' (operand types are 'std::vector<int>' and 'll' {aka 'int'})
   68 |                 res = Ask(right);
      |                                ^
In file included from /usr/include/c++/10/vector:72,
                 from /usr/include/c++/10/functional:62,
                 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 prize.cpp:1:
/usr/include/c++/10/bits/vector.tcc:198:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]'
  198 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/bits/vector.tcc:199:42: note:   no known conversion for argument 1 from 'll' {aka 'int'} to 'const std::vector<int>&'
  199 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 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 prize.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:709:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = int; _Alloc = std::allocator<int>]'
  709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:709:26: note:   no known conversion for argument 1 from 'll' {aka 'int'} to 'std::vector<int>&&'
  709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:730:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>]'
  730 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:730:46: note:   no known conversion for argument 1 from 'll' {aka 'int'} to 'std::initializer_list<int>'
  730 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~