CF1042D.Petya and Array

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Petya has an array aa consisting of nn 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 tt . Help Petya to calculate this number.

More formally, you are required to calculate the number of pairs l,rl, r ( lrl \le r ) such that al+al+1++ar1+ar<ta_l + a_{l+1} + \dots + a_{r-1} + a_r < t .
Petya 有一个由 nn 个整数组成的数组 aa 。他最近学会了部分求和,现在他可以非常快速地计算数组任意段上的元素之和。段是数组中一个挨着一个的非空元素序列。

现在他想知道数组中总和小于 tt 的数段有多少。请帮助 Petya 计算这个数字。

更正式地说,您需要计算出 l,rl, r ( lrl \le r ) 中有多少对是 al+al+1++ar1+ar<ta_l + a_{l+1} + \dots + a_{r-1} + a_r \lt t

输入格式

The first line contains two integers nn and tt ( 1n200000,t210141 \le n \le 200\,000, |t| \le 2\cdot10^{14} ).

The second line contains a sequence of integers a1,a2,,ana_1, a_2, \dots, a_n ( ai109|a_{i}| \le 10^{9} ) — the description of Petya's array. Note that there might be negative, zero and positive elements.
输入

第一行包含两个整数 nntt ( 1n200000,t210141 \le n \le 200\,000, |t| \le 2\cdot10^{14} )。

第二行包含一串整数 a1,a2,,ana_1, a_2, \dots, a_n ( ai109|a_{i}| \le 10^{9} ) - Petya 的数组描述。请注意,可能存在负、零和正元素。

输出格式

Print the number of segments in Petya's array with the sum of elements less than tt .
输出

打印 Petya 数组中元素总和小于 tt 的段的数量。

输入输出样例

  • 输入#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 44 :

  • [2,2][2, 2] , sum of elements is 1-1
  • [2,3][2, 3] , sum of elements is 22
  • [3,3][3, 3] , sum of elements is 33
  • [4,5][4, 5] , sum of elements is 33
  • [5,5][5, 5] , sum of elements is 1-1
    备注

在第一个示例中,以下线段的总和小于 44

  • [2,2][2, 2] ,元素总和为 1-1
  • [2,3][2, 3] ,元素总和为 22
  • [3,3][3, 3] ,元素之和为 33
  • [4,5][4, 5] ,元素之和为 33 [5,5][5, 5] , 元素之和为 33 [5,5][5, 5] .
  • [5,5][5, 5] ,元素之和为 1-1
首页