Counting Subsequences | ||||||
| ||||||
Description | ||||||
"47 is the quintessential random number," states the 47 society. And there might be a grain of truth in that. For example, the first ten digits of the Euler's constant are: 2 7 1 8 2 8 1 8 2 8 And what's their sum? Of course, it is 47. You are given a sequence S of integers we saw somewhere in the nature. Your task will be to compute how strongly does this sequence support the above claims. We will call a continuous subsequence of S interesting if the sum of its terms is equal to 47. E.g., consider the sequence S = (24, 17, 23, 24, 5, 47). Here we have two interesting continuous subsequences: the sequence (23, 24) and the sequence (47). Given a sequence S, find the count of its interesting subsequences. | ||||||
Input | ||||||
The first line of the input file contains an integer T(T <= 10) specifying the number of test cases. Each test case is preceded by a blank line. The first line of each test case contains the length of a sequence N(N <= 500000). The second line contains N space-separated integers – the elements of the sequence. Sum of any continuous subsequences will fit in 32 bit signed integers. | ||||||
Output | ||||||
For each test case output a single line containing a single integer – the count of interesting subsequences of the given sentence. | ||||||
Sample Input | ||||||
2
13
2 7 1 8 2 8 1 8 2 8 4 5 9
7
2 47 10047 47 1047 47 47 | ||||||
Sample Output | ||||||
3 4
注意存sum的时候不能写成 a[sum] = 1; 因为他可能在序列中有0,在这里错了好几发; 其他的就没什么了,注意范围要用map;
|
hrbust 1005 Counting Subsequences【map】
最新推荐文章于 2021-10-13 15:33:16 发布