Bzoj 2961 Total Point round CDQ + convex bag

Source: Internet
Author: User

Topic: A given plane, multiple insertion points and circles, each insertion point asks whether the currently inserted point is in all of the previously inserted circles and at least one circle

Maintaining these points and circles directly with the data structure is not very good to write, we consider CDQ partition

For each layer of division, we need to find out whether all the circles in [L,mid] are covered by this point for each point in [Mid+1,r]

The coordinates of the SetPoint are (x0,y0), then this point must be satisfied in all circles for all the centers (x, y), (x-x0) ^2+ (y-y0) ^2<=x^2+y^2, i.e. 2*x*x0+2*y*y0>=x0^2+y0^2

We find that the above equation is a half plane with a slope of-x0/y0, and if all the centers are in this half plane, then this point is within all the circles.

We can do a convex hull for all the centers (up and down convex hull), to ensure that the [Mid+1,r] part of the slope increment, and then for each point corresponding to the half plane, go convex packet to find the card to the point

If this point is within the circle of the card, then it is within [l,mid] all the circles and vice versa.

And then it's normal--if a point's y0 is positive on the lower convex packet query on the upper convex packet instead

Because the slope is incremented, the lower convex hull should maintain a queue, while the upper convex package needs to maintain a stack y0=0

Also note that there is no circle on the left--

#include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include < algorithm> #define M 500500#define EPS 1e-5#define INF 1e11using namespace std;struct point{double x, y; Point () {}point (double _,double __): X (_), Y (__) {}};struct query:point{int type;double K; Query () {}query (int _,double __,double ___): Type (_) {x=__;y=___;if (Fabs (y) <=eps) k=inf;else k=-x/y;} BOOL operator < (const Query &AMP;Q) Const{return x < q.x;}} Mempool[m],*q[m],*nq[m];int n;bool outside_the_circles[m],appeared;bool Compare (query* q1,Query* Q2) {return q1->k < q2->k;} Inline double get_slope (const point &p1,const point &p2) {if (Fabs (p1.x-p2.x) <eps) return p1.y<p2.y? Inf:-inf;return (P1.Y-P2.Y)/(p1.x-p2.x);} Inline double Distance (const point &p1,const point &p2) {return sqrt ((p1.x-p2.x) * (p1.x-p2.x) + (P1.Y-P2.Y) * ( P1.Y-P2.Y));} void Cdq_divide_and_conquer (int x,int y) {static point *queue[m],*stack[m];//queue-under convex hull stack-convex package int i,mid=x+y>>1 ; IF (x==y) return, int l1=x,l2=mid+1;for (i=x;i<=y;i++) {if (q[i]-mempool<=mid) nq[l1++]=q[i];elsenq[l2++]=q[i];} memcpy (q+x,nq+x,sizeof (q[0)) * (y-x+1)); Cdq_divide_and_conquer (x,mid); int top=0,r=0,h=0;for (i=x;i<=mid;i++) {if (q[i]->type==1) continue; Point P=*q[i];while (top>=2 && get_slope (*stack[top-1],*stack[top]) <get_slope (*stack[top],p)) stack[ Top--]=0x0;stack[++top]=q[i];while (r-h>=2 && get_slope (*queue[r-1],*queue[r]) >get_slope (*queue[r], p)) queue[r--]=0x0;queue[++r]=q[i];} for (i=mid+1;i<=y;i++) {if (q[i]->type==0) continue;if (q[i]->y>eps) {while (r-h>=2 && get_slope (*queue[h+1],*queue[h+2]) <q[i]->k) queue[++h]=0x0;if (r-h>=1 && Distance (*queue[h+1],point (0,0)) < Distance (*queue[h+1],*q[i]) outside_the_circles[q[i]-mempool]=1;} Else{while (top>=2 && get_slope (*stack[top-1],*stack[top]) <q[i]->k) stack[top--]=0x0;if (top>=1 && Distance (*queue[h+1],point (0,0)) < Distance (*queue[h+1],*q[i]) outside_the_circles[q[i]-mempool]=1;}} Cdq_divide_and_conquer (mid+1,y); L1=x;l2=mid+1;for (i=x;i<=y;i++) {if (L2 > y | | l1<=mid && *q[l1]<* Q[L2]) nq[i]=q[l1++];elsenq[i]=q[l2++];} memcpy (Q+x,nq+x,sizeof (q[0]) * (y-x+1)); int main () {int i,type;double x,y;cin>>n;for (i=1;i<=n;i++) {scanf ("%d%lf%lf", &type,&x,&y); Q[i] =& (Mempool[i]=query (Type,x,y));} Sort (q+1,q+n+1,compare); Cdq_divide_and_conquer (1,n); for (i=1;i<=n;i++) {if (mempool[i].type==0) appeared=1;elseputs (appeared&&! Outside_the_circles[i]? " Yes ":" No ");} return 0;}


Bzoj 2961 Total Point round CDQ + convex bag

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.