Codeforces Round #244 (Div. 2) B. Prison Transfer 线段树rmq
2015-07-01 20:30
417 查看
B. Prison Transfer
Time Limit: 20 SecMemory Limit: 256 MB
题目连接
http://codeforces.com/problemset/problem/427/BDescription
The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has 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, with a number written on their chests. The number is the severity of the crime he/she has committed. The greater the number, the more severe his/her crime was.
Then, the mayor told you to choose the c prisoners, who will be transferred to the other prison. He also imposed two conditions. They are,
The chosen c prisoners has to form a contiguous segment of prisoners.
Any of the chosen prisoner's crime level should not be greater then t. Because, that will make the prisoner a severe criminal and the mayor doesn't want to take the risk of his running away during the transfer.
Find the number of ways you can choose the c prisoners.
[b]Input[/b]
The first line of input will contain three space separated integers n (1 ≤ n ≤ 2·105), t (0 ≤ t ≤ 109) and c (1 ≤ c ≤ n). The next line will contain n space separated integers, the ith integer is the severity ith prisoner's crime. The value of crime severities will be non-negative and will not exceed 109.
[b]Output[/b]
Print a single integer — the number of ways you can choose the c prisoners.
[b]Sample Input[/b]
4 3 3
2 3 1 1
[b]Sample Output[/b]
2
HINT
[b]题意[/b]
给你n个人,让你选出连续c个人,要求这c个人的最大值小于t
问你有多少种选择方法
[b]题解:[/b]
正解大概双端队列吧
我写的线段树
[b]代码[/b]
#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> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define test freopen("test.txt","r",stdin) #define maxn 1050005 #define mod 10007 #define eps 1e-9 const int inf=0x3f3f3f3f; const ll infll = 0x3f3f3f3f3f3f3f3fLL; inline ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } //************************************************************************************** struct node { int l,r; int ma; }; node a[maxn*4]; int num[maxn]; void build(int x,int l,int r) { a[x].l=l,a[x].r=r; if(l==r) { a[x].ma=num[l]; return; } int mid=(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); } int query(int x,int l,int r) { int L=a[x].l,R=a[x].r; if(l<=L&&R<=r) return a[x].ma; int mid=(a[x].l+a[x].r)>>1; if(r<=mid) return query(x<<1,l,r); if(l>mid) return query(x<<1|1,l,r); return max(query(x<<1,l,mid),query(x<<1|1,mid+1,r)); } int main() { int n=read(),t=read(),c=read(),ans=0; c--; for(int i=1;i<=n;i++) num[i]=read(); build(1,1,n); for(int i=1;i<=n-c;i++) if(query(1,i,i+c)<=t) ans++; cout<<ans<<endl; }
相关文章推荐
- How to update jQuery Mobile in Dreamweaver CS6
- How to update jQuery Mobile in Dreamweaver CS6
- Jquery的个人学习笔记
- 【nodejs】jade模板入门
- jquery国内cdn
- JavaScript基本类型转换,== != === !==总结
- 深入浅出Ext JS 学习计划
- jQuery中间each实施例的方法
- ExtJs中分页时带查询条件
- Proactor VS Reactor
- 多屏复杂动画CSS技巧三则(转载)
- fedora22 安装fcitx
- Java NIO框架Netty教程(四) ChannelBuffer
- Error Code: 1175. You are using safe update mode
- 在JAVA中怎么清空StringBuffer变量内容
- jsp+servlet小练习
- js 闭包理解
- HTML5技术之图像处理:一个滑动的拼图游戏(转)
- [caffe]深度学习之图像分类模型VGG解读
- js 多选 反选