Poi 2001 goldmine line segment tree Scan Line

Source: Internet
Author: User

Question Link

Http://www.acm.cs.ecnu.edu.cn/problem.php? Problemid = 1350

Http://main.edu.pl/en/archive/oi/8/kop

Calculate N points (n <= 15000) in the plane, and use a matrix with a length and width of s w to set the maximum number of points. The points on the edge are also calculated.

In fact, it is similar to the previous rectangular nested area (poj's Atlantic). Using a scanning line like this, the vertex is treated as an edge (Y to Y value + W) and inserted into the line segment tree, in this way, the y direction is maintained, and the X direction is maintained using similar queues,

When the distance is greater than S, the Front (that is, the side removed from the line segment tree) is displayed, and the current side is added.

Maintain a value. It can be seen when the number of sides accumulates the most after scanning.

At first, I thought it was necessary to maintain the coverage value. Later I found it was useless. I just needed to maintain the accumulated layers directly.

At the beginning, I did not write the EOF, And re several times. I don't know why. After the change, I Will 1A.

# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # define lson RT <1, l, mid # define rson RT <1 | 1, Mid + 1, rusing namespace STD; const int n = 100020; // int cover [n <2]; int flag [n <2]; int d [n <2]; int S, W, N, maxn; struct node {int X, Y; bool operator <(const node & RHs) const {If (x = RHS. x) return Y <RHS. y; return x <RHS. X ;}} point [15010]; bool input () {maxn = 0; If (scanf ("% d", & S, & W) = EOF) return false; scanf ("% d", & N); For (INT I = 1; I <= N; I ++) {scanf ("% d ", & point [I]. x, & point [I]. y); point [I]. X ++ = 30000; point [I]. Y ++ = 30000; maxn = max (maxn, point [I]. y);} maxn + = W + 10; return true;} void build (int rt, int L, int R) {// cover [RT] = 0; flag [RT] = 0; d [RT] = 0; If (L> = r) return; int mid = (L + r)> 1; build (lson ); build (rson);} void Pushdown (int rt, int L, int R) {If (flag [RT] = 0) return; int mid = (L + r)> 1; // cover [RT <1] + = Flag [RT] * (mid-L + 1 ); // cover [RT <1 | 1] + = Flag [RT] * (R-mid); D [RT <1] + = Flag [RT]; d [RT <1 | 1] + = Flag [RT]; flag [RT <1] + = Flag [RT]; flag [RT <1 | 1] + = Flag [RT]; flag [RT] = 0;} void up (int rt) {// cover [RT] = cover [RT <1] + cover [RT <1 | 1]; d [RT] = max (d [RT <1], d [RT <1 | 1]);} void remove (int l, int R, int RT, int L, int R) {If (L <= L & R <= r) {// cover [RT]-= (R-l + 1 ); d [RT] --; flag [RT] + =-1; return;} Pushdown (RT, L, R); int mid = (L + r)> 1; if (L <= mid) Remove (L, R, lson); If (r> mid) Remove (L, R, rson); up (RT );} void inserts (int l, int R, int RT, int L, int R) {If (L <= L & R <= r) {// cover [RT] + = (R-l + 1); D [RT] ++; flag [RT] + = 1; return;} Pushdown (RT, l, R); int mid = (L + r)> 1; if (L <= mid) inserts (L, R, lson); If (r> mid) inserts (L, R, rson); up (RT) ;}int main () {While (input () {sort (point + 1, point + 1 + n ); build (1, 0, maxn); int pre = 1; int ans = 0; For (INT I = 1; I <= N; I ++) {// cout <I <Endl; while (point [pre]. X + S <point [I]. x) {remove (point [pre]. y, point [pre]. Y + W, 1, 0, maxn); Pre ++;} inserts (point [I]. y, point [I]. Y + W, 1, 0, maxn); ans = max (ANS, d [1]);} printf ("% d \ n", ANS );}}

Poi 2001 goldmine line segment tree Scan Line

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.