Submission #75543

#TimeUsernameProblemLanguageResultExecution timeMemory
75543nocleverVudu (COCI15_vudu)C++14
Compilation error
0 ms0 KiB
#include <iostream> #include <vector> #include <algorithm> #include <map> using namespace std; template<typename T> class fenwick { private: int n; vector<T> fenw; public: fenwick(int _n) : n(_n) { fenw.resize(n); } void modify(int x, T v) { while (x < n) { fenw[x] += v; x |= (x + 1); } } T get(int x) { T v{}; while (x >= 0) { v += fenw[x]; x = (x & (x + 1)) - 1; } return v; } }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<long long> a(n); vector<long long> b(n); for (int i = 0; i < n; i++) { cin >> a[i]; } long long p; cin >> p; for (int i = 0; i < n; i++) { a[i] -= p; } b[0] = a[0]; for (int i = 1; i < n; i++) { a[i] += a[i - 1]; b[i] = a[i]; } sort(unique(b.begin(), b.end())); map<long long, int> mp; for (int i = 0; i < n; i++) { mp[a[i]] = lower_bound(b.begin(), b.end(), a[i]) - b.begin(); } fenwick<long long> fenw(n); long long ans = 0ll; for (int i = 0; i < n; i++) { if (a[i] >= 0) { ans++; } int tmp = mp[a[i]]; ans += (fenw.get(tmp)); fenw.modify(tmp, +1); } cout << ans << endl; return 0; }

Compilation message (stderr)

vudu.cpp: In function 'int main()':
vudu.cpp:56:34: error: no matching function for call to 'sort(__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >)'
   sort(unique(b.begin(), b.end()));
                                  ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from vudu.cpp:3:
/usr/include/c++/7/bits/stl_algo.h:4826:5: note: candidate: template<class _RAIter> void std::sort(_RAIter, _RAIter)
     sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
     ^~~~
/usr/include/c++/7/bits/stl_algo.h:4826:5: note:   template argument deduction/substitution failed:
vudu.cpp:56:34: note:   candidate expects 2 arguments, 1 provided
   sort(unique(b.begin(), b.end()));
                                  ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from vudu.cpp:3:
/usr/include/c++/7/bits/stl_algo.h:4856:5: note: candidate: template<class _RAIter, class _Compare> void std::sort(_RAIter, _RAIter, _Compare)
     sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
     ^~~~
/usr/include/c++/7/bits/stl_algo.h:4856:5: note:   template argument deduction/substitution failed:
vudu.cpp:56:34: note:   candidate expects 3 arguments, 1 provided
   sort(unique(b.begin(), b.end()));
                                  ^