COJ969 WZJ data structure (minus 31)

Source: Internet
Author: User

WZJ data structure (minus 31)
Difficulty level: D; operating time limit: 3000ms; operating space limit: 262144KB; code length limit: 2000000B
Question Description
A state-owned two main base stations, supply the national resources. Defines a primary base station that can cover a circle with a radius of R (including the boundary) at the center of the main base station.
If a sub-base station can be overwritten by a primary base station, it is active.
There are n events, and there are two types of events:
1. Create a new sub-base station with coordinates (x, y).
2. Give the radius of two main base stations: R1, R2. Inquire about the number of sub-base stations that are inactive.
Input
The first line is four positive integers: x1, y1, x2, y2. Represents the coordinates of the two primary base stations (X1,Y1) and (X2,y2).
The second line is a positive integer n, which indicates that there are N events.
The next n rows, three positive integers per line.
If the first number is 1, then the next two digits are X, Y, which represents a new base station with coordinates (x, y).
If the first number is 2, then the next two numbers are R1,R2, which indicates the number of sub-base stations in the inactive state when two primary base stations have a coverage radius of R1 and R2.
Output
Output answers for each query.
Input example
1 10 5 2
10
1 2 6
1 1 9
1 3 8
1 6 7
1 4 12
2 1 1
2 3 2
2 8 2
2 2 2
2 3 2
Output example
4
3
0
4
3
Other Notes
1<=x1,y1,x2,y2,x,y,r1,r2<=10^9
1<=n<=200000

Mom, I'm going to write a line-of-tree Division!

According to the method of the paper, the operation corresponds to a time interval, marking the interval, then the number of marks of the operation is O (NLOGN), the query corresponds to a point, the point is located in the interval marked, then the number of tags asked is O (Nlogn). At last, you can do it offline for each line segment.

#include <cstdio>#include<cctype>#include<queue>#include<cstring>#include<algorithm>#defineRep (i,s,t) for (int i=s;i<=t;i++)#defineDwn (i,s,t) for (int i=s;i>=t;i--)#defineren for (int i=first[x];i!=-1;i=next[i])using namespaceStd;inlineintRead () {intx=0, f=1;CharC=GetChar ();  for(;! IsDigit (c); C=getchar ())if(c=='-') f=-1;  for(; IsDigit (c); C=getchar ()) x=x*Ten+c-'0'; returnx*F;} typedefLong Longll;Const intmaxn=200010; ll X0,Y0,X1,Y1,TMP[MAXN];intn,n,first1[maxn*3],next1[maxn* the],id1[maxn* the],tot1;intfirst2[maxn*3],next2[maxn* the],id2[maxn* the],tot2;structQuery {intTp,id; ll x, y;} Q[MAXN];structPoint {ll x, y;intID; BOOL operator< (Constpoint& a)Const {        if(x!=a.x)returnX>a.x; if(Y!=A.Y)returnY>a.y; }}A[MAXN];voidPre () {Rep (I,1, N) tmp[i]=-q[i].y; Sort (tmp+1, tmp+n+1); Rep (I,1, N) q[i].y=lower_bound (tmp+1, tmp+n+1,-Q[I].Y)-tmp;}intANS[MAXN],SUMV[MAXN];voidAddintXintV) { for(; x<=n;x+=x&-x) sumv[x]+=v;}intSumintx) {intres=0; for(; x;x-=x&-x) res+=sumv[x];returnRes;}voidQuery1 (intOintLintRintQlintQrintv) {if(ql<=l&&r<=qr) {id1[++tot1]=v;next1[tot1]=first1[o];first1[o]=ToT1; }    Else {        intMid=l+r>>1,lc=o<<1, rc=lc|1; if(ql<=mid) Query1 (LC,L,MID,QL,QR,V); if(Qr>mid) Query1 (rc,mid+1, r,ql,qr,v); }} voidQuery2 (intOintLintRintXintv) {id2[++tot2]=v;next2[tot2]=first2[o];first2[o]=ToT2; if(L==R)return; intMid=l+r>>1,lc=o<<1, rc=lc|1; if(x<=mid) Query2 (LC,L,MID,X,V); ElseQuery2 (rc,mid+1, r,x,v);}intMain () {x0=read (); Y0=read (); X1=read (); y1=read (); N=read (); Rep (I,1, N) {Q[q[i].id=i].tp=read (); ll x=read (), y=read (); if(q[i].tp==1) {q[i].x= (x-x0) * (x-x0) + (y-y0) * (y-y0), q[i].y= (x-x1) * (x-x1) + (y-y1) * (yy1); Query1 (1,1, N,i,n,i); }        Else{q[i].x=x*x,q[i].y=y*y; Query2 (1,1, N,i,i);    }} pre (); Rep (I,1,3*N) {intm=0;  for(intJ=FIRST2[I];J;J=NEXT2[J]) a[++m]=(point) {q[id2[j]].x,q[id2[j]].y,q[id2[j]].id};  for(intJ=FIRST1[I];J;J=NEXT1[J]) a[++m]= (point) {q[id1[j]].x,q[id1[j]].y,0}; Sort (A+1, a+m+1); Rep (J,1, m)if(! a[j].id) Add (A[J].Y,1);ElseAns[a[j].id]+=sum (a[j].y-1); Rep (J,1, m)if(! a[j].id) Add (a[j].y,-1); } Rep (I,1, N)if(q[i].tp==2) printf ("%d\n", Ans[i]); return 0;}
View Code

CDQ Divide the constant is relatively small:

#include <cstdio>#include<cctype>#include<queue>#include<cstring>#include<algorithm>#defineRep (i,s,t) for (int i=s;i<=t;i++)#defineDwn (i,s,t) for (int i=s;i>=t;i--)#defineren for (int i=first[x];i!=-1;i=next[i])using namespaceStd;inlineintRead () {intx=0, f=1;CharC=GetChar ();  for(;! IsDigit (c); C=getchar ())if(c=='-') f=-1;  for(; IsDigit (c); C=getchar ()) x=x*Ten+c-'0'; returnx*F;} typedefLong Longll;Const intmaxn=200010; ll X0,Y0,X1,Y1,TMP[MAXN];structQuery {intTp,id; ll x, y;} Q[MAXN];structPoint {ll x, y;intID; BOOL operator< (Constpoint& a)Const {        if(x!=a.x)returnX>a.x; if(Y!=A.Y)returnY>a.y; }}A[MAXN];intN,ANS[MAXN],SUMV[MAXN];voidAddintXintV) { for(; x<=n;x+=x&-x) sumv[x]+=v;}intSumintx) {intres=0; for(; x;x-=x&-x) res+=sumv[x];returnRes;}voidSolveintLintR) {if(L&GT;=R)return; intMid=l+r>>1, m0=0, m=0; Solve (l,mid); Solve (mid+1, R); Rep (I,l,mid)if(q[i].tp==1) a[++m0]= (point) {q[i].x,q[i].y,0}; if(!M0)return; m=M0; Rep (I,mid+1Rif(q[i].tp==2) a[++m0]=(point) {q[i].x,q[i].y,q[i].id}; if(m0==m)return; m=M0; Sort (A+1, a+m+1); Rep (I,1, m)if(! a[i].id) Add (A[I].Y,1);ElseAns[a[i].id]+=sum (a[i].y-1); Rep (I,1, m)if(! a[i].id) Add (a[i].y,-1);}voidPre () {Rep (I,1, N) tmp[i]=-q[i].y; Sort (tmp+1, tmp+n+1); Rep (I,1, N) q[i].y=lower_bound (tmp+1, tmp+n+1,-Q[I].Y)-tmp;}intMain () {x0=read (); Y0=read (); X1=read (); y1=read (); N=read (); Rep (I,1, N) {Q[q[i].id=i].tp=read (); ll x=read (), y=read (); if(q[i].tp==1) q[i].x= (x-x0) * (x-x0) + (y-y0) * (y-y0), q[i].y= (x-x1) * (x-x1) + (y-y1) * (yy1); Elseq[i].x=x*x,q[i].y=y*y; } pre (); Solve (1, N); Rep (I,1, N)if(q[i].tp==2) printf ("%d\n", Ans[i]); return 0;}
View Code

COJ969 WZJ data structure (minus 31)

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.