Codeforces Round #244 (Div. 2) B. Prison Transfer 线段树rmq
B. Prison Transfer
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/problemset/problem/427/B
Description
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.
Input
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.
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
题意
给你n个人,让你选出连续c个人,要求这c个人的最大值小于t
问你有多少种选择方法
题解:
正解大概双端队列吧
我写的线段树
代码
#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=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** struct node
{
int l,r;
int ma;
};
node a[maxn*];
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)>>;
build(x<<,l,mid);
build(x<<|,mid+,r);
a[x].ma=max(a[x<<].ma,a[x<<|].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)>>;
if(r<=mid)
return query(x<<,l,r);
if(l>mid)
return query(x<<|,l,r);
return max(query(x<<,l,mid),query(x<<|,mid+,r));
}
int main()
{
int n=read(),t=read(),c=read(),ans=;
c--;
for(int i=;i<=n;i++)
num[i]=read();
build(,,n);
for(int i=;i<=n-c;i++)
if(query(,i,i+c)<=t)
ans++;
cout<<ans<<endl;
}
Codeforces Round #244 (Div. 2) B. Prison Transfer 线段树rmq的更多相关文章
- Codeforces Round #244 (Div. 2) B. Prison Transfer
题目是选出c个连续的囚犯,而且囚犯的级别不能大于t #include <iostream> using namespace std; int main(){ int n,t,c; cin ...
- Codeforces Round #305 (Div. 2) D题 (线段树+RMQ)
D. Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #603 (Div. 2) E. Editor(线段树)
链接: https://codeforces.com/contest/1263/problem/E 题意: The development of a text editor is a hard pro ...
- Codeforces Round #530 (Div. 2) F (树形dp+线段树)
F. Cookies 链接:http://codeforces.com/contest/1099/problem/F 题意: 给你一棵树,树上有n个节点,每个节点上有ai块饼干,在这个节点上的每块饼干 ...
- Codeforces Round #546 (Div. 2) E 推公式 + 线段树
https://codeforces.com/contest/1136/problem/E 题意 给你一个有n个数字的a数组,一个有n-1个数字的k数组,两种操作: 1.将a[i]+x,假如a[i]+ ...
- Codeforces Round #222 (Div. 1) D. Developing Game 线段树有效区间合并
D. Developing Game Pavel is going to make a game of his dream. However, he knows that he can't mak ...
- Codeforces Round #275 Div.1 B Interesting Array --线段树
题意: 构造一个序列,满足m个形如:[l,r,c] 的条件. [l,r,c]表示[l,r]中的元素按位与(&)的和为c. 解法: 线段树维护,sum[rt]表示要满足到现在为止的条件时该子树的 ...
- Codeforces Round #271 (Div. 2) F. Ant colony 线段树
F. Ant colony time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #406 (Div. 2) D. Legacy (线段树建图dij)
D. Legacy time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...
随机推荐
- javascript的变态位运算
javascript的变态位运算 var a = "10" | 0; alert(a); alert (typeof a);结果为10,number. 这就是说这条语句可以将字符串 ...
- IOS播放音乐和音效
1.播放音效 1.1 首先获取到音效文件路径 NSString *path = [[NSBundle mainBundle] pathForResource:soundFileName ofType: ...
- 《Windows核心编程》第5版 学习进度备忘
学习资源:<Windows核心编程>第5版 知识基础支持: 本书与<Windows程序设计>第5版珍藏版结合很好,二者重叠内容不多,二者互补性强,而且相关方面的优秀书籍 跳过的 ...
- bzoj 1806 [Ioi2007]Miners 矿工配餐(DP)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1806 [题意] 给定一个权在1..3内的序列,在保持相对位置不变的情况下拆分成两个序列 ...
- How to Keep Alive SSH Sessions
How to Keep Alive SSH Sessions Many NAT firewalls time out idle sessions after a certain period of t ...
- iOS 检测有没有安装其它应用 和ios9下要注意的地方
UIApplication *app = [UIApplication sharedApplication]; NSURL *url = [NSURL URLWithString:@"Tri ...
- URAL-1981 Parallel and Perpendicular 水题
题目链接:http://www.cnblogs.com/zhsl/p/3395868.html 水题,注意细节. //STATUS:C++_AC_31MS_333KB #include <fun ...
- 数据库中使用 Synonym和openquery
如果,你想在一台数据库服务器上,查询另一个台数据服务器的数据该如何做呢?如果,你想在同一台数据服务器上,在不同的数据库之间查询数据,又该怎么办呢?那就让我为你介绍Synonym和openquery吧. ...
- 关于设置MX记录
简介:正确设置MX(Mail Exchanger)邮件交换记录是企业电子邮件服务稳定运行的基本条件,我们经常发现很多企业电子邮箱管理员因为设置了不符合规范的MX记录,导致重要的外部邮件退回或者丢失. ...
- git 安装与使用场景
1. 安装 yum install git #自动安装依赖 centos sudo apt-get install git #ubutu http://msysgit.github.io/ #wind ...