Language: C++

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

typedef long long ll;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

struct pa {
  int i;
  int num;

  bool operator<(const pa& right) const {
    return num == right.num ? i < right.i : num < right.num;
  }
};

int main() {
  ll n, ans[100001] = {};
  cin >> n;
  pa a[n];
  rep(i, 0, n) {
    cin >> a[i].num;
    a[i].i = i;
  }
  sort(a, a + n);

  ll z = a[n - 1].num, zz = z, m = 1145141919;
  dep(i, n - 2, 0) {
    if(z != a[i].num) {
      m = min(m, a[i + 1].i);
      ans[m] += (z - a[i].num) * (n - i - 1);
      zz = z;
      z = a[i].num;
    }
  }

  m = min(m, a[0].i);
  ans[m] += (zz - a[0].num) * n;

  rep(i, 0, n) {
    cout << ans[i] << endl;
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:39:14: error: no matching function for call to 'min(ll&, int&)'
   39 |       m = min(m, a[i + 1].i);
      |           ~~~^~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:39:14: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   39 |       m = min(m, a[i + 1].i);
      |           ~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:39:14: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   39 |       m = min(m, a[i + 1].i);
      |           ~~~^~~~~~~~~~~~~~~
a.cc:46:10: error: no matching function for call to 'min(ll&, int&)'
   46 |   m = min(m, a[0].i);
      |       ~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:46:10: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   46 |   m = min(m, a[0].i);
      |       ~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:46:10: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   46 |   m = min(m, a[0].i);
      |       ~~~^~~~~~~~~~~