HDU 4908 BestCoder Sequence, hdu4908

Source: Internet
Author: User

HDU 4908 BestCoder Sequence, hdu4908

Mark numbers greater than M as numbers smaller than 1 M as-1 M itself as 0

The question is the number of consecutive sequences that require 0 and contain M.

Sum [I] is used to represent the sum of the numbers marked by the largest number of I numbers in 1st.

For all I at a location greater than or equal to M, We Need To sum the number of sum [j] = sum [I] at a location smaller than M as the answer.

# Include <bits. stdc ++. h> using namespace std; int sum [40020], f [80020]; int main () {int N, M, k,; while (scanf ("% d", & N, & M) = 2) {memset (f, 0, sizeof (f); memset (sum, 0, sizeof (sum); for (int I = 1; I <= N; I ++) {scanf ("% d", & a); if (a> M) sum [I] = sum [I-1] + 1; else if (a <M) sum [I] = sum [I-1]-1; else {k = I; sum [I] = sum [I-1] ;}for (int I = 0; I <= K-1; I ++) f [sum [I] + 40000] ++; int ans = 0; for (int I = k; I <= N; I ++) ans + = f [sum [I] + 40000]; printf ("% d \ n", ans);} return 0 ;}





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.