#P17579. [JAG 2026 Summer Camp #3] Noise Cancelling

    ID: 20287 远端评测题 3000ms 2048MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>二分分治哈希 hashingICPC2026Z 函数

[JAG 2026 Summer Camp #3] Noise Cancelling

Problem Description

A sequence XX consisting of nonzero integers is called noise-cancelling if there exists a positive integer mm such that its length is 2m2m and

xi+xi+m=0x_i+x_{i+m}=0

holds for every ii (1≤i≤m1\le i\le m), where xix_i denotes the ii-th element of XX. In other words, the second half of a noise-cancelling sequence is the elementwise negation of its first half, so the corresponding elements cancel each other out. In particular, no sequence of odd length is noise-cancelling.

For example, (1,2,−3,4,−1,−2,3,−4)(1,2,-3,4,-1,-2,3,-4) is noise-cancelling.

You are given a sequence of NN nonzero integers (a1,a2,…,aN)(a_1,a_2,\ldots,a_N). Find the number of pairs of integers (l,r)(l,r) (1≤l≤r≤N1\le l\le r\le N) such that the contiguous subsequence (al,al+1,…,ar)(a_l,a_{l+1},\ldots,a_r) is noise-cancelling.

Input Format

The input consists of a single test case of the following format.

N
a_1 a_2 ... a_N

The first line contains an integer NN (1≤N≤2×1051\le N\le2\times10^5), representing the length of the sequence.

The second line contains NN nonzero integers a1,a2,…,aNa_1,a_2,\ldots,a_N (1≤∣ai∣≤N1\le |a_i|\le N), representing the elements of the sequence.

Output Format

Print a single integer representing the number of pairs (l,r)(l,r) such that (al,al+1,…,ar)(a_l,a_{l+1},\ldots,a_r) is noise-cancelling.

9
1 -3 2 -2 -1 3 -2 2 -2
4
20
-1 -1 -1 1 1 1 -1 -1 1 1 -1 -1 -1 1 1 -1 1 -1 -1 1
26