#abc233d. D - Count Interval

D - Count Interval

Score : 400400 points

问题描述

给定一个长度为 NN 的序列 A=(A1,A2,,AN)A=(A_1,A_2,\ldots,A_N),以及一个整数 KK

请问在序列 AA 中有多少个连续子序列的和为 KK

换句话说,有多少对整数 (l,r)(l,r) 满足以下所有条件?

  • 1lrN1\leq l\leq r\leq N
  • i=lrAi=K\displaystyle\sum_{i=l}^{r}A_i = K

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Given is a sequence of length NN: A=(A1,A2,,AN)A=(A_1,A_2,\ldots,A_N), and an integer KK.

How many of the contiguous subsequences of AA have the sum of KK? In other words, how many pairs of integers (l,r)(l,r) satisfy all of the conditions below?

  • 1lrN1\leq l\leq r\leq N
  • i=lrAi=K\displaystyle\sum_{i=l}^{r}A_i = K

Constraints

  • 1N2×1051\leq N \leq 2\times 10^5
  • Ai109|A_i| \leq 10^9
  • K1015|K| \leq 10^{15}
  • All values in input are integers.

其中约30%的数据 N5000N \le 5000

Input

Input is given from Standard Input in the following format:

NN KK

A1A_1 A2A_2 \ldots ANA_N

Output

Print the answer.

Sample Input 1

6 5
8 -3 5 7 0 -4

Sample Output 1

3

(l,r)=(1,2),(3,3),(2,6)(l,r)=(1,2),(3,3),(2,6) are the three pairs that satisfy the conditions.

Sample Input 2

2 -1000000000000000
1000000000 -1000000000

Sample Output 2

0

There may be no pair that satisfies the conditions.

update @ 2024/3/10 10:08:53