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)