Problem H

High bridge, low bridge

Q: There are one high bridge and one low bridge across the river. The river has flooded twice, why the high bridge is flooded twice but the low bridge is flooded only once?

A: Because the lower bridge is so low that it's still under water after the first flood is over.

If you're confused, here's how it happens:

  • Suppose high bridge and low bridge's heights are 2 and 5, respectively, and river's initial water level is 1.
  • First flood: the water level is raised to 6(Both bridges are flooded), and then back to 2(high bridge is not flooded anymore, but low bridge is still flooded).
  • Second flood: the water level is raised to 8(The high bridge is flooded again), and then back to 3.

Just a word game, right? The key is that if a bridge is still under water (i.e. the water level is no less than the bridge height) after a flood, then next time it will not be considered flooded again.

Suppose the i-th flood raises the water level to ai and then back to bi. Given n bridges' heights, how many bridges are flooded at least k times? The initial water level is 1.

Input

The input contains at most 25 test cases. Each test case begins with 3 integers n, m, k in the first line (1<=n,m,k<=105). The next line contains n integers hi, the heights of each bridge (2<=hi<=108). Each of the next m lines contains two integers ai and bi (1<=bi<ai<=108, ai>bi-1). The file size of the whole input does not exceed 5MB.

Output

For each test case, print the number of bridges that is flooded at least k times.

Sample Input

2 2 2
2 5
6 2
8 3
5 3 2
2 3 4 5 6
5 3
4 2
5 2

Output for the Sample Input

Case 1: 1
Case 2: 3

Explanation

For the second sample, 5 bridges are flooded 1, 2, 3, 2, 0 times, respectively.


The Ninth Hunan Collegiate Programming Contest (2013)

Problemsetter: Rujia Liu Special Thanks: Feng Chen, Md. Mahbubul Hasan

这道试题很好。用笔画一下,其实就是区间更新,区间询问的树状数组吧,关键是求更新的区间,其实直接使用StL的查找也是可以的。还是那个道理,二分查找的变法很多,

不要太依赖STL ,基础一定要打好。

#include <iostream>
#include <stdio.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <stack>
#include <math.h>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std ;
typedef long long LL ;
const int Max_N= ;
struct Node{
int raise ;
int down ;
};
Node water[Max_N] ;
int bridge[Max_N] ;
int N ,M ,K ;
int find_first_big_id(int x){
int Left= ;
int Right=N ;
int mid ;
int ans_id=- ;
while(Left<=Right){
mid=(Left+Right)>> ;
if(bridge[mid]>x){
ans_id=mid ;
Right=mid- ;
}
else
Left=mid+ ;
}
return ans_id ;
}
int find_last_less_or_equal_id(int x){
int Left= ;
int Right=N ;
int mid ;
int ans_id=- ;
while(Left<=Right){
mid=(Left+Right)>> ;
if(bridge[mid]>x){
Right=mid- ;
}
else{
ans_id=mid ;
Left=mid+ ;
}
}
return ans_id ;
}
int C[Max_N] ;
inline int lowbit(int x){
return x&(-x) ;
}
void Insert(int id ,int x){
while(id<=N){
C[id]+=x ;
id+=lowbit(id) ;
}
}
int get_sum(int id){
int sum= ;
while(id>=){
sum+=C[id] ;
id-=lowbit(id) ;
}
return sum ;
}
int main(){
/*int x ;
while(cin>>N>>x){
for(int i=1;i<=N;i++)
cin>>bridge[i] ;
cout<<find_last_less_or_equal_id(x)<<endl ;
}*/
int L ,R ,ans ,k= ;
while(scanf("%d%d%d",&N,&M,&K)!=EOF){
for(int i=;i<=N;i++)
scanf("%d",&bridge[i]) ;
for(int i=;i<=M;i++)
scanf("%d%d",&water[i].raise,&water[i].down) ;
sort(bridge+,bridge++N) ;
water[].down= ;
fill(C,C+N+,) ;
for(int i=;i<M;i++){
L=find_first_big_id(water[i].down) ;
R=find_last_less_or_equal_id(water[i+].raise) ;
// cout<<L<<" "<<R<<endl ;
if(L==-||R==-)
continue ; Insert(L,) ;
Insert(R+,-) ;
}
ans= ;
for(int i=;i<=N;i++){
if(get_sum(i)>=K)
ans++ ;
}
printf("Case %d: %d\n",k++,ans) ;
}
return ;
}

The Ninth Hunan Collegiate Programming Contest (2013) Problem H的更多相关文章

  1. The Ninth Hunan Collegiate Programming Contest (2013) Problem A

    Problem A Almost Palindrome Given a line of text, find the longest almost-palindrome substring. A st ...

  2. The Ninth Hunan Collegiate Programming Contest (2013) Problem F

    Problem F Funny Car Racing There is a funny car racing in a city with n junctions and m directed roa ...

  3. The Ninth Hunan Collegiate Programming Contest (2013) Problem I

    Problem I Interesting Calculator There is an interesting calculator. It has 3 rows of button. Row 1: ...

  4. The Ninth Hunan Collegiate Programming Contest (2013) Problem J

    Problem J Joking with Fermat's Last Theorem Fermat's Last Theorem: no three positive integers a, b, ...

  5. The Ninth Hunan Collegiate Programming Contest (2013) Problem G

    Problem G Good Teacher I want to be a good teacher, so at least I need to remember all the student n ...

  6. The Ninth Hunan Collegiate Programming Contest (2013) Problem L

    Problem L Last Blood In many programming contests, special prizes are given to teams who solved a pa ...

  7. The Ninth Hunan Collegiate Programming Contest (2013) Problem C

    Problem C Character Recognition? Write a program that recognizes characters. Don't worry, because yo ...

  8. German Collegiate Programming Contest 2013:E

    数值计算: 这种积分的计算方法很好,学习一下! 代码: #include <iostream> #include <cmath> using namespace std; ; ...

  9. German Collegiate Programming Contest 2013:B

    一个离散化的简单题: 我用的是STL来做的离散化: 好久没写离散化了,纪念一下! 代码: #include<cstdio> #include<cstring> #include ...

随机推荐

  1. [oracle] ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务 的解决方法

    ORACLE 32位数据库正常安装,sqlplus 正常连接数据库但是PL/SQL developer 64位却报出这个错误. 第一反应是缺少32位客户端.下载安装,配置完成后如图所示: 还是报这个错 ...

  2. mootools upgrate from 1.2 to 1.3 or 1.4

    Update from 1.2 to 1.3 lorenzos edited this page on 8 Jul 2011 · 2 revisions Pages 19 Home Home Chan ...

  3. 【jmeter】ANT批量执行Jmeter脚本

    一.环境准备: 1.Jdk1.6或以上:命令行输入:java -version,出现如下提示说明安装成功 2.ANT下载:http://ant.apache.org/bindownload.cgi 命 ...

  4. windows下 更新 android studio SDK 到最新版本 解决方案

    一.设置代理信息 打开android studio>>File>>Settings>>Appearance&Behavion>>System S ...

  5. iMac一体机安装苹果和Win7双系统

    前几天,有个客户说有一苹果的一体机,想装苹果和Win7双系统.约好了时间,带上工具就过去了.去的路上,用手机上网查了一下苹果电脑装双系统的过程.虽然以前也有给苹果的电脑安装过双系统,但次数不多而且时间 ...

  6. 【MySQL】索引长度的一些限制

    有同学问到InnoDB的索引长度问题,简单说几个tips. MySQL的每个单表中所创建的索引长度是有限制的,且对不同存储引擎下的表有不同的限制. myisam表,单列索引,最大长度不能超过 1000 ...

  7. 【转】SQL Server sql_variant 类型的比较

    sql_variant 类型用于存储SQL SERVER中支持的各种数据类型. 为了进行 sql_variant 比较,SQL Server 数据类型层次结构顺序划分为多个数据类型系,sql_vari ...

  8. VS 使用Sql Server 数据库增删改查

    /// <summary> /// 执行查询语句,返回DataSet /// </summary> /// <param name="SQLString&quo ...

  9. struts 2 <s:select> 标签

    名称 必填 缺省值 类型 描述 emptyOption false false Boolean 是否在题头选项后面添加一个空的(--)选项 headerKey false   Object/Strin ...

  10. HDU 1011 Starship Troopers 树形DP 有坑点

    本来是一道很水的树形DP题 设dp[i][j]表示,带着j个人去攻打以节点i为根的子树的最大收益 结果wa了一整晚 原因: 坑点1: 即使这个节点里面没有守卫,你如果想获得这个节点的收益,你还是必须派 ...