HDU 1556 Color the ball

Source: Internet
Author: User

Topic Connection

http://acm.hdu.edu.cn/showproblem.php?pid=1556

Color the Balldescription

$N $ A row of balloons, numbered from left to right $1,2,3....n.$ every time a given 2 integers $a\ B (a \leq B) $,lele for riding his "Little Pigeon" brand electric cars from the balloon $a$ start to Balloon $ $b in turn give each balloon color. But $n$ times after Lele has forgotten the first $i$ balloon has been painted several times, can you help him figure out how many times each balloon has been painted color?

Input

The first behavior of each test instance is an integer $n, (N \leq 100000) $. The next n rows, each line consists of 2 integers $a\ B (1 \leq a \leq b \leq N) $.
When $n = 0$, the input ends.

Output


Each test instance outputs one row, including $n$ integers, and the number of $i$ represents the total number of times the $i$ balloon was painted.

Sampleinput

3
1 1
2 2
3 3
3
1 1
1 2
1 3
0

Sampleoutput

1 1 1
3 2 1

Line segment Tree:
1#include <algorithm>2#include <iostream>3#include <cstdlib>4#include <cstring>5#include <cstdio>6#include <vector>7#include <map>8 usingstd::cin;9 usingstd::cout;Ten usingStd::endl; One usingStd::find; A usingStd::map; - usingstd::p air; - usingstd::vector; the #defineAll (c) (c). Begin (), (c). End () - #defineCLS (arr,val) memset (arr,val,sizeof (arr)) - #defineITER (c) Decltype ((c). Begin ()) - #defineCpresent (c, E) (Find (All (c), (e))! = (c). End ()) + #defineRep (i, n) for (int i = 0; i < (int) (n); i++) - #defineTR (c, I) for (ITER (c) i = (c). Begin (); I! = (c). end (); ++i) + #definePB (E) push_back (e) A #defineMP (A, b) Make_pair (A, B) at Const intMax_n =100010; -typedef unsignedLong Longull; - #defineMid ((l+r) >>1) - #defineLC (ROOT&LT;&LT;1) - #defineRC (root<<1|1) - structNode {intVal;}; in intArr[max_n]; - structSegtree { toNode Seg[max_n <<2]; +InlinevoidInit () {CLS (SEG,0); } -InlinevoidPush_down (introot) { the         if(Seg[root].val! =0) { *             int&t =Seg[root].val; $Seg[lc].val + =T;Panax NotoginsengSeg[rc].val + =T; -t =0; the         } +     } AInlinevoidUpdateintRootintLintRintXinty) { the         if(X > R | | y < L)return; +         if(x <= l && y >= R) {Seg[root].val + =1;return; } - Push_down (root); $ Update (LC, L, Mid, X, y); $Update (RC, Mid +1, R, X, y); -     } -InlineintQueryintRootintLintRintp) { the         if(P > R | | p < l)return 0; -         if(P <= L && p >= R)returnSeg[root].val;Wuyi Push_down (root); the         intRET =0; -RET + =Query (LC, L, Mid, p); WuRET + = query (RC, Mid +1, R, p); -         returnret; About     } $ }seg; - intMain () { - #ifdef LOCAL -Freopen ("In.txt","R", stdin); AFreopen ("OUT.txt","w+", stdout); + #endif the     intN, a, B; -      while(~SCANF ("%d", &n) &&N) { $ seg.init (); theRep (i, N) scanf ("%d%d", &a, &b), Seg.update (1,1, N, a, b); theRep (i, n) arr[i] = Seg.query (1,1, N, i +1); theRep (i, N) printf ("%d%c", Arr[i], I < n-1?' ':'\ n'); the     } -     return 0; in}
View Code

HDU 1556 Color the ball

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.