You are given an integer sequence of length N, a= {a1,a2,…,aN}, and an integer K.
a has N(N+1)⁄2 non-empty contiguous subsequences, {al,al+1,…,ar} (1≤l≤r≤N). Among them, how many have an arithmetic mean that is greater than or equal to K?
Constraints
- All input values are integers.
- 1≤N≤2×105
- 1≤K≤109
- 1≤ai≤109
Input
Input is given from Standard Input in the following format:
Output
Print the number of the non-empty contiguous subsequences with an arithmetic mean that is greater than or equal to K.
Sample Input 1
Sample Output 1
All the non-empty contiguous subsequences of a are listed below:
- {a1} = {7}
- {a1,a2} = {7,5}
- {a1,a2,a3} = {7,5,7}
- {a2} = {5}
- {a2,a3} = {5,7}
- {a3} = {7}
Their means are 7, 6, 19⁄3, 5, 6 and 7, respectively, and five among them are 6 or greater. Note that {a1} and {a3} are indistinguishable by the values of their elements, but we count them individually.
Sample Input 2
Sample Output 2
Sample Input 3
Sample Output 3
13
询问有多少区间和满足<=k*len;
暴力肯定不行;
我们要求的就是sum[r]-sum[l-1]>=k*(r-l+1)
--> sum[r]-k*r-(sum[l-1]-k*(l-1))>=0;
也就是求sum[r]-k*r>=sum[l-1]-k*(l-1)的数量;
树状数组!;
当然由于数量级太大,我们可以先离散化;
#include
#include
#include
#include
#include
#include
#include
#include
EPFL - Fighting