HDU 1832 Luck and Love (two-dimensional line segment tree)

Source: Internet
Author: User
Problem Description the farthest distance in the world is not separated by the ends of the Earth
But I am in front of you
But you don't know that I love you
-Zhang Xiaoyu

Some days ago, Feng bingye gave a wedding notice to Wiskey, and the number of invitations reached 5 million. Oh, my God, but it's an astronomical number. I don't know how many MM flocked to it, and suddenly there was nothing to do with it, even the aunt who swept the floor came to join in. -_-|
Because of the large number of people, Wiskey was too busy to handle all the statistics, and he ran home to rest. This is enough for Feng bingye. He has to handle two kinds of tasks. First, he must accept the registration of MM, the second is to help Wiskey find the highest fate among qualified MM.
 


The Input question contains multiple test data. The first digit is M, indicating that there are M consecutive operations. When M = 0, the processing is aborted.
Next is a operator C.
When the operator is 'I', it indicates that there is A MM registration, followed by an integer, H indicates height, two floating point numbers, A indicates activity, and L indicates fate. (100 <= H <= 200, 0.0 <= A, L <= 100.0)
When the operator is 'Q', the following four floating point numbers, H1, H2, indicate the height range, A1, A2, and so on, output the highest fate value in MM that meets the height and liveliness requirements. (100 <= H1, H2 <= 200, 0.0 <= A1, A2 <= 100.0)
All input floating point numbers have only one decimal place.
 


For each query operation, the Output outputs the highest fate value in one row, keeping a decimal number.
Output-1 for queries that cannot be found.
 


Sample Input
8I 160 50.5 165 601_ I 30.0 166 80.5I 10.0 170 501_ I 80.5 150 77.5Q 166 10.0 166 601_q 177 10.0 166 501_ I 40.0 166 99.9Q 177 10.0 50.00
 


Sample Output
80.550000099.9



Bare two-dimensional line segment tree.

Note that the query may be x1> x2, y1> y2. In addition, if a value already exists at the position during the update, it is not directly overwritten but max.

(I did not pay attention to it, but AC should not be set to 0 at the beginning, because the fate value may be 0 when the subject is active)


# Include <cstdio> # include <cstring> # include <algorithm> # define lson o <1, l, m # define rson o <1 | 1, m + 1, rusing namespace std; int T, h, N = 202, M = 1002, x1, x2, y1, y2, a; double tmpa, ll, tmpy1, tmpy2; char s [3]; double mx [222 <2] [1111 <2]; void updatey (int o, int l, int r, int oo, int OK) {if (l = r) {if (OK =-1) mx [oo] [o] = max (ll, mx [oo] [o]); // not directly overwrite, but take the maximum value else mx [oo] [o] = max (mx [oo <1] [o], m X [oo <1 | 1] [o]); return;} int m = (l + r)> 1; if (a <= m) updatey (lson, oo, OK); else updatey (rson, oo, OK); mx [oo] [o] = max (mx [oo] [o <1], mx [oo] [o <1 | 1]);} void updatex (int o, int l, int r) {if (l = r) {updatey (1, 1, M, o,-1); return;} int m = (l + r)> 1; if (h <= m) updatex (lson ); else updatex (rson); updatey (1, 1, M, o, 1);} double queryy (int o, int l, int r, int oo) {if (y1 <= l & r <= y2) ret Urn mx [oo] [o]; int m = (l + r)> 1; double ans =-1.0; if (y1 <= m) ans = queryy (lson, oo); if (m <y2) ans = max (ans, queryy (rson, oo); return ans;} double queryx (int o, int l, int r) {if (x1 <= l & r <= x2) return queryy (1, 1, M, o); int m = (l + r)> 1; double ans =-1.0; if (x1 <= m) ans = queryx (lson); if (m <x2) ans = max (ans, queryx (rson )); return ans;} int main () {// freopen ("in.txt", "r", std In); while (~ Scanf ("% d", & T) {memset (mx, 0, sizeof (mx); while (T --) {scanf ("% s ", s); if (s [0] = 'I') {scanf ("% d % lf", & h, & tmpa, & ll ); a = (int) (tmpa * 10); // printf ("(% d)-> %. 1lf \ n ", h, a, ll); updatex (1, 1, N);} else {scanf (" % d % lf ", & x1, & x2, & tmpy1, & tmpy2); y1 = (int) (tmpy1 * 10); y2 = (int) (tmpy2 * 10); if (x1> x2) swap (x1, x2); if (y1> y2) swap (y1, y2); // ignored at the beginning .. // Printf ("x1 = % d, x2 = % d, y1 = % d, y2 = % d \ n", x1, x2, y1, y2 ); double ans = queryx (1, 1, N); if (ans = 0) puts ("-1"); else printf ("%. 1lf \ n ", ans) ;}} return 0 ;}


Zookeeper

HDU 1832 Luck and Love (two-dimensional line segment tree)

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.