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 ...
随机推荐
- Oracle V$SESSION详解
V$SESSION是APPS用户下面对于SYS.V_$SESSION 视图的同义词. 在本视图中,每一个连接到数据库实例中的session都拥有一条记录.包括用户session及后台进程如DBWR,L ...
- C# 保留2位小数
1.只要求保留N位不四舍5入 float f = 0.55555f; int i =(int)(f * 100); ...
- 【LeetCode】111 - Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...
- bzoj 3781 小B的询问(莫队算法)
[题意] 若干个询问sigma{ cnt[i]^2 } cnt[i]表示i在[l,r]内的出现次数. [思路] 莫队算法,裸题. 一个cnt数组即可维护插入与删除. [代码] #include< ...
- 本人为项目组制定的一份页面优化指南(easyui页面优化方案)
#本人为项目组制定的一份页面优化指南(easyui页面优化方案) ##背景 这是一篇我之前为项目组制定的页面优化指南,主要是面向表单页面,典型的像[注册用户](https://passport.cnb ...
- Iframe的应用以及父窗口和子窗口的相互访问
点评:Iframe和FRAME的区别,方便大家以后在使用过程中根据实际需要取舍.- function getParentIFrameDocument(aID) { var rv = null; // ...
- openstack neutron
- sysctl.conf
linux系统接口 允许改变正在运作linux系统接口Tcp/IP堆栈和虚拟内存系统的高级选项 用来控制Linux网络配置/proc/sys/net/core/ TCP/IP参数修改添加到/etc/s ...
- 第三百五十一天 how can I 坚持
是应该喜欢还是厌烦这种状态,犹豫不定,毫无目标. 人不贪,谁信,我嘴上说我不贪,可是内心已经把我出卖了,要不怎么股票会被套呢. 别人贪婪时我恐惧,别人恐惧时我贪婪,我成了什么,别人贪婪时,我狂妄,别人 ...
- Field 'SCHED_TIME' doesn't have a default value
出现这个情况的原因是: 我jar包使用的是quartz-2.1.7版本,但是初始化集群的dbTables脚本用的却是2.2.1版本的,导致出现这个异常,改用2.1.7的dbTables脚本之后即解决问 ...