luogu#P5161. WD与数列
WD与数列
Background
WD spends all day immersed in sequences and cannot stop.
Problem Description
WD really likes sequences. He thinks two sequences match if and only if and for , . That is, they have the same length, and by adding the same number to every element of one sequence, it can become exactly the other sequence.
Now CX gives him a large sequence of length . WD wants to know how many pairs of non-overlapping subarrays in the sequence are matching.
Input Format
The first line contains an integer , representing the length of the sequence. The second line contains integers, representing the numbers in the sequence.
Output Format
Output one integer in a single line, the number of matching subarrays.
5
1 2 3 4 5
13
10
1 0 -1 -1 -2 -2 -3 -3 -4 -5
65
Hint
For the sample, any two non-overlapping subarrays with the same length are matching. For length there are pairs, and for length there are pairs, so there are pairs in total.
For all data, the absolute value of each number in the sequence is . The time limit for is , and for the others it is .
Translated by ChatGPT 5