先把公式变个形,然后直接BIT 枚举右端点查询左端点累加答案
离散化好题,注意BIT写的时候右端点的范围是离散化区间的大小
#include<bits/stdc++.h>
using namespace std;
#define int long long
using ll = long long;
using pii = pair<int,int>;
const int N = 4e5+10;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
int qmi(int a,int b,int mod){int res=1;while(b){if(b&1)res=res*a%mod;b>>=1;a=a*a%mod;}return res;}int n,q,m;
int x,y;
int a[N];
vector<int>alls;
int tr[N];
int lowbit(int x){return x&-x;}
void modify(int x,int c){for(int i=x;i<=alls.size();i+=lowbit(i))tr[i]+=c;}
int query(int x){int res =0;for(int i=x;i;i-=lowbit(i))res+=tr[i];return res;}
int res = 0;int find(int x){return lower_bound(alls.begin(),alls.end(),x)-alls.begin()+1;
}void solve()
{cin>>n>>x>>y;for(int i=1;i<=n;i++)cin>>a[i],a[i]-=y;//a[r]-a[l-1]<=x//a[l-1]>=a[r]-x;//查询 a[l-1]alls.push_back(0);for(int i=1;i<=n;i++){alls.push_back(a[i]);a[i]+=a[i-1];alls.push_back(a[i]);}sort(alls.begin(),alls.end());alls.erase(unique(alls.begin(),alls.end()),alls.end());modify(find(0),1);for(int i=1;i<=n;i++){res+=query(alls.size())-query(find(a[i]-x)-1);modify(find(a[i]),1);}cout<<res;}signed main()
{ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);int _;//cin>>_;_ = 1;while(_--)solve();return 0;
}