#2242
Se consideră un șir a[1], a[2], …, a[n] de numere distincte din mulțimea {1, 2, ..., n}. O operație constă din extragerea unui număr din șir de la o anumită poziție și inserarea lui în altă poziție a șirului. De exemplu, dacă a = 1, 2, 5, 3, 6, 4, atunci 5 poate fi inserat după 3 și se obține a = 1, 2, 3, 5, 6, 4. Să se obțină șirul ordonat crescător efectuând un număr minim de operații de inserare.
-
| Problema | inserari | Operații I/O |
tastatură/ecran
|
|---|---|---|---|
| Limita timp | 0.3 secunde | Limita memorie |
Total: 64 MB
/
Stivă 8 MB
|
| Id soluție | #64136217 | Utilizator | |
| Fișier | inserari.cpp | Dimensiune | 445 B |
| Data încărcării | 19 Aprilie 2026, 23:49 | Scor/rezultat | Eroare de compilare |
inserari.cpp: In function ‘int main()’: inserari.cpp:12:11: error: ‘class std::vector<int>’ has no member named ‘pushback’; did you mean ‘push_back’? 12 | v.pushback(x); | ^~~~~~~~ | push_back inserari.cpp:16:31: error: no matching function for call to ‘lower_bound(<unresolved overloaded function type>, <unresolved overloaded function type>, int&)’ 16 | auto poz = lower_bound(lis.begin, lis.end, it); | ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/13/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51, from inserari.cpp:1: /usr/include/c++/13/bits/stl_algobase.h:1498:5: note: candidate: ‘template<class _ForwardIterator, class _Tp> _ForwardIterator std::lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&)’ 1498 | lower_bound(_ForwardIterator __first, _ForwardIterator __last, | ^~~~~~~~~~~ /usr/include/c++/13/bits/stl_algobase.h:1498:5: note: template argument deduction/substitution failed: inserari.cpp:16:31: note: couldn’t deduce template parameter ‘_ForwardIterator’ 16 | auto poz = lower_bound(lis.begin, lis.end, it); | ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/13/algorithm:61: /usr/include/c++/13/bits/stl_algo.h:2005:5: note: candidate: ‘template<class _FIter, class _Tp, class _Compare> _FIter std::lower_bound(_FIter, _FIter, const _Tp&, _Compare)’ 2005 | lower_bound(_ForwardIterator __first, _ForwardIterator __last, | ^~~~~~~~~~~ /usr/include/c++/13/bits/stl_algo.h:2005:5: note: template argument deduction/substitution failed: inserari.cpp:16:31: note: candidate expects 4 arguments, 3 provided 16 | auto poz = lower_bound(lis.begin, lis.end, it); | ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~ inserari.cpp:18:16: error: no match for ‘operator[]’ (operand types are ‘std::vector<int>’ and ‘<unresolved overloaded function type>’) 18 | lis[lis.end] = it; | ^ In file included from /usr/include/c++/13/vector:66, from /usr/include/c++/13/queue:63, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:157: /usr/include/c++/13/bits/stl_vector.h:1126:7: note: candidate: ‘std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = int; _Alloc = std::allocator<int>; reference = int&; size_type = long unsigned int]’ 1126 | operator[](size_type __n) _GLIBCXX_NOEXCEPT | ^~~~~~~~ /usr/include/c++/13/bits/stl_vector.h:1126:28: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} 1126 | operator[](size_type __n) _GLIBCXX_NOEXCEPT | ~~~~~~~~~~^~~ /usr/include/c++/13/bits/stl_vector.h:1145:7: note: candidate: ‘std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](size_type) const [with _Tp = int; _Alloc = std::allocator<int>; const_reference = const int&; size_type = long unsigned int]’ 1145 | operator[](size_type __n) const _GLIBCXX_NOEXCEPT | ^~~~~~~~ /usr/include/c++/13/bits/stl_vector.h:1145:28: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} 1145 | operator[](size_type __n) const _GLIBCXX_NOEXCEPT | ~~~~~~~~~~^~~
www.pbinfo.ro permite evaluarea a două tipuri de probleme:
Problema inserari face parte din prima categorie. Soluția propusă de tine va fi evaluată astfel:
Suma punctajelor acordate pe testele utilizate pentru verificare este 100. Astfel, soluția ta poate obține cel mult 100 de puncte, caz în care se poate considera corectă.