HDU4509-湫湫系列故事——减肥记II(线段树)

湫湫系列故事——减肥记II

Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 2395    Accepted Submission(s): 1018


Problem Description
  虽然制定了减肥食谱,但是湫湫显然克制不住吃货的本能,根本没有按照食谱行动!
于是,结果显而易见…
  但是没有什么能难倒高智商美女湫湫的,她决定另寻对策——吃没关系,咱吃进去再运动运动消耗掉不就好了?
  湫湫在内心咆哮:“我真是天才啊~\(≧▽≦)/~”

  可是,大家要知道,过年回家多忙啊——帮忙家里做大扫除,看电影,看小说,高中同学聚餐,初中同学聚餐,小学同学聚餐,吃东西,睡觉,吃东西,睡觉,吃东西,睡觉……所以锻炼得抽着时间来。

  但是,湫湫实在太忙了,所以没时间去算一天有多少时间可以用于锻炼,现在她把每日行程告诉你,拜托你帮忙算算吧~

  皮埃斯:一天是24小时,每小时60分钟
 

Input
输入数据包括多组测试用例。
每组测试数据首先是一个整数n,表示当天有n件事要做。 
接下来n行,第i行是第i件事的开始时间和结束时间,时间格式为HH:MM。

[Technical Specification]
1. 1 <= n <= 500000
2. 00 <= HH <= 23
3. 00 <= MM <= 59
 

Output
请输出一个整数,即湫湫当天可以用于锻炼的时间(单位分钟)
 

Sample Input
  
  
1 15:36 18:40 4 01:35 10:36 04:54 22:36 10:18 18:40 11:47 17:53
 

Sample Output
  
  
1256 179
Hint
大量输入,建议用scanf读数据。
 
水的线段树。。。。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;
const int maxn = 2000;
struct node{
    int lson,rson;
    bool flag;
    int mid(){
        return (lson+rson)>>1;
    }
}tree[maxn*4];
void pushUp(int rt){
    tree[rt].flag = tree[rt<<1].flag&&tree[rt<<1|1].flag;
}
void build(int L,int R,int rt){
    tree[rt].lson = L;
    tree[rt].rson = R;
    tree[rt].flag = false;
    if(L==R)   return;
    int mid = tree[rt].mid();
    build(L,mid,rt<<1);
    build(mid+1,R,rt<<1|1);
}
void update(int L,int R,int l,int r,int rt){
    if(tree[rt].flag) return;
    if(L <= l && R >= r){
        tree[rt].flag = true;
        return;
    }
    int mid = tree[rt].mid();
    if(L <= mid){
        update(L,R,l,mid,rt<<1);
    }
    if(R > mid){
        update(L,R,mid+1,r,rt<<1|1);
    }
    pushUp(rt);
}
int query(int L,int R,int l,int r,int rt){
    if(tree[rt].flag){
        return r-l+1;
    }
    if(l==r) return 0;
    int mid = tree[rt].mid();
    int ret = 0;
    if(L <= mid) ret += query(L,R,l,mid,rt<<1);
    if(R > mid) ret += query(L,R,mid+1,r,rt<<1|1);
    return ret;
}
int main(){

    int n;
    while(~scanf("%d",&n)){
        build(0,1439,1);
        while(n--){
            int a,b,c,d;
            scanf("%d:%d %d:%d",&a,&b,&c,&d);
            update(a*60+b+1,c*60+d,0,1439,1);
        }
        printf("%d\n",1440-query(0,1439,0,1439,1));
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值