本文主要是介绍hdu 4883,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
#include <iostream>
#include <cstdio>
using namespace std;
const int MAX=100010;
struct Line {int left;int right;int cnt; //延迟标记
}a[MAX];int n,m,l,r; //n长度,m线段数
int sum;//函数中的num是节点编号//构建
void Build(int l, int r, int num) {a[num].left = l;a[num].right = r;a[num].cnt = 0;if(l==r)return ;int mid = (a[num].left + a[num].right)/2;Build(l, mid, num*2);Build(mid+1, r, num*2+1);
}//查询
void Query(int l, int r, int num) {if(a[num].cnt!=0) {sum += a[num].cnt*(r-l+1);}if(a[num].left == a[num].right)return ;int mid = (a[num].left + a[num].right)/2;if(r<=mid)Query(l, r, num*2);else if(l>mid)Query(l, r, num*2+1);else {Query(l, mid, num*2);Query(mid+1, r, num*2+1);}
}//更新
void Change(int l, int r, int num, int add) {if(l==a[num].left && r==a[num].right) {a[num].cnt+=add;return ;}if(a[num].left == a[num].right)return ;int mid = (a[num].left + a[num].right)/2;if(r<=mid)Change(l, r, num*2, add);else if(l>mid)Change(l, r, num*2+1, add);else {Change(l, mid, num*2, add);Change(mid+1, r, num*2+1, add);}
}int main()
{// freopen("in","r",stdin);// freopen("out","w",stdout);int ans,n,m,t,i,x,y,add,a1,a2,a3,a4;scanf("%d",&t);while( t-- ){Build(0,1440,1);scanf("%d",&m);while( m-- ){scanf("%d %d:%d %d:%d",&add,&a1,&a2,&a3,&a4);a1=60*a1+a2; a2=60*a3+a4;Change(a1,a2-1,1,add);}ans=0;for(i=0;i<=1440;i++){sum=0;Query(i,i,1);ans=(ans>sum?ans:sum);}printf("%d\n",ans);}return 0;
}
这篇关于hdu 4883的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!