Submission #395728

# Submission time Handle Problem Language Result Execution time Memory
395728 2021-04-28T20:03:21 Z Victor Library (JOI18_library) C++17
Compilation error
0 ms 0 KB
#include "library.h"

#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define per(i, a, b) for (int i = b - 1; i >= (a); --i)
#define trav(a, x) for (auto& a : x)

#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back

#define umap unordered_map
#define uset unordered_set

typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;

const int INF = 1000000007;

vi dummy;
int book = 0;
uset<int> queried;

int binsearch(vi books) {
    vi qvec = dummy;
    qvec[book] = 1;

    if (sz(books) == 1) {
        qvec[books[0]] = 1;
        if (Query(qvec) != 1)
            return -1;
        else
            return books[0];
    }

    int take = sz(books) >> 1;

    rep(i, 0, take) qvec[books[i]] = 1;

    int moves = Query(qvec);
    qvec[book] = 0;
    vi nbooks;

    if (Query(qvec) < moves)
        rep(i, take, sz(books)) nbooks.push_back(books[i]);
    else
        rep(i, 0, take) nbooks.push_back(books[i]);

    return binsearch(nbooks);
}

void Solve(int n) {
    dummy.resize(n);

    vi ans(n);
    int rgt[n];
    memset(rgt, -1, sizeof(rgt));

    while (book != -1 && sz(queried) + 1 != n) {
        queried.insert(book);

        vi vec;
        rep(i, 0, n) if (!queried.count(i)) vec.push_back(i);
        int next = binsearch(vec);

        rgt[book] = next;
        book = next;
    }

    book = 0;
    while (book != -1 && sz(queried) + 1 != n) {
        queried.insert(book);

        vi vec;
        rep(i, 0, n) if (!queried.count(i)) vec.push_back(i);
        int next = binsearch(vec);

        rgt[next] = book;
        book = next;
    }

    assert(sz(queried+1==n));
    int cnt = 1;
    rep(i, 0, n) {
        ans[i] = book + 1;
        book = rgt[book];
    }
    
    Answer(ans);
}

Compilation message

library.cpp: In function 'int binsearch(vi)':
library.cpp:7:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 | #define rep(i, a, b) for (int i = a; i < (b); ++i)
      |                                        ^
library.cpp:52:9: note: in expansion of macro 'rep'
   52 |         rep(i, take, sz(books)) nbooks.push_back(books[i]);
      |         ^~~
library.cpp: In function 'void Solve(int)':
library.cpp:66:42: warning: comparison of integer expressions of different signedness: 'std::unordered_set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   66 |     while (book != -1 && sz(queried) + 1 != n) {
      |                                          ^
library.cpp:78:42: warning: comparison of integer expressions of different signedness: 'std::unordered_set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   78 |     while (book != -1 && sz(queried) + 1 != n) {
      |                                          ^
In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from library.cpp:3:
library.cpp:89:22: error: no match for 'operator+' (operand types are 'std::unordered_set<int>' and 'int')
   89 |     assert(sz(queried+1==n));
      |               ~~~~~~~^~
      |               |       |
      |               |       int
      |               std::unordered_set<int>
library.cpp:89:12: note: in expansion of macro 'sz'
   89 |     assert(sz(queried+1==n));
      |            ^~
In file included from /usr/include/c++/9/bits/stl_algobase.h:67,
                 from /usr/include/c++/9/vector:60,
                 from library.h:1,
                 from library.cpp:1:
/usr/include/c++/9/bits/stl_iterator.h:423:5: note: candidate: 'template<class _Iterator> constexpr std::reverse_iterator<_Iterator> std::operator+(typename std::reverse_iterator<_Iterator>::difference_type, const std::reverse_iterator<_Iterator>&)'
  423 |     operator+(typename reverse_iterator<_Iterator>::difference_type __n,
      |     ^~~~~~~~
/usr/include/c++/9/bits/stl_iterator.h:423:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from library.cpp:3:
library.cpp:89:23: note:   mismatched types 'const std::reverse_iterator<_Iterator>' and 'int'
   89 |     assert(sz(queried+1==n));
      |                       ^
library.cpp:89:12: note: in expansion of macro 'sz'
   89 |     assert(sz(queried+1==n));
      |            ^~
In file included from /usr/include/c++/9/bits/stl_algobase.h:67,
                 from /usr/include/c++/9/vector:60,
                 from library.h:1,
                 from library.cpp:1:
/usr/include/c++/9/bits/stl_iterator.h:1219:5: note: candidate: 'template<class _Iterator> constexpr std::move_iterator<_IteratorL> std::operator+(typename std::move_iterator<_IteratorL>::difference_type, const std::move_iterator<_IteratorL>&)'
 1219 |     operator+(typename move_iterator<_Iterator>::difference_type __n,
      |     ^~~~~~~~
/usr/include/c++/9/bits/stl_iterator.h:1219:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from library.cpp:3:
library.cpp:89:23: note:   mismatched types 'const std::move_iterator<_IteratorL>' and 'int'
   89 |     assert(sz(queried+1==n));
      |                       ^
library.cpp:89:12: note: in expansion of macro 'sz'
   89 |     assert(sz(queried+1==n));
      |            ^~
In file included from /usr/include/c++/9/vector:68,
                 from library.h:1,
                 from library.cpp:1:
/usr/include/c++/9/bits/stl_bvector.h:303:3: note: candidate: 'std::_Bit_iterator std::operator+(std::ptrdiff_t, const std::_Bit_iterator&)'
  303 |   operator+(ptrdiff_t __n, const _Bit_iterator& __x)
      |   ^~~~~~~~
/usr/include/c++/9/bits/stl_bvector.h:303:23: note:   no known conversion for argument 1 from 'std::unordered_set<int>' to 'std::ptrdiff_t' {aka 'long int'}
  303 |   operator+(ptrdiff_t __n, const _Bit_iterator& __x)
      |             ~~~~~~~~~~^~~
/usr/include/c++/9/bits/stl_bvector.h:393:3: note: candidate: 'std::_Bit_const_iterator std::operator+(std::ptrdiff_t, const std::_Bit_const_iterator&)'
  393 |   operator+(ptrdiff_t __n, const _Bit_const_iterator& __x)
      |   ^~~~~~~~
/usr/include/c++/9/bits/stl_bvector.h:393:23: note:   no known conversion for argument 1 from 'std::unordered_set<int>' to 'std::ptrdiff_t' {aka 'long int'}
  393 |   operator+(ptrdiff_t __n, const _Bit_const_iterator& __x)
      |             ~~~~~~~~~~^~~
In file included from /usr/include/c++/9/string:55,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from library.cpp:3:
/usr/include/c++/9/bits/basic_string.h:6020:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&, const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 6020 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/9/bits/basic_string.h:6020:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from library.cpp:3:
library.cpp:89:23: note:   'std::unordered_set<int>' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   89 |     assert(sz(queried+1==n));
      |                       ^
library.cpp:89:12: note: in expansion of macro 'sz'
   89 |     assert(sz(queried+1==n));
      |            ^~
In file included from /usr/include/c++/9/string:56,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from library.cpp:3:
/usr/include/c++/9/bits/basic_string.tcc:1158:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 1158 |     operator+(const _CharT* __lhs,
      |     ^~~~~~~~
/usr/include/c++/9/bits/basic_string.tcc:1158:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from library.cpp:3:
library.cpp:89:23: note:   mismatched types 'const _CharT*' and 'std::unordered_set<int>'
   89 |     assert(sz(queried+1==n));
      |                       ^
library.cpp:89:12: note: in expansion of macro 'sz'
   89 |     assert(sz(queried+1==n));
      |            ^~
In file included from /usr/include/c++/9/string:56,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from library.cpp:3:
/usr/include/c++/9/bits/basic_string.tcc:1174:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(_CharT, const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 1174 |     operator+(_CharT __lhs, const basic_string<_CharT, _Traits, _Alloc>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/9/bits/basic_string.tcc:1174:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from library.cpp:3:
library.cpp:89:23: note:   mismatched types 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' and 'int'
   89 |     assert(sz(queried+1==n));
      |                       ^
library.cpp:89:12: note: in expansion of macro 'sz'
   89 |     assert(sz(queried+1==n));
      |            ^~
In file included from /usr/include/c++/9/string:55,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from library.cpp:3:
/usr/include/c++/9/bits/basic_string.h:6057:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&, const _CharT*)'
 6057 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/9/bits/basic_string.h:6057:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from library.cpp:3:
library.cpp:89:23: note:   'std::unordered_set<int>' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   89 |     assert(sz(queried+1==n));
      |                       ^
library.cpp:89:12: note: in expansion of macro 'sz'
   89 |     assert(sz(queried+1==n));
      |            ^~
In file included from /usr/include/c++/9/string:55,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from library.cpp:3:
/usr/include/c++/9/bits/basic_string.h:6073:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&, _CharT)'
 6073 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs)
      |     ^~~~~~~~
/usr/include/c++/9/bits/basic_string.h:6073:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from library.cpp:3:
library.cpp:89:23: note:   'std::unordered_set<int>' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   89 |     assert(sz(queried+1==n));
      |                       ^
library.cpp:89:12: note: in expansion of macro 'sz'
   89 |     assert(sz(queried+1==n));
      |            ^~
In file included from /usr/include/c++/9/string:55,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from library.cpp:3:
/usr/include/c++/9/bits/basic_string.h:6085:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 6085 |     operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
      |     ^~~~~~~~
/usr/include/c++/9/bits/basic_string.h:6085:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from library.cpp:3:
library.cpp:89:23: note:   'std::unordered_set<int>' is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   89 |     assert(sz(queried+1==n));
      |                       ^
library.cpp:89:12: note: in expansion of macro 'sz'
   89 |     assert(sz(queried+1==n));
      |            ^~
In file included from /usr/include/c++/9/string:55,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from library.cpp:3:
/usr/include/c++/9/bits/basic_string.h:6091:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&, std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
 6091 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/9/bits/basic_string.h:6091:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from library.cpp:3:
library.cpp:89:23: note:   'std::unordered_set<int>' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   89 |     assert(sz(queried+1==n));
      |                       ^
library.cpp:89:12: note: in expansion of macro 'sz'
   89 |     assert(sz(queried+1==n));
      |            ^~
In file included from /usr/include/c++/9/string:55,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from library.cpp:3:
/usr/include/c++/9/bits/basic_string.h:6097:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
 6097 |     operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
      |     ^~~~~~~~
/usr/include/c++/9/bits/basic_string.h:6097:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from library.cpp:3:
library.cpp:89:23: note:   'std::unordered_set<int>' is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   89 |     assert(sz(queried+1==n));
      |                       ^
library.cpp:89:12: note: in expansion of macro 'sz'
   89 |     assert(sz(queried+1==n));
      |            ^~
In file included from /usr/include/c++/9/string:55,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from library.cpp:3:
/usr/include/c++/9/bits/basic_string.h:6109:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
 6109 |     operator+(const _CharT* __lhs,
      |     ^~~~~~~~
/usr/include/c++/9/bits/basic_string.h:6109:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from library.cpp:3:
library.cpp:89:23: note:   mismatched types 'const _CharT*' and 'std::unordered_set<int>'
   89 |     assert(sz(queried+1==n));
      |                       ^
library.cpp:89:12: note: in expansion of macro 'sz'
   89 |     assert(sz(queried+1==n));