p2804-Mysterious number Title description (Simplified version)
There are n numbers, and in this n number, how many consecutive numbers are the averages greater than a given number of M?
Note: This number can be very large, please output this number to 92084931 modulo results.
Input/output format
Input Format:
A total of two lines.
The first behavior is two numbers n and M.
The second behavior n number.
output Format:
The result of a single row of a number, the solution of the problem to 92084931 modulo
Input/Output sample
Input Sample # #:
4 31 5) 4 2
Sample # # of output:
5
Input Sample #:
4 45 2) 7 3
Output Example #:
6
Description
"Sample Interpretation"
① for these 4 numbers, the solution for the problem has {5},{4},{5,4},{1,5,4},{5,4,2} A total of 5 groups.
② for these 4 numbers, the solution for the problem has {5},{7},{2,7},{7,3},{5,2,7},{5,2,7,3} A total of 6 groups.
"Data Size"
For 10% of data, 1
For 30% of data, 1
For 50% of data, 1
For 100% of data, 1
Analysis
Subtract the n numbers in the series by the M. Then a section of the and greater than 0 is to meet the requirements of a paragraph.
The question then translates to: How many intervals in the current sequence are more than 0.
It is easy to find the prefix of the array and put it in the arrays p.
If the number of I to the J number satisfies the requirement (assuming i<j), it is easy to think of p[j]-p[i-1]>0.
In other words: p[j]>p[i-1]
Question into: How many p[i]>p[j before P[j], add the number of answers relative to each p[j] is ans
The inverse of the prefix and sequence p
Expected complexity O (NLOGN)
lg-p2804 Mysterious number/lg-p1196 match queue merge sort, reverse