Submission #1015717

#TimeUsernameProblemLanguageResultExecution timeMemory
1015717nomen_nescioRadio Towers (IOI22_towers)C++17
Compilation error
0 ms0 KiB
#include "towers.h" #include <set> #include <vector> const int NB_TOURS_MAX = 100000; int segtree[2*NB_TOURS_MAX]; struct Tour { int hauteur, index; bool operator<(const Tour &autre) { return hauteur < autre.hauteur; } }; struct TourTrieeIndex { int hauteur, index; bool operator<(const TourTrieeIndex &autre) { return index < autre.index; } }; int hauteurs[NB_TOURS_MAX]; Tour hauteursTriees[NB_TOURS_MAX]; int nbTours; /////////////////////// ARBRE //////////////////////// void initNoeudArbre(int iNoeuds) { if (iNoeud < NB_TOURS_MAX) { initNoeudArbre(iNoeud*2); initNoeudArbre(iNoeud*2+1); segtree[iNoeud] = max(segtree[iNoeud*2], segtree[iNoeud*2+1]); } } void initArbre() { // on fait les feuilles for (int i = 0; i < nbTours; i++) { segtree[i+NB_TOURS_MAX] = hauteurs[i]; } for (int i = nbTours; i < NB_TOURS_MAX; i++) { segtree[i+NB_TOURS_MAX] = 0; } // on fait les autres noeuds initNoeudArbre(1); } int maxSurInter(int debut, int fin, int debutVoulu, int finVoulue, int iNoeud) { if (debut >= debutVoulu && fin <= finVoulue) { return segtree[iNoeud]; } if (debut > finVoulue || fin < debutVoulu) { return 0; } int milieu = (fin + debut) / 2; return max(maxSurInter(debut, milieu, debutVoulu, finVoulue, iNoeud*2), maxSurInter(milieu+1, fin, debutVoulu, finVoulue, iNoeud*2+1)); } //////////////////////////////////////////////// std::set<TourTrieeIndex> toursUtilisees; void init(int N, std::vector<int> H) { for (int i = 0; i < N; i++) { hauteurs[i] = H[i]; hauteursTriees[i].hauteur = H[i]; } initArbre(); sort(hauteursTriees, hauteursTriees+N); nbTours = N; } int max_towers(int L, int R, int D) { toursUtilisees.push({hauteursTriees[0].hauteur, hauteursTriees[0].index}); for (int iTourAAjouter = 1; iTourAAjouter < nbTours; iTourAAjouter++) { TourTrieeIndex aAjouter = hauteursTriees[iTourAAjouter]; if (aAjouter.index >= L && aAjouter.index <= R) // si ca ne sort pas { auto borneDessus = toursUtilisees.lower_bound(aAjouter) + 1; bool marcheAuDessus = false; if (borneDessus >= toursUtilisees.end()) // si c'est le 1er a droite { marcheAuDessus = true; } else { int maxSurNouvR = maxSurInter(0, NB_TOURS_MAX, aAjouter.index, borneDessus - toursUtilisees.begin(), 1); if (maxSurNouvR >= aAjouter.hauteur + D && maxSurNouvR >= borneDessus->hauteur + D) // si c'est pas le 1er a droite mais qu'on peut le connecter a droite { marcheAuDessus = true; } } auto borneDessous = borneDessus - 2; bool marcheAuDessous = false; if (borneDessous < toursUtilisees.begin()) { marcheAuDessous = true; } else { int maxSurLNouv = maxSurInter(0, NB_TOURS_MAX, borneDessous - toursUtilisees.begin(), aAjouter.index, 1); if (maxSurLNouv >= aAjouter.hauteur + D & maxSurLNouv >= borneDessous->hauteur+D) { marcheAuDessous = true; } } if (marcheAuDessus && marcheAuDessous) { toursUtilisees.push(aAjouter); } } } return toursUtilisees.size(); }

Compilation message (stderr)

towers.cpp: In function 'void initNoeudArbre(int)':
towers.cpp:34:7: error: 'iNoeud' was not declared in this scope; did you mean 'iNoeuds'?
   34 |   if (iNoeud < NB_TOURS_MAX)
      |       ^~~~~~
      |       iNoeuds
towers.cpp:38:23: error: 'max' was not declared in this scope; did you mean 'std::max'?
   38 |     segtree[iNoeud] = max(segtree[iNoeud*2], segtree[iNoeud*2+1]);
      |                       ^~~
      |                       std::max
In file included from /usr/include/c++/10/vector:60,
                 from towers.h:1,
                 from towers.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: 'std::max' declared here
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
towers.cpp: In function 'int maxSurInter(int, int, int, int, int)':
towers.cpp:69:10: error: 'max' was not declared in this scope; did you mean 'std::max'?
   69 |   return max(maxSurInter(debut, milieu, debutVoulu, finVoulue, iNoeud*2),
      |          ^~~
      |          std::max
In file included from /usr/include/c++/10/vector:60,
                 from towers.h:1,
                 from towers.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: 'std::max' declared here
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
towers.cpp: In function 'void init(int, std::vector<int>)':
towers.cpp:85:3: error: 'sort' was not declared in this scope; did you mean 'short'?
   85 |   sort(hauteursTriees, hauteursTriees+N);
      |   ^~~~
      |   short
towers.cpp: In function 'int max_towers(int, int, int)':
towers.cpp:91:18: error: 'class std::set<TourTrieeIndex>' has no member named 'push'
   91 |   toursUtilisees.push({hauteursTriees[0].hauteur, hauteursTriees[0].index});
      |                  ^~~~
towers.cpp:94:59: error: conversion from 'Tour' to non-scalar type 'TourTrieeIndex' requested
   94 |     TourTrieeIndex aAjouter = hauteursTriees[iTourAAjouter];
      |                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
towers.cpp:97:63: error: no match for 'operator+' (operand types are 'std::set<TourTrieeIndex>::iterator' {aka 'std::_Rb_tree<TourTrieeIndex, TourTrieeIndex, std::_Identity<TourTrieeIndex>, std::less<TourTrieeIndex>, std::allocator<TourTrieeIndex> >::const_iterator'} and 'int')
   97 |       auto borneDessus = toursUtilisees.lower_bound(aAjouter) + 1;
      |                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~
      |                                                    |            |
      |                                                    |            int
      |                                                    std::set<TourTrieeIndex>::iterator {aka std::_Rb_tree<TourTrieeIndex, TourTrieeIndex, std::_Identity<TourTrieeIndex>, std::less<TourTrieeIndex>, std::allocator<TourTrieeIndex> >::const_iterator}
In file included from /usr/include/c++/10/bits/stl_algobase.h:67,
                 from /usr/include/c++/10/vector:60,
                 from towers.h:1,
                 from towers.cpp:1:
/usr/include/c++/10/bits/stl_iterator.h:508: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>&)'
  508 |     operator+(typename reverse_iterator<_Iterator>::difference_type __n,
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_iterator.h:508:5: note:   template argument deduction/substitution failed:
towers.cpp:97:65: note:   mismatched types 'const std::reverse_iterator<_Iterator>' and 'int'
   97 |       auto borneDessus = toursUtilisees.lower_bound(aAjouter) + 1;
      |                                                                 ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:67,
                 from /usr/include/c++/10/vector:60,
                 from towers.h:1,
                 from towers.cpp:1:
/usr/include/c++/10/bits/stl_iterator.h:1540: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>&)'
 1540 |     operator+(typename move_iterator<_Iterator>::difference_type __n,
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_iterator.h:1540:5: note:   template argument deduction/substitution failed:
towers.cpp:97:65: note:   mismatched types 'const std::move_iterator<_IteratorL>' and 'int'
   97 |       auto borneDessus = toursUtilisees.lower_bound(aAjouter) + 1;
      |                                                                 ^
towers.cpp:129:24: error: 'class std::set<TourTrieeIndex>' has no member named 'push'
  129 |         toursUtilisees.push(aAjouter);
      |                        ^~~~
In file included from /usr/include/c++/10/bits/stl_tree.h:65,
                 from /usr/include/c++/10/set:60,
                 from towers.cpp:2:
/usr/include/c++/10/bits/stl_function.h: In instantiation of 'constexpr bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = TourTrieeIndex]':
/usr/include/c++/10/bits/stl_tree.h:1935:29:   required from 'std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_lower_bound(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Link_type, std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Base_ptr, const _Key&) [with _Key = TourTrieeIndex; _Val = TourTrieeIndex; _KeyOfValue = std::_Identity<TourTrieeIndex>; _Compare = std::less<TourTrieeIndex>; _Alloc = std::allocator<TourTrieeIndex>; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator = std::_Rb_tree<TourTrieeIndex, TourTrieeIndex, std::_Identity<TourTrieeIndex>, std::less<TourTrieeIndex>, std::allocator<TourTrieeIndex> >::iterator; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Link_type = std::_Rb_tree_node<TourTrieeIndex>*; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Base_ptr = std::_Rb_tree_node_base*]'
/usr/include/c++/10/bits/stl_tree.h:1277:30:   required from 'std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::lower_bound(const key_type&) [with _Key = TourTrieeIndex; _Val = TourTrieeIndex; _KeyOfValue = std::_Identity<TourTrieeIndex>; _Compare = std::less<TourTrieeIndex>; _Alloc = std::allocator<TourTrieeIndex>; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator = std::_Rb_tree<TourTrieeIndex, TourTrieeIndex, std::_Identity<TourTrieeIndex>, std::less<TourTrieeIndex>, std::allocator<TourTrieeIndex> >::iterator; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::key_type = TourTrieeIndex]'
/usr/include/c++/10/bits/stl_set.h:830:32:   required from 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::lower_bound(const key_type&) [with _Key = TourTrieeIndex; _Compare = std::less<TourTrieeIndex>; _Alloc = std::allocator<TourTrieeIndex>; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree<TourTrieeIndex, TourTrieeIndex, std::_Identity<TourTrieeIndex>, std::less<TourTrieeIndex>, std::allocator<TourTrieeIndex> >::const_iterator; std::set<_Key, _Compare, _Alloc>::key_type = TourTrieeIndex]'
towers.cpp:97:61:   required from here
/usr/include/c++/10/bits/stl_function.h:386:20: error: no match for 'operator<' (operand types are 'const TourTrieeIndex' and 'const TourTrieeIndex')
  386 |       { return __x < __y; }
      |                ~~~~^~~~~
towers.cpp:20:8: note: candidate: 'bool TourTrieeIndex::operator<(const TourTrieeIndex&)' (near match)
   20 |   bool operator<(const TourTrieeIndex &autre)
      |        ^~~~~~~~
towers.cpp:20:8: note:   passing 'const TourTrieeIndex*' as 'this' argument discards qualifiers
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/vector:60,
                 from towers.h:1,
                 from towers.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:489:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator<(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)'
  489 |     operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_pair.h:489:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/10/bits/stl_tree.h:65,
                 from /usr/include/c++/10/set:60,
                 from towers.cpp:2:
/usr/include/c++/10/bits/stl_function.h:386:20: note:   'const TourTrieeIndex' is not derived from 'const std::pair<_T1, _T2>'
  386 |       { return __x < __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:67,
                 from /usr/include/c++/10/vector:60,
                 from towers.h:1,
                 from towers.cpp:1:
/usr/include/c++/10/bits/stl_iterator.h:366:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)'
  366 |     operator<(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_iterator.h:366:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/10/bits/stl_tree.h:65,
                 from /usr/include/c++/10/set:60,
                 from towers.cpp:2:
/usr/include/c++/10/bits/stl_function.h:386:20: note:   'const TourTrieeIndex' is not derived from 'const std::reverse_iterator<_Iterator>'
  386 |       { return __x < __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:67,
                 from /usr/include/c++/10/vector:60,
                 from towers.h:1,
                 from towers.cpp:1:
/usr/include/c++/10/bits/stl_iterator.h:404:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)'
  404 |     operator<(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_iterator.h:404:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/10/bits/stl_tree.h:65,
                 from /usr/include/c++/10/set:60,
                 from towers.cpp:2:
/usr/include/c++/10/bits/stl_function.h:386:20: note:   'const TourTrieeIndex' is not derived from 'const std::reverse_iterator<_Iterator>'
  386 |       { return __x < __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:67,
                 from /usr/include/c++/10/vector:60,
                 from towers.h:1,
                 from towers.cpp:1:
/usr/include/c++/10/bits/stl_iterator.h:1451:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator<(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorR>&)'
 1451 |     operator<(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_iterator.h:1451:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/10/bits/stl_tree.h:65,
                 from /usr/include/c++/10/set:60,
                 from towers.cpp:2:
/usr/include/c++/10/bits/stl_function.h:386:20: note:   'const TourTrieeIndex' is not derived from 'const std::move_iterator<_IteratorL>'
  386 |       { return __x < __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:67,
                 from /usr/include/c++/10/vector:60,
                 from towers.h:1,
                 from towers.cpp:1:
/usr/include/c++/10/bits/stl_iterator.h:1507:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator<(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorL>&)'
 1507 |     operator<(const move_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_iterator.h:1507:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/10/bits/stl_tree.h:65,
                 from /usr/include/c++/10/set:60,
                 from towers.cpp:2:
/usr/include/c++/10/bits/stl_function.h:386:20: note:   'const TourTrieeIndex' is not derived from 'const std::move_iterator<_IteratorL>'
  386 |       { return __x < __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/10/vector:67,
                 from towers.h:1,
                 from towers.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1930:5: note: candidate: 'template<class _Tp, class _Alloc> bool std::operator<(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)'
 1930 |     operator<(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1930:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/10/bits/stl_tree.h:65,
                 from /usr/include/c++/10/set:60,
                 from towers.cpp:2:
/usr/include/c++/10/bits/stl_function.h:386:20: note:   'const TourTrieeIndex' is not derived from 'const std::vector<_Tp, _Alloc>'
  386 |       { return __x < __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/10/bits/node_handle.h:39,
                 from /usr/include/c++/10/bits/stl_tree.h:72,
                 from /usr/include/c++/10/set:60,
                 from towers.cpp:2:
/usr/include/c++/10/optional:1003:5: note: candidate: 'template<class _Tp, class _Up> constexpr std::__optional_relop_t<decltype ((declval<_Tp>() < declval<_Up>()))> std::operator<(const std::optional<_Tp>&, const std::optional<_Up>&)'
 1003 |     operator<(const optional<_Tp>& __lhs, const optional<_Up>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/10/optional:1003:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/10/bits/stl_tree.h:65,
                 from /usr/include/c++/10/set:60,
                 from towers.cpp:2:
/usr/include/c++/10/bits/stl_function.h:386:20: note:   'const TourTrieeIndex' is not derived from 'const std::optional<_Tp>'
  386 |       { return __x < __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/10/bits/node_handle.h:39,
                 from /usr/include/c++/10/bits/stl_tree.h:72,
                 from /usr/include/c++/10/set:60,
                 from towers.cpp:2:
/usr/include/c++/10/optional:1071:5: note: candidate: 'template<class _Tp> constexpr bool std::operator<(const std::optional<_Tp>&, std::nullopt_t)'
 1071 |     operator<(const optional<_Tp>& /* __lhs */, nullopt_t) noexcept
      |     ^~~~~~~~
/usr/include/c++/10/optional:1071:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/10/bits/stl_tree.h:65,
                 from /usr/include/c++/10/set:60,
                 from towers.cpp:2:
/usr/include/c++/10/bits/stl_function.h:386:20: note:   'const TourTrieeIndex' is not derived from 'const std::optional<_Tp>'
  386 |       { return __x < __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/10/bits/node_handle.h:39,
                 from /usr/include/c++/10/bits/stl_tree.h:72,
                 from /usr/include/c++/10/set:60,
                 from towers.cpp:2:
/usr/include/c++/10/optional:1076:5: note: candidate: 'template<class _Tp> constexpr bool std::operator<(std::nullopt_t, const std::optional<_Tp>&)'
 1076 |     operator<(nullopt_t, const optional<_Tp>& __rhs) noexcept
      |     ^~~~~~~~
/usr/include/c++/10/optional:1076:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/10/bits/stl_tree.h:65,
                 from /usr/include/c++/10/set:60,
                 from towers.cpp:2:
/usr/include/c++/10/bits/stl_function.h:386:20: note:   'const TourTrieeIndex' is not derived from 'const std::optional<_Tp>'
  386 |       { return __x < __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/10/bits/node_handle.h:39,
                 from /usr/include/c++/10/bits/stl_tree.h:72,
                 from /usr/include/c++/10/set:60,
                 from towers.cpp:2:
/usr/include/c++/10/optional:1137:5: note: candidate: 'template<class _Tp, class _Up> constexpr std::__optional_relop_t<decltype ((declval<_Tp>() < declval<_Up>()))> std::operator<(const std::optional<_Tp>&, const _Up&)'
 1137 |     operator<(const optional<_Tp>& __lhs, const _Up& __rhs)
      |     ^~~~~~~~
/usr/include/c++/10/optional:1137:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/10/bits/stl_tree.h:65,
                 from /usr/include/c++/10/set:60,
                 from towers.cpp:2:
/usr/include/c++/10/bits/stl_function.h:386:20: note:   'const TourTrieeIndex' is not derived from 'const std::optional<_Tp>'
  386 |       { return __x < __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/10/bits/node_handle.h:39,
                 from /usr/include/c++/10/bits/stl_tree.h:72,
                 from /usr/include/c++/10/set:60,
                 from towers.cpp:2:
/usr/include/c++/10/optional:1143:5: note: candidate: 'template<class _Tp, class _Up> constexpr std::__optional_relop_t<decltype ((declval<_Up>() < declval<_Tp>()))> std::operator<(const _Up&, const std::optional<_Tp>&)'
 1143 |     operator<(const _Up& __lhs, const optional<_Tp>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/10/optional:1143:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/10/bits/stl_tree.h:65,
                 from /usr/include/c++/10/set:60,
                 from towers.cpp:2:
/usr/include/c++/10/bits/stl_function.h:386:20: note:   'const TourTrieeIndex' is not derived from 'const std::optional<_Tp>'
  386 |       { return __x < __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/10/set:61,
                 from towers.cpp:2:
/usr/include/c++/10/bits/stl_set.h:1023:5: note: candidate: 'template<class _Key, class _Compare, class _Alloc> bool std::operator<(const std::set<_Key, _Compare, _Allocator>&, c