lg-p2804 Mysterious number/lg-p1196 match queue merge sort, reverse

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.