Submission #1083244

#TimeUsernameProblemLanguageResultExecution timeMemory
1083244Math4Life2020Ancient Books (IOI17_books)C++17
Compilation error
0 ms0 KiB
// Source: https://usaco.guide/general/io #include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<ll,ll>; int triv(int N1) { for (ll i=0;i<N1;i++) { int[] *a0 = ask((int)i); if ((a0[0]+a0[1])==0) { return i; } } return -1; } map<ll,pii> pts; ll N; ll gm; ll ans = -1; vector<bool> asked; ll process(ll x) { if (!asked[x]) { int[] *a0 = ask((int)x); pts[x]={a0[0],a0[1]}; asked[x]=1; } ll S = pts[x].first+pts[x].second; if (S==0) { return x; } if (S<gm) { ll y = -1; if (x>0 && !asked[x-1]) { y=max(y,process(x-1)); } if (x<(N-1) && !asked[x+1]) { y=max(y,process(x+1)); } return y; } return -1; } void query(ll a, ll b) { if ((a+1)==b) { return; } if (pts[a].first==pts[b].first) { return; } ll c = (a+b)/2; ans=max(ans,process(c)); if (ans!=-1) { return; } auto A1 = pts.find(a); A1++; query(a,(*A1).first); auto B1 = pts.find(b); B1--; query((*B1).first,b); } int find_best(int N0) { N=N0; gm=0; ans = -1; pts.clear(); asked.clear(); for (ll i=0;i<N;i++) { asked.push_back(0); } if (N<=5000) { return triv(N); } ll r = (N-1)/500; for (ll i=1;i<=500;i++) { int[] *a0 = ask((int)(i*r)); asked[i*r]=1; pts[i*r]={a0[0],a0[1]}; } for (auto A: pts) { pii p0 = A.second; gm = max(gm,p0.first+p0.second); } for (auto A: pts) { ll v = process(A.first); if (v!=-1) { return v; } } if (process(0)!=-1) { return 0; } if (process(N-1)!=-1) { return (N-1); } auto A = pts.begin(); auto B=A; B++; do { pii pa = (*A).second; pii pb = (*B).second; if ((pa.first+pa.second+pb.first+pb.second)==(2*gm)) { query((*A).first,(*B).first); if (ans != -1) { return ans; } } A++; B++; } while (B != pts.end()); return -1; }

Compilation message (stderr)

books.cpp: In function 'int triv(int)':
books.cpp:9:6: error: structured binding declaration cannot have type 'int'
    9 |   int[] *a0 = ask((int)i);
      |      ^~
books.cpp:9:6: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
books.cpp:9:6: error: empty structured binding declaration
books.cpp:9:9: error: expected initializer before '*' token
    9 |   int[] *a0 = ask((int)i);
      |         ^
books.cpp:10:8: error: 'a0' was not declared in this scope; did you mean 'y0'?
   10 |   if ((a0[0]+a0[1])==0) {
      |        ^~
      |        y0
books.cpp:9:6: warning: unused structured binding declaration [-Wunused-variable]
    9 |   int[] *a0 = ask((int)i);
      |      ^~
books.cpp: In function 'll process(ll)':
books.cpp:25:6: error: structured binding declaration cannot have type 'int'
   25 |   int[] *a0 = ask((int)x);
      |      ^~
books.cpp:25:6: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
books.cpp:25:6: error: empty structured binding declaration
books.cpp:25:9: error: expected initializer before '*' token
   25 |   int[] *a0 = ask((int)x);
      |         ^
books.cpp:26:11: error: 'a0' was not declared in this scope; did you mean 'y0'?
   26 |   pts[x]={a0[0],a0[1]};
      |           ^~
      |           y0
books.cpp:26:22: error: no match for 'operator=' (operand types are 'std::map<long long int, std::pair<long long int, long long int> >::mapped_type' {aka 'std::pair<long long int, long long int>'} and '<brace-enclosed initializer list>')
   26 |   pts[x]={a0[0],a0[1]};
      |                      ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from books.cpp:3:
/usr/include/c++/10/bits/stl_pair.h:390:7: note: candidate: 'std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(typename std::conditional<std::__and_<std::is_copy_assignable<_T1>, std::is_copy_assignable<_T2> >::value, const std::pair<_T1, _T2>&, const std::__nonesuch&>::type) [with _T1 = long long int; _T2 = long long int; typename std::conditional<std::__and_<std::is_copy_assignable<_T1>, std::is_copy_assignable<_T2> >::value, const std::pair<_T1, _T2>&, const std::__nonesuch&>::type = const std::pair<long long int, long long int>&]'
  390 |       operator=(typename conditional<
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_pair.h:393:41: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::conditional<true, const std::pair<long long int, long long int>&, const std::__nonesuch&>::type' {aka 'const std::pair<long long int, long long int>&'}
  390 |       operator=(typename conditional<
      |                 ~~~~~~~~~~~~~~~~~~~~~    
  391 |   __and_<is_copy_assignable<_T1>,
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~        
  392 |          is_copy_assignable<_T2>>::value,
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  393 |   const pair&, const __nonesuch&>::type __p)
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_pair.h:401:7: note: candidate: 'std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(typename std::conditional<std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value, std::pair<_T1, _T2>&&, std::__nonesuch&&>::type) [with _T1 = long long int; _T2 = long long int; typename std::conditional<std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value, std::pair<_T1, _T2>&&, std::__nonesuch&&>::type = std::pair<long long int, long long int>&&]'
  401 |       operator=(typename conditional<
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_pair.h:404:31: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::conditional<true, std::pair<long long int, long long int>&&, std::__nonesuch&&>::type' {aka 'std::pair<long long int, long long int>&&'}
  401 |       operator=(typename conditional<
      |                 ~~~~~~~~~~~~~~~~~~~~~
  402 |   __and_<is_move_assignable<_T1>,
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  403 |          is_move_assignable<_T2>>::value,
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  404 |   pair&&, __nonesuch&&>::type __p)
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_pair.h:418:2: note: candidate: 'template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<_T1&, const _U1&>, std::is_assignable<_T2&, const _U2&> >::value, std::pair<_T1, _T2>&>::type std::pair<_T1, _T2>::operator=(const std::pair<_U1, _U2>&) [with _U1 = _U1; _U2 = _U2; _T1 = long long int; _T2 = long long int]'
  418 |  operator=(const pair<_U1, _U2>& __p)
      |  ^~~~~~~~
/usr/include/c++/10/bits/stl_pair.h:418:2: note:   template argument deduction/substitution failed:
books.cpp:26:22: note:   couldn't deduce template parameter '_U1'
   26 |   pts[x]={a0[0],a0[1]};
      |                      ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from books.cpp:3:
/usr/include/c++/10/bits/stl_pair.h:430:2: note: candidate: 'template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<_T1&, _U1&&>, std::is_assignable<_T2&, _U2&&> >::value, std::pair<_T1, _T2>&>::type std::pair<_T1, _T2>::operator=(std::pair<_U1, _U2>&&) [with _U1 = _U1; _U2 = _U2; _T1 = long long int; _T2 = long long int]'
  430 |  operator=(pair<_U1, _U2>&& __p)
      |  ^~~~~~~~
/usr/include/c++/10/bits/stl_pair.h:430:2: note:   template argument deduction/substitution failed:
books.cpp:26:22: note:   couldn't deduce template parameter '_U1'
   26 |   pts[x]={a0[0],a0[1]};
      |                      ^
books.cpp:25:6: warning: unused structured binding declaration [-Wunused-variable]
   25 |   int[] *a0 = ask((int)x);
      |      ^~
books.cpp: In function 'int find_best(int)':
books.cpp:78:6: error: structured binding declaration cannot have type 'int'
   78 |   int[] *a0 = ask((int)(i*r));
      |      ^~
books.cpp:78:6: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
books.cpp:78:6: error: empty structured binding declaration
books.cpp:78:9: error: expected initializer before '*' token
   78 |   int[] *a0 = ask((int)(i*r));
      |         ^
books.cpp:80:13: error: 'a0' was not declared in this scope; did you mean 'N0'?
   80 |   pts[i*r]={a0[0],a0[1]};
      |             ^~
      |             N0
books.cpp:80:24: error: no match for 'operator=' (operand types are 'std::map<long long int, std::pair<long long int, long long int> >::mapped_type' {aka 'std::pair<long long int, long long int>'} and '<brace-enclosed initializer list>')
   80 |   pts[i*r]={a0[0],a0[1]};
      |                        ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from books.cpp:3:
/usr/include/c++/10/bits/stl_pair.h:390:7: note: candidate: 'std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(typename std::conditional<std::__and_<std::is_copy_assignable<_T1>, std::is_copy_assignable<_T2> >::value, const std::pair<_T1, _T2>&, const std::__nonesuch&>::type) [with _T1 = long long int; _T2 = long long int; typename std::conditional<std::__and_<std::is_copy_assignable<_T1>, std::is_copy_assignable<_T2> >::value, const std::pair<_T1, _T2>&, const std::__nonesuch&>::type = const std::pair<long long int, long long int>&]'
  390 |       operator=(typename conditional<
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_pair.h:393:41: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::conditional<true, const std::pair<long long int, long long int>&, const std::__nonesuch&>::type' {aka 'const std::pair<long long int, long long int>&'}
  390 |       operator=(typename conditional<
      |                 ~~~~~~~~~~~~~~~~~~~~~    
  391 |   __and_<is_copy_assignable<_T1>,
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~        
  392 |          is_copy_assignable<_T2>>::value,
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  393 |   const pair&, const __nonesuch&>::type __p)
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_pair.h:401:7: note: candidate: 'std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(typename std::conditional<std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value, std::pair<_T1, _T2>&&, std::__nonesuch&&>::type) [with _T1 = long long int; _T2 = long long int; typename std::conditional<std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value, std::pair<_T1, _T2>&&, std::__nonesuch&&>::type = std::pair<long long int, long long int>&&]'
  401 |       operator=(typename conditional<
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_pair.h:404:31: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::conditional<true, std::pair<long long int, long long int>&&, std::__nonesuch&&>::type' {aka 'std::pair<long long int, long long int>&&'}
  401 |       operator=(typename conditional<
      |                 ~~~~~~~~~~~~~~~~~~~~~
  402 |   __and_<is_move_assignable<_T1>,
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  403 |          is_move_assignable<_T2>>::value,
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  404 |   pair&&, __nonesuch&&>::type __p)
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_pair.h:418:2: note: candidate: 'template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<_T1&, const _U1&>, std::is_assignable<_T2&, const _U2&> >::value, std::pair<_T1, _T2>&>::type std::pair<_T1, _T2>::operator=(const std::pair<_U1, _U2>&) [with _U1 = _U1; _U2 = _U2; _T1 = long long int; _T2 = long long int]'
  418 |  operator=(const pair<_U1, _U2>& __p)
      |  ^~~~~~~~
/usr/include/c++/10/bits/stl_pair.h:418:2: note:   template argument deduction/substitution failed:
books.cpp:80:24: note:   couldn't deduce template parameter '_U1'
   80 |   pts[i*r]={a0[0],a0[1]};
      |                        ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from books.cpp:3:
/usr/include/c++/10/bits/stl_pair.h:430:2: note: candidate: 'template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<_T1&, _U1&&>, std::is_assignable<_T2&, _U2&&> >::value, std::pair<_T1, _T2>&>::type std::pair<_T1, _T2>::operator=(std::pair<_U1, _U2>&&) [with _U1 = _U1; _U2 = _U2; _T1 = long long int; _T2 = long long int]'
  430 |  operator=(pair<_U1, _U2>&& __p)
      |  ^~~~~~~~
/usr/include/c++/10/bits/stl_pair.h:430:2: note:   template argument deduction/substitution failed:
books.cpp:80:24: note:   couldn't deduce template parameter '_U1'
   80 |   pts[i*r]={a0[0],a0[1]};
      |                        ^
books.cpp:78:6: warning: unused structured binding declaration [-Wunused-variable]
   78 |   int[] *a0 = ask((int)(i*r));
      |      ^~