Y. 子数组和 I

    Type: Default 1000ms 256MiB

子数组和 I

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

题目背景

翻译自 CSES-1660 题。

题目描述

给定一个由 nn 个正整数构成的数组,你的任务是计算数组中和为 xx 的子数组的个数。

本题中子数组定义为:任意给定一个数组下标 l,r(1lrn)l,r(1\le l\le r\le n),得到的区间 [l,r][l,r] 中的数组元素 al,al+1,,ara_{l},a_{l+1},\cdots,a_r。即可以理解成连续子序列。

输入格式

第一行输入两个整数 nnxx,分别代表数组的大小和目标和 xx

第二行输入 nn 个整数 a1,a2,...,ana_1, a_2, ..., a_n,代表数组的值。

输出格式

输出一个整数,表示和为 xx 的子数组的个数。

样例

5 7
2 4 1 2 7
3

说明/提示

1n2105,1x,ai1091 \le n \le 2\cdot 10^5,1 \leq x,a_i \le 10^9

CSES练习二 排序贪心STL

Not Claimed
Status
Done
Problem
35
Open Since
2025-5-1 0:00
Deadline
2025-5-31 23:59
Extension
24 hour(s)