1 15:36 18:40 4 01:35 10:36 04:54 22:36 10:18 18:40 11:47 17:53
1256 179Hint大量输入,建议用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; }
HDU4509-湫湫系列故事——减肥记II(线段树),布布扣,bubuko.com
原文:http://blog.csdn.net/mowayao/article/details/38588889