Language: C++

#include <bits/stdc++.h>
using namespace std;

int main(){
  int n;
  long long ans=0;
  cin >> n;
  vector<int> cnt(100000);
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
    ans += a.at(i);
    cnt(a.at(i))++;
  }
  sort(a.begin(),a.end());
  int q;
  cin >> q;
  vector<int> b(q),c(q);
  for(int i=0;i<q;i++){
    cin >> b.at(i) >> c.at(i);
  }
  
  for(int i=0;i<q;i++){
    if(count(b.at(i)) == 0) cout << ans << endl;
    else {
      ans -= cnt(b.at(i))*b.at(i);
      ans += cnt(b.at(i))*c.at(i);
      cnt(c.at(i)) += cnt(b.at(i));
      cnt(b.at(i)) = 0;
      cout << ans << endl;
    }
  }
     
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:13:8: error: no match for call to '(std::vector<int>) (__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)'
   13 |     cnt(a.at(i))++;
      |     ~~~^~~~~~~~~
a.cc:24:13: error: no matching function for call to 'count(__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)'
   24 |     if(count(b.at(i)) == 0) cout << ans << endl;
      |        ~~~~~^~~~~~~~~
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algo.h:4025:5: note: candidate: 'template<class _IIter, class _Tp> typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
 4025 |     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
      |     ^~~~~
/usr/include/c++/14/bits/stl_algo.h:4025:5: note:   candidate expects 3 arguments, 1 provided
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:101:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:101:1: note:   candidate expects 4 arguments, 1 provided
a.cc:26:17: error: no match for call to '(std::vector<int>) (__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)'
   26 |       ans -= cnt(b.at(i))*b.at(i);
      |              ~~~^~~~~~~~~
a.cc:27:17: error: no match for call to '(std::vector<int>) (__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)'
   27 |       ans += cnt(b.at(i))*c.at(i);
      |              ~~~^~~~~~~~~
a.cc:28:10: error: no match for call to '(std::vector<int>) (__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)'
   28 |       cnt(c.at(i)) += cnt(b.at(i));
      |       ~~~^~~~~~~~~
a.cc:28:26: error: no match for call to '(std::vector<int>) (__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)'
   28 |       cnt(c.at(i)) += cnt(b.at(i));
      |                       ~~~^~~~~~~~~
a.cc:29:10: error: no match for call to '(std::vector<int>) (__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)'
   29 |       cnt(b.at(i)) = 0;
      |       ~~~^~~~~~~~~