hdu-5806 nanoape Loves Sequenceⅱ (ruler)

Source: Internet
Author: User

Topic Links:

Nanoape Loves Sequenceⅱ

Time limit:4000/2000 MS (java/others)

Memory limit:262144/131072 K (java/others)


Problem Descriptionnanoape, the retired Dog, have returned back to prepare for for the national Higher Education Entrance E xamination!

In the math class, Nanoape picked up sequences once again. He wrote down a sequence withNNumbers and a numbermOn the paper.

Now he wants to know the number of continous subsequences of the sequence in such a manner that thek-th largest number in the subsequence are no less than m.

Note:the length of the subsequence must is no less than k.

Inputthe first line of the input contains an integerT, denoting the number of test cases.

The first line of the input contains three integersn,m,k .

The second line of the input containsNIntegersa1,a2,.. . ,An , denoting the elements of the sequence.

1≤T≤10, 2≤N≤200000,1≤k ≤n / 2,  1≤m,ai≤< Span id= "mathjax-span-81" class= "Msubsup" >10 9

Outputfor each test case, print a line with one integer, denoting the answer.

Sample Input17 4 24 2 7 7 6 5 1

Sample Output18 Test instructions: Give a sequence, ask the number of interval k greater than or equal to M of what is the number of intervals? Idea: Deal with the interval prefixes greater than or equal to M, and then the ruler method to engage; AC Code:
/************************************************┆┏┓┏┓┆┆┏┛┻━━━┛┻┓┆┆┃┃┆┆┃━┃┆┆┃┳┛┗┳┃┆┆┃┃ ┆┆┃┻┃┆┆┗━┓┏━┛┆┆┃┃┆┆┃┗━━━┓┆┆┃ac Horse ┣┓┆┆┃┏┛┆┆┗┓┓┏━┳┓┏┛┆┆┃┫┫┃┫┫┆ ┆┗┻┛┗┻┛┆************************************************ * * #include <iostream> #include <cstdio># Include <cstring> #include <algorithm> #include <cmath>//#include <bits/stdc++.h> #include <stack> #include <map> using namespace std; #define for (i,j,n) for (int i=j;i<=n;i++) #define MST (SS,B) memset (ss,b,sizeof (ss)); typedef long Long LL;    Template<class t> void Read (t&num) {char CH; bool F=false; For (Ch=getchar (); ch< ' 0 ' | | Ch> ' 9 ';    f= ch== '-', Ch=getchar ()); for (num=0;    ch>= ' 0 ' &&ch<= ' 9 '; num=num*10+ch-' 0 ', Ch=getchar ()); F && (num=-num);}    int stk[70], tp;template<class t> inline void print (T p) {if (!p) {puts ("0"); return;} while (p) Stk[+ TP] = p%10, p/=10;    while (TP) Putchar (stk[tp--] + ' 0 '); Putchar (' \ n ');} Const LL Mod=1e9+7;const double Pi=acos ( -1.0); const int INF=1E9;CONST int N=2e5+10;const int Maxn=2e3+14;const double eps=        1e-12;int N,m,a[n],sum[n],k;int Main () {int t;        Read (t);            while (t--) {read (n); read (m); Read (k);                for (i,1,n) {read (a[i]);                if (a[i]>=m) sum[i]=sum[i-1]+1;            else sum[i]=sum[i-1];            } LL ans=0;            int r=1;                for (i,1,n-k+1) {R=max (i+k-1,r);                while (sum[r]-sum[i-1]<k&&r<=n) r++;            if (r<=n&&r-i+1>=k) ans=ans+ (n-r+1);        } cout<<ans<< "\ n"; } return 0;}

  

hdu-5806 nanoape Loves Sequenceⅱ (ruler)

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.