Language: C++

#include <cstdio>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <vector>
#include <set>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <string>
using u8t = std::uint64_t;
using i8t = std::int64_t;
#define F(I,N) for(i8t I=0,_N=N;I<_N;I++)
#define R(V) i8t V;std::cin>>V;
#define RV(V,N) std::vector<i8t> V;F(i,N){R(x)V.push_back(x);}
#define RL1(line) std::getline(std::cin,line);
#define RL(line) std::string line;RL0(line)
#define P(X) std::cout<<(X)<<std::endl;
int main() {
  R(N)R(K)RV(a,N);
  std::vector<i8t> s;
  i8t sum = 0;
  F(i,N){
    auto d = a[i] - K;
    sum+=d;
    s.push_back(sum);
  }
  //std::vector<i8t> sorted;
  std::multiset<i8t> sorted;
  sorted.insert(0);
  i8t count=0;
  F(i,N){
    auto s1 = s[i];
    auto ins = sorted.upper_bound(s1);
    //count += std::distance(sorted.begin(), ins);
    count += ins - sorted.begin();
    sorted.insert(ins,s1);
  }
  P(count);
  return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:37:18: error: no match for 'operator-' (operand types are 'std::_Rb_tree_const_iterator<long int>' and 'std::multiset<long int>::iterator' {aka 'std::_Rb_tree<long int, long int, std::_Identity<long int>, std::less<long int>, std::allocator<long int> >::const_iterator'})
   37 |     count += ins - sorted.begin();
      |              ~~~ ^ ~~~~~~~~~~~~~~
      |              |                 |
      |              |                 _Rb_tree_const_iterator<[...]>
      |              _Rb_tree_const_iterator<[...]>
In file included from /usr/include/c++/14/string:48,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_iterator.h:618:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__y.base() - __x.base())) std::operator-(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  618 |     operator-(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:618:5: note:   template argument deduction/substitution failed:
a.cc:37:33: note:   'std::_Rb_tree_const_iterator<long int>' is not derived from 'const std::reverse_iterator<_Iterator>'
   37 |     count += ins - sorted.begin();
      |                                 ^
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__x.base() - __y.base())) std::operator-(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1790 |     operator-(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note:   template argument deduction/substitution failed:
a.cc:37:33: note:   'std::_Rb_tree_const_iterator<long int>' is not derived from 'const std::move_iterator<_IteratorL>'
   37 |     count += ins - sorted.begin();
      |                                 ^