Logo
(追記) (追記ここまで)

32736번 - End-Balanced Subarrays 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB25212184.000%

문제

You are given an array $a$ of $n$ integers. A sub-array $[a_l, a_{l+1}, \cdots a_r]$ is considered end-balanced if $l<r$ and $a_l + a_r = a_{l+1} + ... + a_{r-1}$.

For example, the subarrays $[4, 9, 5],ドル $[-1, 3, 5, 9],ドル and $[0, 0]$ are considered end-balanced, and the subarrays $[0],ドル $[-2, -3, -5],ドル and $[1, 1]$ are not.

How many subarrays of $a$ are end-balanced?

입력

The first line of the input contains a single integer $t$ (1ドル \le t \le 10^4$) --- the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer $n$ (1ドル \le n \le 2\cdot 10^5$) --- the size of the array $a$.

The second line of each test case contains $n$ integers $a_1, a_2 \cdots a_n$ ($-10^9 \le a_i \le 10^9$) --- the elements of the array $a$.

It is guaranteed that the sum of $n$ over all test cases does not exceed 2ドル\cdot 10^5$.

출력

For each test case, print a single integer --- the number of end-balanced subarrays of $a$.

제한

예제 입력 1

7
5
1 2 3 4 5
3
0 0 0
4
-10 5 -5 10
6
2 2 2 2 2 2
7
1 0 1 0 1 0 1
5
1000000000 1000000000 1000000000 1000000000 1000000000
1
-1000000000

예제 출력 1

2
3
2
3
5
2
0

힌트

The end-balanced subarrays in the first test case are:

  • $[a_1, a_2, a_3, a_4] = [1, 2, 3, 4]$
  • $[a_2, a_3, a_4, a_5] = [2, 3, 4, 5]$

The end-balanced subarrays in the second test case are:

  • $[a_1, a_2] = [0, 0]$
  • $[a_2, a_3] = [0, 0]$
  • $[a_1, a_2, a_3] = [0, 0, 0]$

The end-balanced subarrays in the third test case are:

  • $[a_2, a_3] = [5, -5]$
  • $[a_1, a_2, a_3, a_4] = [-10, 5, -5, 10]$

출처

University > Rutgers University > Rutgers Programming Contest Fall 2024 C번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /