PKU 2528 mayor's posters discrete line segment tree

Source: Internet
Author: User

# Include <iostream>
# Include <stdio. h>
# Include <algorithm>
Using namespace STD;
Const int n = 20010;/* Is it PKU playing rogue or I opened too small? I originally followed 10010 by 10 * n, and the result is re, you can only pass n = 20010 !!!!! */

Int mark [10 * n];
Struct tree
{
Int L, R; // The number of discrete points
Int turn;
} T [8 * n * 4];

Struct point
{
Int beg, end;
Int turn;
} Dia [N * 10];

Int node [10 * n];
Int all;

Void maketree (int c, int L, int R)
{
T [C]. L = L;
T [C]. r = R;
T [C]. Turn = 0;
If (L = r)
{
Return;
}
Int mid = (L + r)> 1;
Maketree (C * 2, L, mid );
Maketree (2 * C + 1, Mid + 1, R );
}

Void Update (int c, int L, int R, int turn)
{
If (T [C]. L> = L & T [C]. r <= r)
{
T [C]. Turn = turn;
Return;
}
If (T [C]. Turn! = 0)
{
T [2 * C]. Turn = T [2 * C + 1]. Turn = T [C]. turn;
T [C]. Turn = 0;
}
Int mid = (T [C]. L + T [C]. R)> 1;
If (r <= mid)
Update (2 * C, L, R, turn );
Else if (L> mid)
Update (2 * C + 1, L, R, turn );
Else
{
Update (2 * C, L, mid, turn );
Update (2 * C + 1, Mid + 1, R, turn );
}
}

Void findans (int c)
{
If (T [C]. Turn! = 0 | T [C]. L = T [C]. R)
{
Mark [T [C]. Turn] = 1;
}
Else
{
Findans (C * 2 );
Findans (C * 2 + 1 );
}
}

Int F (INT num)
{
Int L = 1, R = all;
While (L <= r)
{
Int mid = (L + r)> 1;
If (num = node [Mid])
Return mid;
If (Num <node [Mid])
R = mid-1;
Else
L = Mid + 1;
}
}

Int main ()
{
Int N, I;
Int ans = 0;
Int CNT = 1;
Int T;
Scanf ("% d", & T );
While (t --)
{
Scanf ("% d", & N );
For (I = 0; I <n; I ++)
{
Scanf ("% d", & Dia [I]. Beg, & Dia [I]. End );
Dia [I]. Turn = I + 1;
Node [CNT ++] = Dia [I]. Beg;
Node [CNT ++] = Dia [I]. end;
Mark [I + 1] = 0;
}
Sort (node + 1, node + CNT );
All = 1;
For (I = 2; I <CNT; I ++)
{
While (I <CNT & node [I] = node [I-1]) I ++;
If (I! = CNT)
Node [++ all] = node [I];
}
Maketree (1, 1, all );
For (I = 0; I <n; I ++)
{
Int B = f (DIA [I]. Beg );
Int e = f (DIA [I]. End );
// Cout <B <"<e <Endl;
Update (1, B, E, DIA [I]. Turn );
}
Int sum = 0;
Findans (1 );
For (I = 1; I <= N; I ++)
If (MARK [I])
Sum ++;
Printf ("% d/N", sum );
}
Return 0;
}

 

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.