Color the ball
Time Limit: 9000/3000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 5851 accepted submission (s): 3116
Problem descriptionn balloons are arranged 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 <iostream> # include <cstring> using namespace STD; int tree [100100]; int maxn; void Update (int K, int v) {While (k <= maxn) {tree [k] + = V; int T = tree [k]; // printf ("tree [% d] = % d \ n", K, T); k + = K &-K; // K = K * 2; // printf ("k = % d \ n", k); // printf ("\ n") ;}} int read (int K) // çóçø ¼ ä1 µ½ K µä° íöμ {int sum = 0; while (k> 0) {// printf ("k111111 = % d \ n", k); sum + = tree [k]; // printf ("summmmmm = % d \ n ", sum); k-= K &-K; // Printf ("k2222222 = % d \ n", k); // printf ("\ n");} return sum;} int main () {int I, a, B, temp; while (scanf ("% d", & maxn) {temp = maxn; memset (tree, 0, sizeof (tree )); while (temp --) {scanf ("% d", & A, & B); Update (A, 1); Update (B + 1,-1 );} for (I = 1; I <= maxn; I ++) {printf ("% d", read (I); if (I! = Maxn) printf (""); else printf ("\ n") ;}} return 0 ;}