Submission #659747

#TimeUsernameProblemLanguageResultExecution timeMemory
659747MahdiA Difficult(y) Choice (BOI21_books)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#include "books.h"
#pragma GCC optimize("Ofast")
using namespace std;
#define F first
#define S second
#define siz(v) (int)v.size()
typedef pair<ll, int> pii;
typedef long long ll;
const int N=1e5+5;
int n, k, s;
vector<pii>v;
vector<int>res;
ll a, num[N];

ll skm(int i){
    if(num[i]==0)
        return num[i]=skim(i);
    return num[i];
}

int bin(ll x){
    int l=-1, r=n;
    while(r-l>1){
        int m=(r+l)/2;
        if(skm(m+1)>x)
            r=m;
        else
            l=m;
    }
    return l;
}

void sol(){
    vector<int>w;
    ll sm=0;
    sort(v.begin(), v.end());
    /*for(pii fuk : v)
        cout<<"("<<fuk.F<<", "<<fuk.S<<") ";
    cout<<'\n';*/
    for(int i=0;i<k;++i){
        sm+=v[i].F;
        w.push_back(i);
    }
    w.push_back(siz(v));
    while(sm<a){
        bool kuf=0;
        for(int i=0;i<k;++i){
            if(w[i]+1!=w[i+1]){
                sm-=v[w[i]].F;
                sm+=v[w[i]+1].F;
                ++w[i];
                kuf=1;
                break;
            }
        }
        if(!kuf)
            impossible();
    }
    w.pop_back();
    for(int i=0;i<k;++i)
        w[i]=v[w[i]].S+1;
    answer(w);
}

void solve(int N, int K, long long A, int S) {
    n=N;k=K;a=A;s=S;
    int x=bin(a/k);
    ll sm=0, ls=1e18, h;
    bool z=0;
    //cout<<"aha : "<<x<<'\n';
    if(x==-1){
        vector<int>w;
        for(int j=1;j<=k;++j){
            sm+=skm(j);
            w.push_back(j);
        }
        if(sm<=2*a)
            answer(w);
        impossible();
    }
    for(int i=x;i<n && sm<a;++i){
        h=skm(i+1);
        sm+=h;
        v.push_back({h, i});
        if(h-ls>a){
            z=1;
            break;
        }
        ls=h;
    }
    if(z){
        ll hh=h;
        int j=x+siz(v)-1;
        sm-=h;
        for(int i=max(x-k+siz(v)-1, 0);i<x;++i){
            h=skm(i+1);
            sm+=h;
            v.push_back({h, i});
        }
        if(sm<a){
            sm=hh;
            vector<int>w;
            for(int i=1;i<k;++i){
                h=skm(i);
                sm+=h;
                w.push_back(i);
            }
            w.push_back(j+1);
            if(sm<=2*a)
                answer(w);
            impossible();
        }
        for(int i=max(x-k+1, 0);i<x-k+siz(v)-1;++i){
            h=skm(i+1);
            v.push_back({h, i});
        }
    }
    for(int i=max(0, x-k+1);i<x;++i){
        h=skm(i+1);
        v.push_back({h, i});
    }
    sol();
}

Compilation message (stderr)

books.cpp:8:14: error: 'll' was not declared in this scope
    8 | typedef pair<ll, int> pii;
      |              ^~
books.cpp:8:21: error: template argument 1 is invalid
    8 | typedef pair<ll, int> pii;
      |                     ^
books.cpp: In function 'void sol()':
books.cpp:5:11: error: request for member 'first' in 'v.std::vector<int>::operator[](((std::vector<int>::size_type)i))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
    5 | #define F first
      |           ^~~~~
books.cpp:42:18: note: in expansion of macro 'F'
   42 |         sm+=v[i].F;
      |                  ^
books.cpp:5:11: error: request for member 'first' in 'v.std::vector<int>::operator[](((std::vector<int>::size_type)w.std::vector<int>::operator[](((std::vector<int>::size_type)i))))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
    5 | #define F first
      |           ^~~~~
books.cpp:50:29: note: in expansion of macro 'F'
   50 |                 sm-=v[w[i]].F;
      |                             ^
books.cpp:5:11: error: request for member 'first' in 'v.std::vector<int>::operator[](((std::vector<int>::size_type)(w.std::vector<int>::operator[](((std::vector<int>::size_type)i)) + 1)))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
    5 | #define F first
      |           ^~~~~
books.cpp:51:31: note: in expansion of macro 'F'
   51 |                 sm+=v[w[i]+1].F;
      |                               ^
books.cpp:6:11: error: request for member 'second' in 'v.std::vector<int>::operator[](((std::vector<int>::size_type)w.std::vector<int>::operator[](((std::vector<int>::size_type)i))))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
    6 | #define S second
      |           ^~~~~~
books.cpp:62:22: note: in expansion of macro 'S'
   62 |         w[i]=v[w[i]].S+1;
      |                      ^
books.cpp: In function 'void solve(int, int, long long int, int)':
books.cpp:85:27: error: no matching function for call to 'std::vector<int>::push_back(<brace-enclosed initializer list>)'
   85 |         v.push_back({h, i});
      |                           ^
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 books.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const int&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
books.cpp:99:31: error: no matching function for call to 'std::vector<int>::push_back(<brace-enclosed initializer list>)'
   99 |             v.push_back({h, i});
      |                               ^
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 books.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const int&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
books.cpp:116:31: error: no matching function for call to 'std::vector<int>::push_back(<brace-enclosed initializer list>)'
  116 |             v.push_back({h, i});
      |                               ^
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 books.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const int&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
books.cpp:121:27: error: no matching function for call to 'std::vector<int>::push_back(<brace-enclosed initializer list>)'
  121 |         v.push_back({h, i});
      |                           ^
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 books.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const int&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~