Color the ball (hangdian 1556)

Source: Internet
Author: User

Color the balltime limit: 9000/3000 ms (Java/other) memory limit: 32768/32768 K (Java/other) total submission (s): 8 accepted submission (s): 2 Font: times New Roman | verdana | georgiafont size: Batch → problem descriptionn balloons in a row, numbered 1, 2, 3 .... n. given two integers a B (A <= B) each time, Lele colors each balloon one time from balloon a to balloon B, riding his "little pigeon" electric car. But after N times, Lele has forgotten how many times the I-th balloon has been painted. Can you help him figure out how many times each balloon has been painted? Input the first behavior of each test instance is an integer N, (n <= 100000 ). next n rows, each row contains two integers, a B (1 <= A <= B <= N ).
When n = 0, the input ends. Output each test instance outputs a row, which contains N integers. The number of I represents the total number of times that the I balloon is colored. Sample Input
31 12 23 331 11 21 30
Sample output
1 1 13 2 1
/*树状数组应用。 */#include<stdio.h>#include<string.h> int n,tree[100010];int lowbit(int N){return N&(-N);}int add(int i,int t)//求第i个数之后都加上t. {while(i<=n){tree[i]+=t;i+=lowbit(i);}}int sum(int m) {int sum=0;while(m>0){sum+=tree[m];m-=lowbit(m);}return sum;}int main(){int i,a,b;while(scanf("%d",&n),n){memset(tree,0,sizeof(tree));for(i=0;i<n;i++){scanf("%d %d",&a,&b);add(a,1);  //将a之后的涂色次数加1. add(b+1,-1);//将b之后的涂色次数减1. }printf("%d",sum(1));for(i=2;i<=n;i++)   printf(" %d",sum(i));printf("\n");}return 0;}


Color the ball (hangdian 1556)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.