# Kuangbin_segtree D (POJ 2528)

Source: Internet
Author: User

Reason I skipped the coloring question for a moment because I always felt that there was something very high-end algorithm to query

It wasn't until I did the F question (ZOJ 1610) that I found out it was a violent statistic .... It's also about tens of thousands of units of length ....

F is not the PO up to choose a bit of difficulty in the D problem need to use the discretization

The pure discretization will be dyed before the stain is covered, so we need to insert a position between each of the two locations where the gap is greater than 1.

The above ideas refer to http://blog.csdn.net/non_cease/article/details/7383736 but the original po a little bit wrong mixed POJ data but it is really wrong ...

That is, the background may be accidentally counted, so when you count, ignore the background.

`#include <cstdio>#include<cstring>#include<algorithm>#defineINF 0x3f3f3f3f#defineMem (str,x) memset (str, (x), sizeof (str))#defineLson L, M, rt<<1#defineRson m+1, R, rt<<1|1using namespaceStd;typedefLong LongLL;Const intMAXN =10005;intN, hash[maxn<<3], col[maxn<<4];intans, LI[MAXN], RI[MAXN];BOOLVis[maxn];inlinevoidPush_down (intRT) {    if(~Col[rt]) {Col[rt<<1] = col[rt<<1|1] =Col[rt]; COL[RT]= -1; }}voidUpdateintLintRintCintLintRintRT) {    if(l <= l && R >=R) {Col[rt]=C; //printf ("%d-%d:%d\n", L, R, c);        return;    } push_down (RT); intm = (L + r) >>1; if(L <=m) Update (L, R, C, Lson); if(R >m) Update (L, R, C, Rson);}voidQueryintLintRintRT) {    if(L = =R) {        if(!vis[col[rt]) && ~Col[rt]) {            //printf ("%d at%d\n", Col[rt], L);ans++; VIS[COL[RT]]=true; }        return;    } push_down (RT); intm = (L + r) >>1;    Query (Lson); Query (Rson);}intBinary_search (intLintRintc) {    intm;  while(L <=R) {m= (L + r) >>1; if(Hash[m] = = c)returnm; Else if(Hash[m] > c) r = M-1; ElseL = m +1; }    return-1;}intMain () {intT; scanf ("%d", &t);  while(t--) {mem (col,-1); Mem (Vis,false); scanf ("%d", &N); intnn =0, MM =1;  for(inti =1; I <= N; i++) {scanf ("%d%d", &li[i], &Ri[i]); hash[++NN] =Li[i]; hash[++NN] =Ri[i]; } sort (Hash+1, hash+1+, N); //Remove Duplicate Data         for(inti =2; I <= nn; i++){            if(Hash[i]! = hash[i-1]) hash[++mm] =Hash[i]; }        //Insert a point between points that are more than 1 apart to prevent overwriting         for(inti = mm; i >1; i--){            if(Hash[i]-hash[i-1] >1) hash[++mm] = Hash[i]-1; } sort (Hash+1, hash+1+mm); //discrete construction of segment tree         for(inti =1; I <= N; i++){            intL = Binary_search (1, MM, li[i]); intR = Binary_search (1, MM, ri[i]); Update (L, R, I,1Mm1); //printf ("%d-%d:%d\n", L, R, I);} ans=0; Query (1Mm1); printf ("%d\n", ans); }    return 0;}`

Kuangbin_segtree D (POJ 2528)

Related Keywords:

### 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.