HDU 1556Color the ball
来源:互联网 发布:居民社保退休工资算法 编辑:程序博客网 时间:2024/06/06 01:56
题意:线段树水题,区间更新,带上lazy标记即可;
#include<iostream>#include<queue>#include<vector>#include<map>#include<set>#include<algorithm>#include<stack>#include<cstring>#include<cstdio>#define N 100005#define INF 0x3f3f3f3fusing namespace std;typedef struct node{int x;int y;int date;}node;typedef struct list{int x;int y;}list;node a[4*N];list c[N];int b[N];void built(int root,int first,int end){if(first==end){a[root].x=first;a[root].y=end;a[root].date=0;return ;}int mid=(first+end)/2;built(root*2,first,mid);built(root*2+1,mid+1,end);a[root].x=a[root*2].x;a[root].y=a[root*2+1].y;a[root].date=0;}void U(int root,int first,int end,int l,int r){if(l<=first&&end<=r){a[root].date++;return ;}int mid=(first+end)/2;if(a[root].date!=0){a[root*2].date+=a[root].date;a[root*2+1].date+=a[root].date;a[root].date=0;}if(l<=mid) U(2*root,first,mid,l,r);if(r>mid) U(2*root+1,mid+1,end,l,r);}void Q(int root,int first,int end){if(first==end){b[first]=a[root].date;return ;}if(a[root].date!=0){a[root*2].date+=a[root].date;a[root*2+1].date+=a[root].date;a[root].date=0;}int mid=(first+end)/2;Q(2*root,first,mid);Q(2*root+1,mid+1,end);}int main(){int n;while(scanf("%d",&n)==1&&n!=0){memset(b,0,sizeof(b));for(int i=1;i<=n;i++){scanf("%d %d",&c[i].x,&c[i].y);}built(1,1,n);for(int i=1;i<=n;i++){U(1,1,n,c[i].x,c[i].y);}Q(1,1,n);for(int i=1;i<=n;i++){if(i==1){printf("%d",b[i]);}else{printf(" %d",b[i]);}}printf("\n");}return 0;}
阅读全文
0 0
- hdu 1556 color the ball
- hdu 1556Color the ball
- HDU 1556 - Color the ball
- Hdu 1556 Color the ball
- hdu 1556 Color the ball
- hdu 1556 Color the ball
- hdu 1556 Color the ball
- hdu 1556 Color the ball
- hdu 1556 Color the ball
- hdu 1556 Color the ball
- HDU 1556 Color the ball
- HDU 1556 Color the ball
- HDU 1556 Color the ball
- HDU 1556 Color the ball
- HDU 1556 Color the ball
- HDU 1556 Color the ball
- HDU 1556 Color the ball
- HDU 1556 Color the ball
- 【论文待读】Gcforest https://www.zhihu.com/question/56474891
- 判断线段与直线交点——noyj 管道问题
- C++ 日常笔记(2)
- 逆向与分析-WebBrowserPassView消息分析
- Linux--RH254---uint 11 Bash
- HDU 1556Color the ball
- 解决Linux_CentOS上网问题
- Linux下如何定位Java进程CPU利用率过高原因
- Python IDE:PyCharm
- 菜鸟看源码之HashTable
- Rotate List
- python 文件读写
- HashMap的理解
- Flex定制Tree外观