[Two-dimensional line segment tree] HDU 1823

Source: Internet
Author: User

A very bare two-dimensional line segment tree. For the first time, a two-dimensional line segment tree is also a tree cover tree. The first dimension is then the second-dimensional. The first and second-dimensional operations are similar.

Speaking back to HDU, there is a bit of water. Remember to submit C ++ when submitting, and g ++ will die for you!

# Define N 210 struct node {int Al, Ar; double MX ;}; struct node1 {int HL, HR; node subt [4000] ;}t [N * 4]; void build_sub (int id, int RT, int LL, int RR) {// second-dimensional build T [ID]. subt [RT]. al = ll; t [ID]. subt [RT]. AR = RR; t [ID]. subt [RT]. MX =-1.0; If (LL = RR) {return;} int mid = (LL + RR)> 1; build_sub (ID, RT <1, ll, mid); build_sub (ID, RT <1 | 1, Mid + 1, RR);} void build (int id, int L, int R, int LL, int RR) {// One-dimensional build T [ID]. hl = L; t [ID ]. HR = r; build_sub (ID, 1, ll, RR); If (L = r) return; int mid = (L + r)> 1; build (ID <1, L, mid, ll, RR); Build (ID <1 | 1, Mid + 1, R, ll, RR );} void add_sub (int id, int RT, int act, double love) {// insert T [ID] In the second dimension. subt [RT]. MX = max (Love, t [ID]. subt [RT]. MX); If (T [ID]. subt [RT]. al = T [ID]. subt [RT]. AR) return; int mid = (T [ID]. subt [RT]. al + T [ID]. subt [RT]. AR)> 1; if (Act <= mid) add_sub (ID, RT <1, Act, love); else add_sub (ID, RT <1 | 1, Act, love); t [ID]. subt [RT]. MX = max (T [ID]. subt [RT <1]. MX, t [ID]. subt [RT <1 | 1]. MX);} void add (int id, int H, int act, double love) {// insert add_sub (ID, 1, Act, love) first ); if (T [ID]. hl = T [ID]. HR) {return;} int mid = (T [ID]. hl + T [ID]. HR)> 1; if (H <= mid) add (ID <1, h, act, love); else add (ID <1 | 1, h, act, love);} double sear (int id, int RT, int LL, int RR) {// search for the second-dimensional if (T [ID]. subt [RT]. al = ll & T [ID]. subt [RT]. AR = RR) {return t [ID]. subt [RT]. MX;} int mid = (T [ID]. subt [RT]. al + T [ID]. subt [RT]. AR)> 1; if (RR <= mid) return sear (ID, RT <1, ll, RR); else if (LL> mid) return sear (ID, RT <1 | 1, ll, RR); else return max (SEAR (ID, RT <1, ll, mid), sear (ID, RT <1 | 1, Mid + 1, RR);} double query (int id, int L, int R, int LL, int RR) {// query the second-dimensional if (T [ID]. hl = L & T [ID]. hR = r) {return sear (ID, 1, ll, RR);} int mid = (T [ID]. hl + T [ID]. HR)> 1; if (r <= mid) return query (ID <1, L, R, ll, RR); else if (L> mid) return query (ID <1 | 1, L, R, ll, RR ); else return max (query (ID <1, L, mid, ll, RR), query (ID <1 | 1, Mid + 1, R, ll, rr);} int main () {int N; while (scanf ("% d", & N) {int I, j; build (1,100,200, ); char STR [3]; while (n --) {scanf ("% s", STR); If (STR [0] = 'I ') {Double X, Y; int h; scanf ("% d % lf", & H, & X, & Y); int xx = x * 10; add (1, h, XX, Y);} else {int H1, H2; double x1, x2; int Y1, Y2; SC ANF ("% d % lf", & H1, & H2, & X1, & x2); Y1 = x1 * 10, y2 = x2 * 10; if (h1> H2) Swap (H1, H2); // trick! If (Y1> Y2) Swap (Y1, Y2); double ans = query (1, H1, H2, Y1, Y2); If (ANS =-1.0) printf ("-1 \ n"); else printf ("%. 1lf \ n ", ANS) ;}} return 0 ;}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Related Article

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.