HDU 4819 Mosaic two-dimensional line segment tree

Source: Internet
Author: User

HDU 4819 Mosaic two-dimensional line segment tree

Connection: http://acm.hdu.edu.cn/showproblem.php? Pid = 1, 4819

Question: a matrix of less than 800x800 is given. The value of each update point is the average value of the maximum and minimum values in the matrix with the length centered on this point as Li, and output this value.

Idea: Line Segment tree template question. A two-dimensional line segment tree is a decision tree.



The significance of this question is that it has brought me a two-dimensional line segment tree template that runs for 2359 ms, and the line segment tree of the structure will not be stuck. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + PGJyPgo8L3A + cjxwprt6wuuju.pdf vcD4KPHA + PHByZSBjbGFzcz0 = "brush: java;" >#include # Include # Include # Include # Include # Include # Include # Include # Include # Include # Include # Include # Define PI acos (-1.0) # define maxn 1000 # define INF 0x7fffffff # define eps 1e-16 # define MOD 1000000009 typedef long LL; typedef unsigned long ULL; using namespace std; int x_pos [maxn], y_pos [maxn]; int n; // maximum value range of y: struct y_line {int left, right; int Max, Min; // int sum; int mid () {return (left + right)> 1 ;}}; struct x_line {int left, right; y_line yy [maxn * 4]; int mid () {return (left + right)> 1;} void build_ytree (int I, int l, int r) {yy [I]. max =-INF; yy [I]. min = INF; yy [I]. left = l; yy [I]. right = r; if (l = r) {y_pos [l] = I; return;} build_ytree (I <1, l, yy [I]. mid (); build_ytree (I <1 | 1, yy [I]. mid () + 1, r);} int query_Min (int I, int y1, int y2) {if (yy [I]. left = y1 & yy [I]. right = y2) return yy [I]. min; if (yy [I]. mid ()> = y2) return query_Min (I <1, y1, y2); if (yy [I]. mid () = Y2) return query_Max (I <1, y1, y2); if (yy [I]. mid () 0; I >>= 1) for (int j = y_p; j> 0; j >>= 1) if (j = y_p & I = x_p) {xx [I]. yy [j]. max = xx [I]. yy [j]. min = num;} else if (j = y_p) {xx [I]. yy [j]. max = max (xx [I <1]. yy [j]. max, xx [I <1 | 1]. yy [j]. max); xx [I]. yy [j]. min = min (xx [I <1]. yy [j]. min, xx [I <1 | 1]. yy [j]. min);} else {xx [I]. yy [j]. max = max (xx [I]. yy [j <1]. max, xx [I]. yy [j <1 | 1]. max); xx [I]. yy [j]. min = min (xx [I]. yy [j <1]. min, xx [I]. yy [j <1 | 1]. min) ;}} int query_Min (int I, int x1, int y1, int x2, int y2) {if (xx [I]. left = x1 & xx [I]. right = x2) return xx [I]. query_Min (1, y1, y2); if (xx [I]. mid ()> = x2) return query_Min (I <1, x1, y1, x2, y2); if (xx [I]. mid () = X2) return query_Max (I <1, x1, y1, x2, y2); if (xx [I]. mid () > 1; change (c_x, c_y, t_need); printf ("% d \ n", t_need) ;}} 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.