HDU 1823 two-dimensional line segment tree

Source: Internet
Author: User

HDU 1823 two-dimensional line segment tree

Question about two-dimensional line segment tree

Open two dimensions with height and liveliness respectively

Take height-100, lively * 10 as two intervals

The so-called two-dimensional query is to enter the second-dimensional query to find the correct position in the First-dimension query.


# Include "stdio. h" # include "string. h" double ans; double Max (double a, double B) {if (
 
  
Data [k]. mark [kk]. x) data [k]. mark [kk]. x = z; if (data [k]. mark [kk]. l = data [k]. mark [kk]. r) return; mid = (data [k]. mark [kk]. l + data [k]. mark [kk]. r)/2; if (w2 <= mid) updata_sec (w2, z, k, kk * 2); else updata_sec (w2, z, k, kk * 2 + 1);} void updata_main (int w1, int w2, double z, int k) {int mid; updata_sec (w2, z, k, 1 ); if (data [k]. l = data [k]. r) return; mid = (data [k]. l + data [k]. r)/2; if (w1 <= mid) updata_main (w1, w2, z, k * 2); else up Data_main (w1, w2, z, k * 2 + 1);} double query_sec (int l, int r, int k, int kk) {int mid; if (data [k]. mark [kk]. l = l & data [k]. mark [kk]. r = r) return data [k]. mark [kk]. x; mid = (data [k]. mark [kk]. l + data [k]. mark [kk]. r)/2; if (r <= mid) return query_sec (l, r, k, kk * 2); else if (l> mid) return query_sec (l, r, k, kk * 2 + 1); else return Max (query_sec (l, mid, k, kk * 2), query_sec (mid + 1, r, k, kk * 2 + 1);} void query_main (int l, int r, int ll, Int rr, int k) {int mid; if (data [k]. l = l & data [k]. r = r) {ans = Max (ans, query_sec (ll, rr, k, 1); return;} mid = (data [k]. l + data [k]. r)/2; if (r <= mid) query_main (l, r, ll, rr, k * 2); else if (l> mid) query_main (l, r, ll, rr, k * 2 + 1); else {query_main (l, mid, ll, rr, k * 2); query_main (mid + 1, r, ll, rr, k * 2 + 1) ;}} int main () {int n, x, w1, w2, l1, l2, r1, r2; double y, z; char ch [10]; while (scanf ("% d", & n )! = EOF) {if (n = 0) break; build_main (0,100, 1); while (n --) {scanf ("% s", ch ); if (ch [0] = 'I') {scanf ("% d % lf", & x, & y, & z); w1 = X-100; w2 = y * 10; updata_main (w1, w2, z, 1);} else {scanf ("% d % lf", & l1, & r1, & y, & z); l1-= 100; r1-= 100; l2 = y * 10; r2 = z * 10; if (l1> r1) {x = l1; l1 = r1; r1 = x;} if (l2> r2) {x = l2; l2 = r2; r2 = x;} ans =-1.0; query_main (l1, r1, l2, r2, 1); if (ans + 1 <= 0.000000001) printf ("-1 \ n"); else printf ("%. 1lf \ n ", ans) ;}} 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.