#3860
consecutive1
Se dă un șir (a[1], a[2], ..., a[n])
de numere naturale cuprinse între 1
și n
. Se dau de asemenea Q
interogări, fiecare prin două numere x
, y
: dacă s-ar ordona a[x], a[x+1], ..., a[y]
, se obține sau nu o secvență de numere consecutive? (De exemplu, 5,3,6,4
dacă e ordonată se obține 3,4,5,6
, care este o secvență de numere consecutive). Dându-se Q
întrebări, să se răspundă la acestea. La fiecare interogare, dacă prin sortare se obține o secvență de numere consecutive veți afișa valoarea 1
, iar în caz contrar veți afișa valoarea 0
.
EJOI 2021, sesiunea de antrenament
Problema | consecutive1 | Operații I/O | tastatură/ecran |
---|---|---|---|
Limita timp | 1 secunde | Limita memorie |
Total: 256 MB
/
Stivă 8 MB
|
Id soluție | #51439915 | Utilizator | |
Fișier | consecutive1.cpp | Dimensiune | 2.11 KB |
Data încărcării | 17 Iunie 2024, 12:51 | Scor / rezultat | Eroare de compilare |
consecutive1.cpp: In function 'int main()': consecutive1.cpp:41:23: error: 'x' was not declared in this scope int minim = a[x]; ^ consecutive1.cpp:44:30: error: 'y' was not declared in this scope for (int i = x; i <= y; ++i) { ^ consecutive1.cpp:45:33: error: no matching function for call to 'std::vector<int>::insert(__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type&)' secventa.insert(a[i]); ^ consecutive1.cpp:45:33: note: candidates are: In file included from /usr/include/c++/4.8/vector:69:0, from consecutive1.cpp:7: /usr/include/c++/4.8/bits/vector.tcc:107:5: note: std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::iterator, const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; typename std::_Vector_base<_Tp, _Alloc>::pointer = int*; std::vector<_Tp, _Alloc>::value_type = int] vector<_Tp, _Alloc>:: ^ /usr/include/c++/4.8/bits/vector.tcc:107:5: note: candidate expects 2 arguments, 1 provided In file included from /usr/include/c++/4.8/vector:64:0, from consecutive1.cpp:7: /usr/include/c++/4.8/bits/stl_vector.h:988:7: note: std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::iterator, std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; typename std::_Vector_base<_Tp, _Alloc>::pointer = int*; std::vector<_Tp, _Alloc>::value_type = int] insert(iterator __position, value_type&& __x) ^ /usr/include/c++/4.8/bits/stl_vector.h:988:7: note: candidate expects 2 arguments, 1 provided /usr/include/c++/4.8/bits/stl_vector.h:1005:7: note: void std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::iterator, std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; typename std::_Vector_base<_Tp, _Alloc>::pointer = int*] insert(iterator __position, initializer_list<value_type> __l) ^ /usr/include/c++/4.8/bits/stl_vector.h:1005:7: note: candidate expects 2 arguments, 1 provided /usr/include/c++/4.8/bits/stl_vector.h:1023:7: note: void std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::iterator, std::vector<_Tp, _Alloc>::size_type, const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; typename std::_Vector_base<_Tp, _Alloc>::pointer = int*; std::vector<_Tp, _Alloc>::size_type = unsigned int; std::vector<_Tp, _Alloc>::value_type = int] insert(iterator __position, size_type __n, const value_type& __x) ^ /usr/include/c++/4.8/bits/stl_vector.h:1023:7: note: candidate expects 3 arguments, 1 provided /usr/include/c++/4.8/bits/stl_vector.h:1044:9: note: template<class _InputIterator, class> void std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::iterator, _InputIterator, _InputIterator) [with _InputIterator = _InputIterator; <template-parameter-2-2> = <template-parameter-1-2>; _Tp = int; _Alloc = std::allocator<int>] insert(iterator __position, _InputIterator __first, ^ /usr/include/c++/4.8/bits/stl_vector.h:1044:9: note: template argument deduction/substitution failed: consecutive1.cpp:45:33: note: cannot convert 'a.std::vector<_Tp, _Alloc>::operator[]<int, std::allocator<int> >(((std::vector<int>::size_type)i))' (type '__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type {aka int}') to type 'std::vector<int>::iterator {aka __gnu_cxx::__normal_iterator<int*, std::vector<int> >}' secventa.insert(a[i]); ^ consecutive1.cpp:59:106: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] if (maxim - minim == indiceFinal - indiceStart && secventa.size() == indiceFinal - indiceStart + 1) { ^
www.pbinfo.ro permite evaluarea a două tipuri de probleme:
Problema consecutive1 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ă.