【HDU】 1166 Color the ball
来源:互联网 发布:战舰少女r 胡德 知乎 编辑:程序博客网 时间:2024/06/06 10:56
Color the ball
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 14092 Accepted Submission(s): 7055
Problem Description
N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一次颜色。但是N次以后lele已经忘记了第I个气球已经涂过几次颜色了,你能帮他算出每个气球被涂过几次颜色吗?
Input
每个测试实例第一行为一个整数N,(N <= 100000).接下来的N行,每行包括2个整数a b(1 <= a <= b <= N)。
当N = 0,输入结束。
当N = 0,输入结束。
Output
每个测试实例输出一行,包括N个整数,第I个数代表第I个气球总共被涂色的次数。
Sample Input
31 12 23 331 11 21 30
Sample Output
1 1 13 2 1
Author
8600
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;struct tree{ int l,r,k;};tree d[400005];int n,a,b,c[100005];void buildtree(int i,int l,int r){ d[i].l=l; d[i].r=r; d[i].k=0; if (l==r) return; buildtree(i*2,l,(l+r)/2); buildtree(i*2+1,(l+r)/2+1,r);}void _insert(int i,int l,int r){ int mid=(d[i].l+d[i].r)/2; if (d[i].l==l &&r==d[i].r) d[i].k++; else if (r<=mid) _insert(i*2,l,r); else if (l>mid) _insert(i*2+1,l,r); else { _insert(i*2,l,mid); _insert(i*2+1,mid+1,r); }}void solve(int i,int l,int r,int k){ int mid=(d[i].l+d[i].r)/2; if (d[i].l==d[i].r) { c[d[i].l]=k+d[i].k; return; } solve(i*2,l,mid,k+d[i].k); solve(i*2+1,mid+1,r,k+d[i].k);}int main(){ while(scanf("%d",&n),n) { buildtree(1,1,n); for (int i=1;i<=n;i++) { scanf("%d%d",&a,&b); _insert(1,a,b); } solve(1,1,n,0); for (int i=1;i<=n-1;i++) printf("%d ",c[i]); printf("%d",c[n]); printf("\n"); } return 0;}
0 0
- 【HDU】 1166 Color the ball
- Color the ball HDU
- Color the ball HDU
- Color the Ball HDU
- hdu 1556 color the ball
- hdu 1556Color the ball
- HDU 1556 - Color the ball
- hdu 1199 Color the Ball
- HDU 1199-Color the Ball
- Hdu 1556 Color the ball
- hdu 1556 Color the ball
- hdu 1556 Color the ball
- HDU 1566 Color the ball
- hdu 1556 Color the ball
- hdu 1556 Color the ball
- hdu 1556 Color the ball
- HDU-1199 color the ball
- hdu 1556 Color the ball
- STM32 理解宏定义的重要性
- 如何优化SQL语句的心得浅谈
- TegraK1(ubuntu)上添加QtCreator并运行OpenCv
- RecyclerView-干掉Listview和GridView
- NGUI所见即所得之UIAtlasMaker , UIAtlas
- 【HDU】 1166 Color the ball
- JAVA 笔记-JSP/Servlet(七)
- 欢迎使用CSDN-markdown编辑器
- mybatis-generator的使用
- Xamarin.InAppPurchased/Components
- LAMP环境配置-Apache的深入理解
- JAVA-JSP/Servlet 笔记(八)
- 查看ios7中的所有系统字体名字
- 几种排序算法java版