CF1042D.Petya and Array
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
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.
彼得亚有一个由 n 个整数组成的数组 a。他最近学习了前缀和,并因此能够非常快速地计算数组中任意区间的元素之和。这里的“区间”指数组中连续且非空的一段元素。
现在他想知道:他的数组中有多少个区间的元素之和小于 t?请帮助彼得亚计算这个数目。
更准确地说,你需要计算满足 al+al+1+⋯+ar−1+ar<t 的数对 (l,r)(其中 l≤r)的个数。
输入格式
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],元素和为 −1
输入解题思路,AI测评打分。不知道怎么写?