BestCoder Round #36 (hdu5200)Strange Class(离线)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud
Trees
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
1)x+1=y or y+1=x;
2)there exists an uncutted tree which is numbered z, and x is in the same block with z, while y is also in the same block with z.
Now CodeFamer want to cut some trees whose height is not larger than some value, after those trees are cut, how many tree blocks are there?
For each case, first line contains two integers N and Q separated by exactly one space, N indicates there are N trees, Q indicates there are Q queries.
In the following N lines, there will appear h[1],h[2],h[3],…,h[N] which indicates the height of the trees.
In the following Q lines, there will appear q[1],q[2],q[3],…,q[Q] which indicates CodeFamer’s queries.
Please process to the end of file.
[Technical Specification]
1 \leq N, Q \leq 50000
0≤h[i]≤1000000000(109)
0≤q[i]≤1000000000(109)
5
2
3
6
2
2
In this test case, there are 3 trees whose heights are 5 2 3.
For the query 6, if CodeFamer cuts the tree whose height is not large than 6, the height form of left trees are -1 -1 -1(-1 means this tree was cut). Thus there is 0 block.
For the query 2, if CodeFamer cuts the tree whose height is not large than 2, the height form of left trees are 5 -1 3(-1 means this tree was cut). Thus there are 2 blocks.
//#####################
//Author:fraud
//Blog: http://www.cnblogs.com/fraud/
//#####################
#include <iostream>
#include <sstream>
#include <ios>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cctype>
using namespace std;
#define XINF INT_MAX
#define INF 0x3FFFFFFF
#define MP(X,Y) make_pair(X,Y)
#define PB(X) push_back(X)
#define REP(X,N) for(int X=0;X<N;X++)
#define REP2(X,L,R) for(int X=L;X<=R;X++)
#define DEP(X,R,L) for(int X=R;X>=L;X--)
#define CLR(A,X) memset(A,X,sizeof(A))
#define IT iterator
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<PII> VII;
typedef vector<int> VI;
int Scan()
{
int res, ch=;
while(!(ch>=''&&ch<='')) ch=getchar();
res=ch-'';
while((ch=getchar())>=''&&ch<='')
res=res*+ch-'';
return res;
}
void Out(int a)
{
if(a>)
Out(a/);
putchar(a%+'');
}
int h[];
int q[];
int p[];
int px[];
int ans[];
bool cmp(int x,int y){
if(q[x]==q[y])return x<y;
return q[x]<q[y];
}
bool cmp1(int x,int y){
return h[x]<h[y];
}
int main()
{
//ios::sync_with_stdio(false);
int n,m;
while(scanf("%d%d",&n,&m)!=EOF){
h[n+]=-;h[]=-;
for(int i=;i<=n;i++)h[i]=Scan();
for(int i=;i<=n;i++)px[i]=i;
sort(px+,px+n+,cmp1);
for(int i=;i<=m;i++)q[i]=Scan();
for(int i=;i<=m;i++)p[i]=i;
sort(p+,p+m+,cmp);
int j=;
ans[]=;
p[]=;
for(int i=;i<=m;i++){
ans[p[i]]=ans[p[i-]];
while(j<=n&&h[px[j]]<=q[p[i]]){
h[px[j]]=-;
if(h[px[j]-]==-&&h[px[j]+]==-)ans[p[i]]--;
else if(h[px[j]-]>&&h[px[j]+]>)ans[p[i]]++;
j++;
}
}
for(int i=;i<=m;i++){
printf("%d\n",ans[i]);
}
}
return ;
}
BestCoder Round #36 (hdu5200)Strange Class(离线)的更多相关文章
- BestCoder Round #36 (hdu5198)Strange Class(水题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Strange Class Time Limit: 2000/1000 MS (J ...
- BestCoder Round #36
HDU5198 Strange Class 问题描述 在Vivid的学校里,有一个奇怪的班级(SC).在SC里,这些学生的名字非常奇怪.他们的名字形式是这样的anbncn(a,b,c两两不相同.).例 ...
- BestCoder Round #36 [B] Gunner
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=5199 先对树的高度排序,然后对每次射击高度二分查找即可,打过之后数目变为0. #include< ...
- BestCoder Round #36 (hdu5199)Gunner(水题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Gunner Time Limit: 8000/4000 MS (Java/Oth ...
- 二分查找 BestCoder Round #36 ($) Gunner
题目传送门 /* 题意:问值为x的个数有几个,第二次查询就是0 lower/upper_bound ()函数的使用,map也可过,hash方法不会 */ #include <cstdio> ...
- bestcoder Round #7 前三题题解
BestCoder Round #7 Start Time : 2014-08-31 19:00:00 End Time : 2014-08-31 21:00:00Contest Type : ...
- BestCoder Round #75 1001 - King's Cake
Problem Description It is the king's birthday before the military parade . The ministers prepared a ...
- BestCoder Round #14
Harry And Physical Teacher Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- hdu 5667 BestCoder Round #80 矩阵快速幂
Sequence Accepts: 59 Submissions: 650 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536 ...
随机推荐
- uva 10125 - Sumsets
题意: 输入n,然后输入n个数字,,要在这n个数字中找出a,b,c,d..满足a,b,c,d是不同元素,并且a + b + c = d...求出最大的d 直接暴力时间复杂度为O(n^4)..会超时.. ...
- angular-route 里面templeteUrl 动态加载
https://segmentfault.com/q/1010000002524964
- C# 过滤SerialPort端口
C#中的SerialPort类只能通过SerialPort.GetPortNames()来获取端口名字,而且出来都是COM+数字的字样,如果我要识别COM端口是什么设备的,它就无能为力了,此时我们可以 ...
- 当 IDENTITY_INSERT 设置为 OFF 时,不能为表中的标识列插入显式值。
出现以上错误是应为在执行insert语句时,将自动增加的字段加入,导致报错. 解决办法:把自增列的字段从插入语句中删除
- linux系统编程之进程(四):进程退出exit,_exit区别即atexit函数(转载)
一,进程终止有5种方式: 正常退出: 从main函数返回 调用exit 调用_exit 异常退出: 调用abort 由信号终止 二,exit和_exit区别: 关于_exit(): #include ...
- linux虚拟机命令行模式下,某些命令显示乱码问题。
刚安装了linux虚拟机,使用vi命令试着修改IP配置,结果出现乱码.配置IP的文件内容本身没有乱码,主要是vi编辑的命令行的提示出现乱码,例如,按i是插入模式,结果底下出现乱码提升,不是提示插入. ...
- poj1220:高精度进制转换模板题
今天撸3708 一直奇怪的re 就先放下了,写这个题的过程中学习了一个高精度进制转换,用这个模板写了1220 记录一下: #include <iostream> #include < ...
- Web开发之RSET API
REST介绍 如果要说什么是REST的话,那最好先从Web(万维网)说起. 什么是Web呢?读者可以查看维基百科的词条(http://zh.wikipedia.org/zh-cn/Web),具体的我就 ...
- Java代码编译和执行的整个过程
Java代码编译是由Java源码编译器来完成,流程图如下所示: Java字节码的执行是由JVM执行引擎来完成,流程图如下所示: Java代码编译和执行的整个过程包含了以下三个重要的机制: Java源码 ...
- HDU4514(非连通图的环判断与图中最长链)
题目:设计风景线 题意:给定一个无向图,图可能是非连通的,如果图中存在环,就输出YES,否则就输出图中最长链的长度. 分析:首先我们得考虑这是一个无向图,而且有可能是非连通的,那么就不能直接像求树那样 ...