• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Uva 省赛傻逼题 H

我勒个去,每次无论什么代码总TM的有各种错误,这游戏能玩?

Problem H

Time limit: 1.000 seconds

 

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

 

 1 #include <map>
 2 #include <queue>
 3 #include <vector>
 4 #include <string>
 5 #include <cstdio>
 6 #include <cstring>
 7 #include <iostream>
 8 #include <algorithm>
 9 using namespace std;
10 #define maxn 100005
11 #define ll long long
12 #define INF 0x7fffffff
13 ll sum[maxn<<2];
14 ll add[maxn<<2];
15 int h[maxn];
16 int n,m,k;
17 void up(int rt){sum[rt]=sum[rt<<1]+sum[rt<<1|1];}
18 void down(int rt,int m){
19     if(add[rt]){
20         add[rt<<1]+=add[rt];
21         add[rt<<1|1]+=add[rt];
22         sum[rt<<1]+=(m-(m>>1))*add[rt];
23         sum[rt<<1|1]+=(m>>1)*add[rt];
24         add[rt]=0;
25     }
26 }
27 void build(int l,int r,int rt){
28     add[rt]=0;
29     if(l==r){sum[rt]=0;return;}
30     int m=l+(r-l)/2;
31     build(l,m,rt<<1);
32     build(m+1,r,rt<<1|1);
33     up(rt);
34 }
35 void update(int L,int R,int l,int r,int rt){
36     if(L<=l&&R>=r){sum[rt]+=(ll)r-l+1;add[rt]++;return;}
37     down(rt,r-l+1);
38     int m=l+(r-l)/2;
39     if(L<=m)update(L,R,l,m,rt<<1);
40     if(R>m)update(L,R,m+1,r,rt<<1|1);
41     up(rt);
42 }
43 ll query(int p,int l,int r,int rt){
44     if(l==r)return sum[rt];
45     down(rt,r-l+1);
46     int m=l+(r-l)/2;
47     ll res=0;
48     if(p<=m)res+=query(p,l,m,rt<<1);
49     if(p>m)res+=query(p,m+1,r,rt<<1|1);
50     return res;
51 }
52 int main(){
53     int a,b,t;
54     int cas=1;
55     while(~scanf("%d%d%d",&n,&m,&k)){
56         for(int i=0;i<n;i++)scanf("%d",&h[i]);
57         sort(h,h+n);
58         t=1;
59         build(0,n-1,1);
60         for(int i=0;i<m;i++){
61             scanf("%d%d",&a,&b);
62             a=upper_bound(h,h+n,a)-h-1;
63             t=upper_bound(h,h+n,t)-h;
64             update(t,a,0,n-1,1);
65             t=b;
66         }
67         t=0;
68         for(int i=0;i<n;i++)if(query(i,0,n-1,1)>=k)t++;
69         printf("Case %d: ",cas++);
70         printf("%d\n",t);
71     }
72     return 0;
73 }
View Code 2013-10-14 22:13:01 

 

posted @ 2013-10-14 22:10  HaibaraAi  阅读(180)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3