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 ...
随机推荐
- GetMemory 函数解析
GetMemory函数 代码1: void GetMemory(char *p){ p = (char*)malloc(100);}int main(int argc, char *argv[]){ ...
- Android 颜色大全 (colors.xml )
<resources> <color name="pink">#ffc0cb</color><!--粉红色 --> <colo ...
- css 动画 transform transition animation
1.transform transform 是通过在浏览器里面让网页元素 移动 旋转 透明 模糊 等方法来实现改变其外观的技术 -webkit-transform : translate(3em,0 ...
- [UVALive] 6492 Welcome Party(最小点覆盖)
6492 Welcome Party For many summers, the Agile Crystal Mining company ran an internship program for ...
- 自制单片机之六……串行I2C总线E2PROM AT24CXXX的应用
这一篇介绍I2C存储器的使用.主要是介绍AT24CXX系列器件,它分为两类,主要是通过被存储容量地址来分的,一类是AT24C02-AT24C16,它的存储容量从256字节到2048字节.另一类是AT2 ...
- PowerShell 简单模式识别 1
PowerShell 简单模式识别 1 10 6月, 2013 在 Powershell tagged 字符串 / 文本 / 通配符 by Mooser Lee 在验证用户的条目时,模式识别是必要并 ...
- cf493A Vasya and Football
A. Vasya and Football time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- c#秒转时分秒
2个办法 @{ int hour = item.track / 3600; int min = (item.track - hour * 3 ...
- linux下,FTP服务相关
虚拟机上安装完CentOS 6.5后,使用FTP工具(FlashFXP)来上传文件到虚拟机的linux,结果发现连接不上.现在解决了,解决方法总结一下: 1.先检查有没有安装ftp.好像包括两个部分, ...
- 人人必知的10个jQuery小技巧
收集的10个 jQuery 小技巧/代码片段,可以帮你快速开发. 1.返回顶部按钮 你可以利用 animate 和 scrollTop 来实现返回顶部的动画,而不需要使用其他插件. // Back t ...