Submission #772725

#TimeUsernameProblemLanguageResultExecution timeMemory
772725ZHIRDILBILDIZA Difficult(y) Choice (BOI21_books)C++14
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
#include"books.h"
#define ll long long
#define fi first
#define se second
using namespace std ;
//void impossible()
//{
//    cout << "-1\n" ;
//    exit(0) ;
//}
//void answer(vector<int> ans)
//{
//    for(int i : ans)
//        cout << i << ' ' ;
//    exit(0) ;
//}
//ll skim(int ind)
//{
//    cout << "? " << ind << '\n' ;
//    return ind ;
//}
void solve(int n, int k, ll a, int s)
{
    vector<int> ans ;
    ll x[n + 1] = {} ;
    if(s >= n)
    {
        set<pair<ll, int>> s ;
        ll pref[n + 1] = {} ;
        for(int i = 1 ; i <= n ; i++)
        {
            x[i] = skim(i) ;
            s.insert({x[i], i}) ;
            pref[i] = pref[i - 1] + x[i] ;
        }
        if(k == 3 && n <= 1000)
        {
            for(int i = 1 ; i <= n ; i++)
                for(int j = i + 1 ; j <= n ; j++)
                    ll sum = a - x[i] - x[j], sum1 = x[i] + x[j] ;
                    if(a <= (*s.upper_bound({sum - 1, 0})).fi + sum1 && (*s.upper_bound({sum - 1, 0})).fi + sum1 <= 2 * a)
                    {
                        ans.push_back(i) ;
                        ans.push_back(j) ;
                        ans.push_back((*s.upper_bound({sum - 1, 0})).se) ;
                        answer(ans) ;
                    }
            impossible() ;
        }
        for(int i = k ; i <= n ; i++)
            if(a <= pref[i] - pref[i - k] && pref[i] - pref[i - k] <= 2ll * a)
            {
                for(int j = i - k + 1 ; j <= i ; j++)
                    ans.push_back(j) ;
                answer(ans) ;
            }
        impossible() ;
    }
    ll l = 0, r = n - k + 1 ;
    vector<pair<ll, int>> w, ls ;
    while(l + 1 < r)
    {
        w.clear() ;
        ll mid = (l + r) >> 1, sum = 0 ;
        for(int i = mid ; i < mid + k ; i++)
        {
            ll num = skim(i) ;
            sum += num ;
            w.push_back({num, i}) ;
        }
        if(sum > 2 * a)r = mid ;
        else
        {
            ls = w ;
            ans.clear() ;
            for(auto i : w)
                ans.push_back(i.se) ;
            l = mid ;
        }
    }
    ll sum = 0 ;
    for(auto i : ls)
        sum += i.fi ;
    if(a <= sum && sum <= 2 * a)
        answer(ans) ;
    else
        impossible() ;
}
//signed main()
//{
//    int n, k, a, s ;
//    cin >> n >> k >> a >> s ;
//    solve(n, k, a, s) ;
//    return 0 ;
//}

Compilation message (stderr)

books.cpp: In function 'void solve(int, int, long long int, int)':
books.cpp:41:24: warning: unused variable 'sum' [-Wunused-variable]
   41 |                     ll sum = a - x[i] - x[j], sum1 = x[i] + x[j] ;
      |                        ^~~
books.cpp:41:47: warning: unused variable 'sum1' [-Wunused-variable]
   41 |                     ll sum = a - x[i] - x[j], sum1 = x[i] + x[j] ;
      |                                               ^~~~
books.cpp:42:46: error: 'sum' was not declared in this scope
   42 |                     if(a <= (*s.upper_bound({sum - 1, 0})).fi + sum1 && (*s.upper_bound({sum - 1, 0})).fi + sum1 <= 2 * a)
      |                                              ^~~
books.cpp:42:57: error: no matching function for call to 'std::set<std::pair<long long int, int> >::upper_bound(<brace-enclosed initializer list>)'
   42 |                     if(a <= (*s.upper_bound({sum - 1, 0})).fi + sum1 && (*s.upper_bound({sum - 1, 0})).fi + sum1 <= 2 * a)
      |                                                         ^
In file included from /usr/include/c++/10/set:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:87,
                 from books.cpp:1:
/usr/include/c++/10/bits/stl_set.h:859:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::upper_bound(const key_type&) [with _Key = std::pair<long long int, int>; _Compare = std::less<std::pair<long long int, int> >; _Alloc = std::allocator<std::pair<long long int, int> >; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree<std::pair<long long int, int>, std::pair<long long int, int>, std::_Identity<std::pair<long long int, int> >, std::less<std::pair<long long int, int> >, std::allocator<std::pair<long long int, int> > >::const_iterator; std::set<_Key, _Compare, _Alloc>::key_type = std::pair<long long int, int>]'
  859 |       upper_bound(const key_type& __x)
      |       ^~~~~~~~~~~
/usr/include/c++/10/bits/stl_set.h:859:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const key_type&' {aka 'const std::pair<long long int, int>&'}
  859 |       upper_bound(const key_type& __x)
      |                   ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_set.h:863:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::const_iterator std::set<_Key, _Compare, _Alloc>::upper_bound(const key_type&) const [with _Key = std::pair<long long int, int>; _Compare = std::less<std::pair<long long int, int> >; _Alloc = std::allocator<std::pair<long long int, int> >; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree<std::pair<long long int, int>, std::pair<long long int, int>, std::_Identity<std::pair<long long int, int> >, std::less<std::pair<long long int, int> >, std::allocator<std::pair<long long int, int> > >::const_iterator; std::set<_Key, _Compare, _Alloc>::key_type = std::pair<long long int, int>]'
  863 |       upper_bound(const key_type& __x) const
      |       ^~~~~~~~~~~
/usr/include/c++/10/bits/stl_set.h:863:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const key_type&' {aka 'const std::pair<long long int, int>&'}
  863 |       upper_bound(const key_type& __x) const
      |                   ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_set.h:869:2: note: candidate: 'template<class _Kt> decltype ((std::set<_Key, _Compare, _Alloc>::iterator)(((std::set<_Key, _Compare, _Alloc>*)this)->std::set<_Key, _Compare, _Alloc>::_M_t._M_upper_bound_tr(__x))) std::set<_Key, _Compare, _Alloc>::upper_bound(const _Kt&) [with _Kt = _Kt; _Key = std::pair<long long int, int>; _Compare = std::less<std::pair<long long int, int> >; _Alloc = std::allocator<std::pair<long long int, int> >]'
  869 |  upper_bound(const _Kt& __x)
      |  ^~~~~~~~~~~
/usr/include/c++/10/bits/stl_set.h:869:2: note:   template argument deduction/substitution failed:
books.cpp:42:57: note:   couldn't deduce template parameter '_Kt'
   42 |                     if(a <= (*s.upper_bound({sum - 1, 0})).fi + sum1 && (*s.upper_bound({sum - 1, 0})).fi + sum1 <= 2 * a)
      |                                                         ^
In file included from /usr/include/c++/10/set:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:87,
                 from books.cpp:1:
/usr/include/c++/10/bits/stl_set.h:875:2: note: candidate: 'template<class _Kt> decltype ((std::set<_Key, _Compare, _Alloc>::iterator)(((const std::set<_Key, _Compare, _Alloc>*)this)->std::set<_Key, _Compare, _Alloc>::_M_t._M_upper_bound_tr(__x))) std::set<_Key, _Compare, _Alloc>::upper_bound(const _Kt&) const [with _Kt = _Kt; _Key = std::pair<long long int, int>; _Compare = std::less<std::pair<long long int, int> >; _Alloc = std::allocator<std::pair<long long int, int> >]'
  875 |  upper_bound(const _Kt& __x) const
      |  ^~~~~~~~~~~
/usr/include/c++/10/bits/stl_set.h:875:2: note:   template argument deduction/substitution failed:
books.cpp:42:57: note:   couldn't deduce template parameter '_Kt'
   42 |                     if(a <= (*s.upper_bound({sum - 1, 0})).fi + sum1 && (*s.upper_bound({sum - 1, 0})).fi + sum1 <= 2 * a)
      |                                                         ^
books.cpp:42:65: error: 'sum1' was not declared in this scope
   42 |                     if(a <= (*s.upper_bound({sum - 1, 0})).fi + sum1 && (*s.upper_bound({sum - 1, 0})).fi + sum1 <= 2 * a)
      |                                                                 ^~~~
books.cpp:42:101: error: no matching function for call to 'std::set<std::pair<long long int, int> >::upper_bound(<brace-enclosed initializer list>)'
   42 |                     if(a <= (*s.upper_bound({sum - 1, 0})).fi + sum1 && (*s.upper_bound({sum - 1, 0})).fi + sum1 <= 2 * a)
      |                                                                                                     ^
In file included from /usr/include/c++/10/set:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:87,
                 from books.cpp:1:
/usr/include/c++/10/bits/stl_set.h:859:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::upper_bound(const key_type&) [with _Key = std::pair<long long int, int>; _Compare = std::less<std::pair<long long int, int> >; _Alloc = std::allocator<std::pair<long long int, int> >; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree<std::pair<long long int, int>, std::pair<long long int, int>, std::_Identity<std::pair<long long int, int> >, std::less<std::pair<long long int, int> >, std::allocator<std::pair<long long int, int> > >::const_iterator; std::set<_Key, _Compare, _Alloc>::key_type = std::pair<long long int, int>]'
  859 |       upper_bound(const key_type& __x)
      |       ^~~~~~~~~~~
/usr/include/c++/10/bits/stl_set.h:859:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const key_type&' {aka 'const std::pair<long long int, int>&'}
  859 |       upper_bound(const key_type& __x)
      |                   ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_set.h:863:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::const_iterator std::set<_Key, _Compare, _Alloc>::upper_bound(const key_type&) const [with _Key = std::pair<long long int, int>; _Compare = std::less<std::pair<long long int, int> >; _Alloc = std::allocator<std::pair<long long int, int> >; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree<std::pair<long long int, int>, std::pair<long long int, int>, std::_Identity<std::pair<long long int, int> >, std::less<std::pair<long long int, int> >, std::allocator<std::pair<long long int, int> > >::const_iterator; std::set<_Key, _Compare, _Alloc>::key_type = std::pair<long long int, int>]'
  863 |       upper_bound(const key_type& __x) const
      |       ^~~~~~~~~~~
/usr/include/c++/10/bits/stl_set.h:863:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const key_type&' {aka 'const std::pair<long long int, int>&'}
  863 |       upper_bound(const key_type& __x) const
      |                   ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_set.h:869:2: note: candidate: 'template<class _Kt> decltype ((std::set<_Key, _Compare, _Alloc>::iterator)(((std::set<_Key, _Compare, _Alloc>*)this)->std::set<_Key, _Compare, _Alloc>::_M_t._M_upper_bound_tr(__x))) std::set<_Key, _Compare, _Alloc>::upper_bound(const _Kt&) [with _Kt = _Kt; _Key = std::pair<long long int, int>; _Compare = std::less<std::pair<long long int, int> >; _Alloc = std::allocator<std::pair<long long int, int> >]'
  869 |  upper_bound(const _Kt& __x)
      |  ^~~~~~~~~~~
/usr/include/c++/10/bits/stl_set.h:869:2: note:   template argument deduction/substitution failed:
books.cpp:42:101: note:   couldn't deduce template parameter '_Kt'
   42 |                     if(a <= (*s.upper_bound({sum - 1, 0})).fi + sum1 && (*s.upper_bound({sum - 1, 0})).fi + sum1 <= 2 * a)
      |                                                                                                     ^
In file included from /usr/include/c++/10/set:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:87,
                 from books.cpp:1:
/usr/include/c++/10/bits/stl_set.h:875:2: note: candidate: 'template<class _Kt> decltype ((std::set<_Key, _Compare, _Alloc>::iterator)(((const std::set<_Key, _Compare, _Alloc>*)this)->std::set<_Key, _Compare, _Alloc>::_M_t._M_upper_bound_tr(__x))) std::set<_Key, _Compare, _Alloc>::upper_bound(const _Kt&) const [with _Kt = _Kt; _Key = std::pair<long long int, int>; _Compare = std::less<std::pair<long long int, int> >; _Alloc = std::allocator<std::pair<long long int, int> >]'
  875 |  upper_bound(const _Kt& __x) const
      |  ^~~~~~~~~~~
/usr/include/c++/10/bits/stl_set.h:875:2: note:   template argument deduction/substitution failed:
books.cpp:42:101: note:   couldn't deduce template parameter '_Kt'
   42 |                     if(a <= (*s.upper_bound({sum - 1, 0})).fi + sum1 && (*s.upper_bound({sum - 1, 0})).fi + sum1 <= 2 * a)
      |                                                                                                     ^
books.cpp:44:39: error: 'i' was not declared in this scope
   44 |                         ans.push_back(i) ;
      |                                       ^
books.cpp:45:39: error: 'j' was not declared in this scope
   45 |                         ans.push_back(j) ;
      |                                       ^
books.cpp:46:67: error: no matching function for call to 'std::set<std::pair<long long int, int> >::upper_bound(<brace-enclosed initializer list>)'
   46 |                         ans.push_back((*s.upper_bound({sum - 1, 0})).se) ;
      |                                                                   ^
In file included from /usr/include/c++/10/set:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:87,
                 from books.cpp:1:
/usr/include/c++/10/bits/stl_set.h:859:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::upper_bound(const key_type&) [with _Key = std::pair<long long int, int>; _Compare = std::less<std::pair<long long int, int> >; _Alloc = std::allocator<std::pair<long long int, int> >; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree<std::pair<long long int, int>, std::pair<long long int, int>, std::_Identity<std::pair<long long int, int> >, std::less<std::pair<long long int, int> >, std::allocator<std::pair<long long int, int> > >::const_iterator; std::set<_Key, _Compare, _Alloc>::key_type = std::pair<long long int, int>]'
  859 |       upper_bound(const key_type& __x)
      |       ^~~~~~~~~~~
/usr/include/c++/10/bits/stl_set.h:859:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const key_type&' {aka 'const std::pair<long long int, int>&'}
  859 |       upper_bound(const key_type& __x)
      |                   ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_set.h:863:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::const_iterator std::set<_Key, _Compare, _Alloc>::upper_bound(const key_type&) const [with _Key = std::pair<long long int, int>; _Compare = std::less<std::pair<long long int, int> >; _Alloc = std::allocator<std::pair<long long int, int> >; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree<std::pair<long long int, int>, std::pair<long long int, int>, std::_Identity<std::pair<long long int, int> >, std::less<std::pair<long long int, int> >, std::allocator<std::pair<long long int, int> > >::const_iterator; std::set<_Key, _Compare, _Alloc>::key_type = std::pair<long long int, int>]'
  863 |       upper_bound(const key_type& __x) const
      |       ^~~~~~~~~~~
/usr/include/c++/10/bits/stl_set.h:863:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const key_type&' {aka 'const std::pair<long long int, int>&'}
  863 |       upper_bound(const key_type& __x) const
      |                   ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_set.h:869:2: note: candidate: 'template<class _Kt> decltype ((std::set<_Key, _Compare, _Alloc>::iterator)(((std::set<_Key, _Compare, _Alloc>*)this)->std::set<_Key, _Compare, _Alloc>::_M_t._M_upper_bound_tr(__x))) std::set<_Key, _Compare, _Alloc>::upper_bound(const _Kt&) [with _Kt = _Kt; _Key = std::pair<long long int, int>; _Compare = std::less<std::pair<long long int, int> >; _Alloc = std::allocator<std::pair<long long int, int> >]'
  869 |  upper_bound(const _Kt& __x)
      |  ^~~~~~~~~~~
/usr/include/c++/10/bits/stl_set.h:869:2: note:   template argument deduction/substitution failed:
books.cpp:46:67: note:   couldn't deduce template parameter '_Kt'
   46 |                         ans.push_back((*s.upper_bound({sum - 1, 0})).se) ;
      |                                                                   ^
In file included from /usr/include/c++/10/set:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:87,
                 from books.cpp:1:
/usr/include/c++/10/bits/stl_set.h:875:2: note: candidate: 'template<class _Kt> decltype ((std::set<_Key, _Compare, _Alloc>::iterator)(((const std::set<_Key, _Compare, _Alloc>*)this)->std::set<_Key, _Compare, _Alloc>::_M_t._M_upper_bound_tr(__x))) std::set<_Key, _Compare, _Alloc>::upper_bound(const _Kt&) const [with _Kt = _Kt; _Key = std::pair<long long int, int>; _Compare = std::less<std::pair<long long int, int> >; _Alloc = std::allocator<std::pair<long long int, int> >]'
  875 |  upper_bound(const _Kt& __x) const
      |  ^~~~~~~~~~~
/usr/include/c++/10/bits/stl_set.h:875:2: note:   template argument deduction/substitution failed:
books.cpp:46:67: note:   couldn't deduce template parameter '_Kt'
   46 |                         ans.push_back((*s.upper_bound({sum - 1, 0})).se) ;
      |                                                                   ^