#3941
Scrieți funcția care are antetul:
long long CountSumS(vector<int> &a, int s)
Funcția va returna numărul de perechi (a[i], a[j]) cu i < j și a[i] + a[j] = s.
| Problema | CountSumS | Operații I/O |
countsums.in/countsums.out
|
|---|---|---|---|
| Limita timp | 0.4 secunde | Limita memorie |
Total: 128 MB
/
Stivă 64 MB
|
| Id soluție | #64483544 | Utilizator | |
| Fișier | countsums.cpp | Dimensiune | 774 B |
| Data încărcării | 10 Mai 2026, 13:11 | Scor/rezultat | Eroare de compilare |
countsums.cpp: In function ‘long long int CountSumS(std::vector<int>&, int)’: countsums.cpp:6:29: error: expected initializer before ‘-’ token 6 | int n=a.size(), left-0, right=a.size()-1; | ^ countsums.cpp:10:36: error: invalid conversion from ‘std::ios_base& (*)(std::ios_base&)’ to ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-fpermissive] 10 | long long sum=(long long)b[left]+b[right]; | ^~~~ | | | std::ios_base& (*)(std::ios_base&) 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, from countsums.cpp:1: /usr/include/c++/13/bits/stl_vector.h:1126:28: note: initializing argument 1 of ‘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 | ~~~~~~~~~~^~~ countsums.cpp:10:44: error: invalid conversion from ‘std::ios_base& (*)(std::ios_base&)’ to ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-fpermissive] 10 | long long sum=(long long)b[left]+b[right]; | ^~~~~ | | | std::ios_base& (*)(std::ios_base&) /usr/include/c++/13/bits/stl_vector.h:1126:28: note: initializing argument 1 of ‘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 | ~~~~~~~~~~^~~ countsums.cpp:11:15: warning: suggest parentheses around assignment used as truth value [-Wparentheses] 11 | if(sum=s){ | ~~~^~ countsums.cpp:12:18: error: invalid conversion from ‘std::ios_base& (*)(std::ios_base&)’ to ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-fpermissive] 12 | if(b[left]==b[right]){ | ^~~~ | | | std::ios_base& (*)(std::ios_base&) /usr/include/c++/13/bits/stl_vector.h:1126:28: note: initializing argument 1 of ‘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 | ~~~~~~~~~~^~~ countsums.cpp:12:27: error: invalid conversion from ‘std::ios_base& (*)(std::ios_base&)’ to ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-fpermissive] 12 | if(b[left]==b[right]){ | ^~~~~ | | | std::ios_base& (*)(std::ios_base&) /usr/include/c++/13/bits/stl_vector.h:1126:28: note: initializing argument 1 of ‘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 | ~~~~~~~~~~^~~ countsums.cpp:13:34: error: ISO C++ forbids using pointer to a function in subtraction [-fpermissive] 13 | long long r=right-left+1; | ~~~~~^~~~~ countsums.cpp:18:23: warning: pointer to a function used in arithmetic [-Wpointer-arith] 18 | while(left+1<right && b[left]==b[left+1]){left++; lcnt++;} | ~~~~^~ countsums.cpp:18:37: error: invalid conversion from ‘std::ios_base& (*)(std::ios_base&)’ to ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-fpermissive] 18 | while(left+1<right && b[left]==b[left+1]){left++; lcnt++;} | ^~~~ | | | std::ios_base& (*)(std::ios_base&) /usr/include/c++/13/bits/stl_vector.h:1126:28: note: initializing argument 1 of ‘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 | ~~~~~~~~~~^~~ countsums.cpp:18:50: warning: pointer to a function used in arithmetic [-Wpointer-arith] 18 | while(left+1<right && b[left]==b[left+1]){left++; lcnt++;} | ~~~~^~ countsums.cpp:18:50: error: invalid conversion from ‘std::ios_base& (*)(std::ios_base&)’ to ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-fpermissive] 18 | while(left+1<right && b[left]==b[left+1]){left++; lcnt++;} | ~~~~^~ | | | std::ios_base& (*)(std::ios_base&) /usr/include/c++/13/bits/stl_vector.h:1126:28: note: initializing argument 1 of ‘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 | ~~~~~~~~~~^~~ countsums.cpp:18:55: warning: ISO C++ forbids incrementing a pointer of type ‘std::ios_base& (*)(std::ios_base&)’ [-Wpointer-arith] 18 | while(left+1<right && b[left]==b[left+1]){left++; lcnt++;} | ^~~~ countsums.cpp:18:55: error: lvalue required as increment operand countsums.cpp:19:24: warning: pointer to a function used in arithmetic [-Wpointer-arith] 19 | while(right-1>left && b[right]==b[right-1]){right--; rnct++;} | ~~~~~^~ countsums.cpp:19:37: error: invalid conversion from ‘std::ios_base& (*)(std::ios_base&)’ to ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-fpermissive] 19 | while(right-1>left && b[right]==b[right-1]){right--; rnct++;} | ^~~~~ | | | std::ios_base& (*)(std::ios_base&) /usr/include/c++/13/bits/stl_vector.h:1126:28: note: initializing argument 1 of ‘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 | ~~~~~~~~~~^~~ countsums.cpp:19:52: warning: pointer to a function used in arithmetic [-Wpointer-arith] 19 | while(right-1>left && b[right]==b[right-1]){right--; rnct++;} | ~~~~~^~ countsums.cpp:19:52: error: invalid conversion from ‘std::ios_base& (*)(std::ios_base&)’ to ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-fpermissive] 19 | while(right-1>left && b[right]==b[right-1]){right--; rnct++;} | ~~~~~^~ | | | std::ios_base& (*)(std::ios_base&) /usr/include/c++/13/bits/stl_vector.h:1126:28: note: initializing argument 1 of ‘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 | ~~~~~~~~~~^~~ countsums.cpp:19:57: warning: ISO C++ forbids decrementing a pointer of type ‘std::ios_base& (*)(std::ios_base&)’ [-Wpointer-arith] 19 | while(right-1>left && b[right]==b[right-1]){right--; rnct++;} | ^~~~~ countsums.cpp:19:57: error: lvalue required as decrement operand countsums.cpp:19:66: error: ‘rnct’ was not declared in this scope; did you mean ‘rcnt’? 19 | while(right-1>left && b[right]==b[right-1]){right--; rnct++;} | ^~~~ | rcnt countsums.cpp:21:13: warning: ISO C++ forbids incrementing a pointer of type ‘std::ios_base& (*)(std::ios_base&)’ [-Wpointer-arith] 21 | left++; | ^~~~ countsums.cpp:21:13: error: lvalue required as increment operand countsums.cpp:22:13: warning: ISO C++ forbids decrementing a pointer of type ‘std::ios_base& (*)(std::ios_base&)’ [-Wpointer-arith] 22 | right--; | ^~~~~ countsums.cpp:22:13: error: lvalue required as decrement operand countsums.cpp:24:23: warning: ISO C++ forbids incrementing a pointer of type ‘std::ios_base& (*)(std::ios_base&)’ [-Wpointer-arith] 24 | else if(sum<s)left++; | ^~~~ countsums.cpp:24:23: error: lvalue required as increment operand countsums.cpp:25:14: warning: ISO C++ forbids decrementing a pointer of type ‘std::ios_base& (*)(std::ios_base&)’ [-Wpointer-arith] 25 | else right--; | ^~~~~ countsums.cpp:25:14: error: lvalue required as decrement operand countsums.cpp:6:13: warning: unused variable ‘n’ [-Wunused-variable] 6 | int n=a.size(), left-0, right=a.size()-1; | ^
www.pbinfo.ro permite evaluarea a două tipuri de probleme:
Problema CountSumS face parte din a doua categorie. Pentru aceste probleme se folosește un program suport, furnizat de propunătorul problemei. 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ă.