Language: C++

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

const long long N=4e5+1e3+7;

long long n,a[N],k,s[N],ans;

long long tot,root,size[N],num[N],key[N],fa[N],son[N][2];

void pushup(long long x)
{
	size[x]=size[son[x][0]]+size[son[x][1]]+num[x];
}


void rotate(long long x)
{
	long long y=fa[x],z=fa[y],t=(son[y][0]==x);
	if(z)
		son[z][son[z][1]==y]=x;
	fa[x]=z;
	son[y][!t]=son[x][t];
	fa[son[y][!t]]=y;
	son[x][t]=y;
	fa[y]=x;
	pushup(y);
	pushup(x);
}



void splay(long long x,long long s)
{
	while(fa[x]!=s)
	{
		long long y=fa[x],z=fa[y];
		if(z!=s)
			if(son[z][0]==y^son[y][0]==x)
				rotate(x);
			else
				rotate(y);
		rotate(x);
	}
	if(s==0)
		root=x;
}


void insert(long long &x,long long v,long long s)
{
	if(!x)
	{
		x=++tot;
		size[x]=num[x]=1;
		son[x][0]=son[x][1]=0;
		key[x]=v;
		fa[x]=s;
		splay(x,0);
		return;
	}
	if(v==key[x])
	{
		num[x]++;
		size[x]++;
		splay(x,0);
		return;
	}
	insert(son[x][v>key[x]],v,x);
	pushup(x);
}

long long get(long long v)
{
	long long x=root;
	while(x&&v!=key[x])
		x=son[x][v>key[x]];
	return x;
}



void del(long long x)
{
	x=get(x);
	if(!x)
		return;
	splay(x,0);
	if(num[x]>1)
	{
		num[x]--;
		size[x]--;
		return;
	}
	if(!son[x][0]||!son[x][1])
		root=son[x][0]+son[x][1];
	else
	{
		long long y=son[x][1];
		while(son[y][0])
			y=son[y][0];
		splay(y,x);
		son[y][0]=son[x][0];
		fa[son[y][0]]=y;
		root=y;
	}
	fa[root]=0;
	pushup(root);
}

long long rank(long long v)
{
	insert(root,v,0);
	long long ans=size[son[root][0]];
	del(v);
	return ans;
}

int main()
{
	cin>>n>>k;
	for(long long i=1;i<=n;i++)
		cin>>a[i],a[i]-=k,s[i]=s[i-1]+a[i];
	insert(root,0,0);
	for(long long i=1;i<=n;i++)
	{
		insert(root,s[i],0);
		ans+=rank(s[i]+1)-1;
	}
	cout<<ans;
}

Compiler output:
a.cc: In function 'void pushup(long long int)':
a.cc:15:9: error: reference to 'size' is ambiguous
   15 |         size[x]=size[son[x][0]]+size[son[x][1]]+num[x];
      |         ^~~~
In file included from /usr/include/c++/14/string:53,
                 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:3:
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:11:20: note:                 'long long int size [401007]'
   11 | long long tot,root,size[N],num[N],key[N],fa[N],son[N][2];
      |                    ^~~~
a.cc:15:17: error: reference to 'size' is ambiguous
   15 |         size[x]=size[son[x][0]]+size[son[x][1]]+num[x];
      |                 ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:11:20: note:                 'long long int size [401007]'
   11 | long long tot,root,size[N],num[N],key[N],fa[N],son[N][2];
      |                    ^~~~
a.cc:15:33: error: reference to 'size' is ambiguous
   15 |         size[x]=size[son[x][0]]+size[son[x][1]]+num[x];
      |                                 ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:11:20: note:                 'long long int size [401007]'
   11 | long long tot,root,size[N],num[N],key[N],fa[N],son[N][2];
      |                    ^~~~
a.cc: In function 'void insert(long long int&, long long int, long long int)':
a.cc:57:17: error: reference to 'size' is ambiguous
   57 |                 size[x]=num[x]=1;
      |                 ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:11:20: note:                 'long long int size [401007]'
   11 | long long tot,root,size[N],num[N],key[N],fa[N],son[N][2];
      |                    ^~~~
a.cc:67:17: error: reference to 'size' is ambiguous
   67 |                 size[x]++;
      |                 ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:11:20: note:                 'long long int size [401007]'
   11 | long long tot,root,size[N],num[N],key[N],fa[N],son[N][2];
      |                    ^~~~
a.cc: In function 'void del(long long int)':
a.cc:94:17: error: reference to 'size' is ambiguous
   94 |                 size[x]--;
      |                 ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:11:20: note:                 'long long int size [401007]'
   11 | long long tot,root,size[N],num[N],key[N],fa[N],son[N][2];
      |                    ^~~~
a.cc: In function 'long long int rank(long long int)':
a.cc:116:23: error: reference to 'size' is ambiguous
  116 |         long long ans=size[son[root][0]];
      |                       ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:11:20: note:                 'long long int size [401007]'
   11 | long long tot,root,size[N],num[N],key[N],fa[N],son[N][2];
      |                    ^~~~
a.cc: In function 'int main()':
a.cc:130:22: error: reference to 'rank' is ambiguous
  130 |                 ans+=rank(s[i]+1)-1;
      |                      ^~~~
In file included from /usr/include/c++/14/bits/move.h:37,
                 from /usr/include/c++/14/bits/exception_ptr.h:41,
                 from /usr/include/c++/14/exception:166,
                 from /usr/include/c++/14/ios:41:
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:113:11: note:                 'long long int rank(long long int)'
  113 | long long rank(long long v)
      |           ^~~~