CF1042D.Petya and Array
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Petya has an array a consisting of n integers. He has learned partial sums recently, and now he can calculate the sum of elements on any segment of the array really fast. The segment is a non-empty sequence of elements standing one next to another in the array.
Now he wonders what is the number of segments in his array with the sum less than t . Help Petya to calculate this number.
More formally, you are required to calculate the number of pairs l,r ( l≤r ) such that al+al+1+⋯+ar−1+ar<t .
Petya 有一个由 n 个整数组成的数组 a 。他最近学会了部分求和,现在他可以非常快速地计算数组任意段上的元素之和。段是数组中一个挨着一个的非空元素序列。
现在他想知道数组中总和小于 t 的数段有多少。请帮助 Petya 计算这个数字。
更正式地说,您需要计算出 l,r ( l≤r ) 中有多少对是 al+al+1+⋯+ar−1+ar<t 。
输入格式
The first line contains two integers n and t ( 1≤n≤200000,∣t∣≤2⋅1014 ).
The second line contains a sequence of integers a1,a2,…,an ( ∣ai∣≤109 ) — the description of Petya's array. Note that there might be negative, zero and positive elements.
输入
第一行包含两个整数 n 和 t ( 1≤n≤200000,∣t∣≤2⋅1014 )。
第二行包含一串整数 a1,a2,…,an ( ∣ai∣≤109 ) - Petya 的数组描述。请注意,可能存在负、零和正元素。
输出格式
Print the number of segments in Petya's array with the sum of elements less than t .
输出
打印 Petya 数组中元素总和小于 t 的段的数量。
输入输出样例
输入#1
5 4 5 -1 3 4 -1
输出#1
5
输入#2
3 0 -1 2 -3
输出#2
4
输入#3
4 -1 -2 1 -2 3
输出#3
3
说明/提示
In the first example the following segments have sum less than 4 :
- [2,2] , sum of elements is −1
- [2,3] , sum of elements is 2
- [3,3] , sum of elements is 3
- [4,5] , sum of elements is 3
- [5,5] , sum of elements is −1
备注
在第一个示例中,以下线段的总和小于 4 :
- [2,2] ,元素总和为 −1 。
- [2,3] ,元素总和为 2 。
- [3,3] ,元素之和为 3 。
- [4,5] ,元素之和为 3 [5,5] , 元素之和为 3 [5,5] .
- [5,5] ,元素之和为 −1