晋江市建设招投标网站,安平县护栏网站建设,网站搭建吧,购物网站策划方案正题
题目链接:https://www.luogu.com.cn/problem/P2717 题目大意 nnn个数#xff0c;求有多少个连续子序列的平均值大于等于kkk。 解题思路
因为长度会十分干扰#xff0c;所以我们将所有数减去kkk。问题就变为了求有多少连续子序列的和非负。用前缀和逆序对求就好了。 co…正题
题目链接:https://www.luogu.com.cn/problem/P2717 题目大意
nnn个数求有多少个连续子序列的平均值大于等于kkk。 解题思路
因为长度会十分干扰所以我们将所有数减去kkk。问题就变为了求有多少连续子序列的和非负。用前缀和逆序对求就好了。 codecodecode
#includecstdio
#includecstring
#includealgorithm
#define ll long long
#define lowbit(x) (x-x)
using namespace std;
const ll N1e510;
ll n,k,a[N],b[N],t[N],ans;
void change(ll x,ll num)
{while(xn)t[x]num,xlowbit(x);return;
}
ll ask(ll x)
{ll ans0;while(x)anst[x],x-lowbit(x);return ans;
}
int main()
{scanf(%lld%lld,n,k);for(ll i1;in;i)scanf(%lld,a[i]),a[i]a[i-1]-k,b[i]a[i];b[n1]0;sort(b1,b2n);ll munique(b1,b2n)-b-1;change(lower_bound(b1,b1m,0)-b,1);for(ll i1;in;i){a[i]lower_bound(b1,b1m,a[i])-b;ansask(a[i]);change(a[i],1);}printf(%lld,ans);
}