Segment tree "Scan line" Petrozavodsk Winter Training Camp 2018 Day 5:grand Prix of Korea, Sunday, February 4, 2018 problem A. Donut

Source: Internet
Author: User

Test instructions: N points on the plane, each point with one or a positive or negative weight, let you put an inner edge in the plane length of 2l, the outside length of 2r square box, ask you the maximum can circle out of the weight and how much?

Easy to roll out, the center of the box that can be framed to each point is also a box with the same size centered on that point.

Then, the box of each point is split into 4 lines. Sweep the past from the bottom, the bottom line, the [r,r] interval plus the weight of the point, and then the [l,l] minus the above, and then to [l,l] plus, and then to the [R,r] minus. Each time you sweep a row, you try to update the answer with the global maximum of the segment tree.

Two pit points: first, because the segment tree is stored in a discrete point, so there may be some dead ends, so give the discretization of every two points between the insertion of a point, so there is no dead ends.

Second, the corresponding line of the out side to move up one unit, and the left and right end of the inward reduction of a unit, so as to facilitate processing.

(UPDATE: Although AC this problem, but was hack, suspect is "out of the side of the line to move up a unit, and the left and right end point inward reduction of a unit" here is a bug)

#include <cstdio> #include <algorithm>using namespace std;typedef long long ll;struct data{int P;ll v;} T[1200005];int A[1200005];bool CMP (const data &AMP;A,CONST data &b) {return A.V&LT;B.V;} struct Line{int y;int l,r;int w;bool in;} Lines[400005];bool cm2 (const line &a,const line &b) {return a.y!=b.y? A.y<b.y:a.in>b.in;} int N,l,r,e,zy;int y[100005],z[100005],ans;int maxv[4800005],delta[4800005];void pushdown (int rt) {if (Delta[rt]) { DELTA[RT&LT;&LT;1]+=DELTA[RT];d elta[rt<<1|1]+=delta[rt];maxv[rt<<1]+=delta[rt];maxv[rt<<1|1] +=DELTA[RT];d elta[rt]=0;}} void update (int ql,int qr,int v,int rt,int l,int R) {if (ql<=l && r<=qr) {Maxv[rt]+=v;delta[rt]+=v;return;} int m= (l+r>>1);p Ushdown (RT), if (ql<=m) {update (QL,QR,V,RT&LT;&LT;1,L,M);} if (M&LT;QR) {update (QL,QR,V,RT&LT;&LT;1|1,M+1,R);} Maxv[rt]=max (maxv[rt<<1],maxv[rt<<1|1]);} int main () {//freopen ("a.in", "R", stdin), int x;scanf ("%d%d%d", &n,&l,&r); for (int i=1;i<=n;++i) {scanf ("%d%d%d", &x,&y[i],&z[i]), t[++e].v= (LL) (X-r) *2ll;t[e].p=e;t[++e].v= (LL) (X-R) *2ll-1ll;t[e] . p=e;t[++e].v= (ll) (X-r) *2ll+1ll;t[e].p=e;t[++e].v= (LL) (x-l+1) *2ll;t[e].p=e;t[++e].v= (LL) (x-l+1) *2LL-1LL;T[E].P =e;t[++e].v= (LL) (x-l+1) *2ll+1ll;t[e].p=e;t[++e].v= (LL) (X+L-1) *2ll;t[e].p=e;t[++e].v= (LL) (X+L-1) *2LL-1LL;T[E].P =e;t[++e].v= (LL) (X+L-1) *2ll+1ll;t[e].p=e;t[++e].v= (LL) (X+r) *2;t[e].p=e;t[++e].v= (LL) (X+r) *2-1;t[e].p=e;t[++e]. v= (LL) (X+r) *2+1;t[e].p=e;} Sort (t+1,t+e+1,cmp); a[t[1].p]=++zy;for (int i=2;i<=e;++i) {if (T[I].V!=T[I-1].V) {++zy;} A[t[i].p]=zy;} for (int i=1;i<=n;++i) {lines[i*4-3].y=y[i]-r;lines[i*4-2].y=y[i]-l+1;lines[i*4-1].y=y[i]+l;lines[i*4-0].y=y[i ]+R+1;LINES[I*4-3].L=A[I*12-11];LINES[I*4-2].L=A[I*12-8];LINES[I*4-1].L=A[I*12-8];LINES[I*4-0].L=A[I*12-11]; lines[i*4-3].r=a[i*12-2];lines[i*4-2].r=a[i*12-5];lines[i*4-1].r=a[i*12-5];lines[i*4-0].r=a[i*12-2];lines[i* 4-3].w=z[i];lines[i*4-2].w=z[i];lines[i*4-1].w=z[i];lines[i*4-0].w=z[i];lines[i*4-3].in=1;lines[i*4-2].in=0;lines[i*4-1].in=1;lines[i*4-0].in=0;} Sort (lines+1,lines+ (n<<2|1), cm2), for (int i=1;i<= (N&LT;&LT;2); ++i) {if (lines[i].in) {update (LINES[I].L, Lines[i].r,lines[i].w,1,1,zy);} Else{update (Lines[i].l,lines[i].r,-lines[i].w,1,1,zy);} if (lines[i].y!=lines[i+1].y) {Ans=max (ans,maxv[1]);}} printf ("%d\n", ans); return 0;}

Segment tree, scan line Petrozavodsk Winter Training Camp 2018 Day 5:grand Prix of Korea, Sunday, February 4, 2018 problem A. donut< /p>

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.