HDU1556 (tree-like array)

Source: Internet
Author: User

Color the ball

Time limit:9000/3000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 17044 Accepted Submission (s): 8513


problem DescriptionN balloons are lined up in a row, numbered from left to right in 1,2,3....N. Given 2 integers a B (a <= B) each time, Lele to ride his "Little Pigeon" brand electric car from balloon A to balloon B in turn to each balloon painted color. But n times after Lele has forgotten the first balloon has been painted several times, can you help him to figure out how many times each balloon has been painted color?InputThe first behavior of each test instance is an integer n, (n <= 100000). The next n rows, each line consists of 2 integers a B (1 <= a <= b <= N).
When n = 0, the input ends.OutputEach test instance outputs one row, including n integers, and number I indicates the number of times the balloon was painted in total.Sample Input31 12 23 331 11 21 30Sample Output1 1 1 3 2 1

Getting Started with tree arrays, interval updates, single-point queries

1 //2016.8.102 //tree-like array, interval update, single-point query3#include <iostream>4#include <cstdio>5#include <cstring>6 7 using namespacestd;8 9 intarr[100005], N;Ten  One intLowbit (intx) {returnx& (-x);} A  - intAddintPosintTT) - { the      for(inti = pos; i >0; i-=lowbit (i)) -Arr[i] + =tt; -     return 0; - } +  - intQueryintPOS) + { A     intsum =0;  at      for(inti = pos; I <= N; i+=lowbit (i)) -sum+=Arr[i]; -     returnsum; - } -  - intMain () in { -     intA, B; to      while(cin>>N) +     { -memset (arr,0,sizeof(arr)); the          for(inti =0; I < n; i++) *         { $scanf"%d%d", &a, &b);Panax NotoginsengAdd (b,1); -Add (A-1, -1); the         } +          for(inti =1; I <= N; i++) A           if(i = =N) theCout<<query (i) <<Endl; +           ElseCout<<query (i) <<" "; -     } $  $     return 0; -}

HDU1556 (tree-like array)

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.