Codeforces Round #244 (Div. 2) b. Prison Transfer segment Tree RMQ

Source: Internet
Author: User

B. Prison Transfer

Time Limit:20 Sec

Memory limit:256 MB

Topic Connection

Http://codeforces.com/problemset/problem/427/B

DescriptionThe Prison of your city have n prisoners. As the prison can ' t accommodate all of them, the city mayor have decided to transfer c of the prisoners to a prison located In another city.

For this reason, he made the N prisoners to stand in a line, and a number written on their chests. The number is the severity of the crime he/she have committed. The greater the number, the more severe his/her crime was.

Then, the mayor told your to choose the C-prisoners, who'll be transferred to the other prison. He also imposed and conditions. They is,

The chosen C prisoners have to form a contiguous segment of prisoners.
Any of the chosen prisoner's crime level should not being greater then T. Because, that'll make the prisoner a severe criminal and the mayor doesn ' t want to take the risk of his running away dur ing the transfer.

Find the number of ways you can choose the C prisoners.

Input

The first line of input would contain three space separated integers n (1≤n≤2 105), T (0≤t≤109) and C (1≤c≤n). The next line would contain n space separated integers, the ith integer is the severity ith prisoner ' s crime. The value of crime severities would be non-negative and would not exceed 109.

Output

Print a single integer-the number of ways you can choose the C prisoners.

Sample Input

4 3 3
2 3 1 1

Sample Output

2

HINT

Test instructions

give you n person, let you elect continuous C person, ask this C person's maximum value is less than t

Ask you how many options you have

Exercises

The positive solution is probably a double-ended queue.

I wrote the line of the tree

Code

#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>#include<map>#include<stack>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineTest Freopen ("Test.txt", "R", stdin)#defineMAXN 1050005#defineMoD 10007#defineEPS 1e-9Const intinf=0x3f3f3f3f;Constll infll =0x3f3f3f3f3f3f3f3fll;inline ll Read () {ll x=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}//**************************************************************************************structnode{intL,r; intMa;}; Node A[MAXN*4];intNUM[MAXN];voidBuildintXintLintR) {A[X].L=l,a[x].r=R; if(l==r) {a[x].ma=Num[l]; return; }    intMid= (l+r) >>1; Build (x<<1, L,mid); Build (x<<1|1, mid+1, R); A[x].ma=max (a[x<<1].ma,a[x<<1|1].ma);}intQueryintXintLintR) {    intL=a[x].l,r=A[X].R; if(l<=l&&r<=R)returna[x].ma; intMid= (A[X].L+A[X].R) >>1; if(r<=mid)returnQuery (x<<1, L,r); if(l>mid)returnQuery (x<<1|1, L,r); returnMax (Query (x<<1, L,mid), query (x<<1|1, mid+1, R));}intMain () {intN=read (), T=read (), C=read (), ans=0; C--;  for(intI=1; i<=n;i++) Num[i]=read (); Build (1,1, N);  for(intI=1; i<=n-c;i++)        if(Query (1, I,i+c) <=t) ans++; cout<<ans<<Endl;}

Codeforces Round #244 (Div. 2) b. Prison Transfer segment Tree RMQ

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.