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. 会话控制:SESSION,COOKIE

    1.http协议: HTTP—超文本传输协议,在TCP协议(长连接.像一个硬件)基础上; 特点:短连接,无状态协议,没法记录本次连接的状态;适用于静态页面的访问,对于后期某些页面是需要浏览器预知客户信 ...

  2. [原]我在Windows环境下的首个Libevent测试实例

    libevent对Windows环境也有很好的支持,不过初次学习和编译libevent简单实例,总是有一些陌生感的,只有成功编译并测试了一个实例,才会有恍然大悟的感觉.下面将要讲到的一个实例是我从网上 ...

  3. TCP segment of a reassembled PDU

    Wireshark有时候会显示这个东东. 此处PDU是指上层(如HTTP)的Protocol Data Unit,意指上层协议的一个协议段太长,无法放入单个TCP数据包. 如果你在wireshark中 ...

  4. oracle imp导入数据到另一个表空间

    http://blog.163.com/darlingchenlin@126/blog/static/7156283420100531431855/ 1.在第一个数据库导出数据:qlyg_xs_db_ ...

  5. activiti自定义流程之自定义表单(二):创建表单

    注:环境配置:activiti自定义流程之自定义表单(一):环境配置 在上一节自定义表单环境搭建好以后,我就正式开始尝试自己创建表单,在后台的处理就比较常规,主要是针对ueditor插件的功能在前端进 ...

  6. 【转】图片IMG标记的alt属性和title属性的使用

    alt text 替 换文字(alt text)是为了给那些不能看到你文档中图像的浏览者提供文字说明.这包括那些使用本来就不支持图像显示或者图像显示被关闭的浏览器的用户,视觉障碍的用户和使用屏幕阅读器 ...

  7. [Java Web – 3A] – Spring MVC开发注意事项

    1.使用Maven构建项目 2.SpringMVC 绝对路径的问题 首先要明确一点,在html中,资源文件也是有自己的URL,即href中是支持绝对路径.如下代码: <link href=&qu ...

  8. Spark工程开发常用函数与方法(Scala语言)

    import org.apache.spark.{SparkContext, SparkConf}import org.apache.spark.sql.{SaveMode, DataFrame}im ...

  9. python (1)一个简单的爬虫: python 在windows下 创建文件夹并写入文件

    1.一个简单的爬虫:爬取豆瓣的热门电影的信息 写在前面:如何创建本来存在的文件夹并写入 t_path = "d:/py/inn" #本来不存在inn,先定义路径,然后如果不存在,则 ...

  10. android的照片浏览器(一)至返回所有图片文件

    今天开始写android的照片浏览器 首先要解决的问题是要得到sdcard下面所有是图片的文件的目录 于是我先写了一个普通的java类 来得到后缀是.jpg,.bmp.png.jpeg的文件 pack ...