Bzoj 3165 Segment

Source: Internet
Author: User

The previous question.

#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#defineMAXN 40000using namespacestd;Long Longn,m,type,a,b,c,d,root,tot=0,ls[maxn<<2],rs[maxn<<2],cnt=0;BOOLflag[maxn<<2];Long Longans,lastans=0;Doublemx=0;structseg{Long LongX1,y1,x2,y2,id; SEG (Long LongX1,Long LongY1,Long LongX2,Long LongY2,Long LongID): X1 (x1), y1 (y1), X2 (x2), y2 (y2), id (ID) {} seg () {}}S[MAXN<<2];voidBuildLong Long&now,Long LongLeftLong LongRight ) { Now=++tot; if(Left==right)return; Long LongMid= (left+right) >>1;      Build (Ls[now],left,mid); Build (Rs[now],mid+1, right);}DoubleF (Seg X,Long LongPOS) {    DoubleK= (Double) (X.y1-x.y2)/(X.X1-X.X2), b= (Double) (x.x1*x.y2-x.x2*x.y1)/(x.x1-x.x2); returnk*pos+b; }voidAskLong LongNowLong LongLeftLong LongRightLong LongPOS) {    if((Mx<f (S[now],pos)) && (Flag[now])) {mx=f (s[now],pos); ans=S[now].id;} if(Left==right)return; Long LongMid= (left+right) >>1; if(pos<=mid) Ask (Ls[now],left,mid,pos); ElseAsk (rs[now],mid+1, Right,pos);}voidPushdown (Long LongNowLong LongLeftLong Longright,seg x) {    Long LongMid= (left+right) >>1; if(!flag[now]) {flag[now]=true; s[now]=x;return;} DoubleR1=f (X,mid), r2=f (s[now],mid); if(Left==right) {if(R1&GT;R2) Swap (X,s[now]);return;} DoubleF1=f (X,left), F2=f (S[now],left), F3=f (x,right), f4=f (s[now],right); if((F1&LT;F2) && (F3&LT;F4))return; if((F1&GT;F2) && (F3&GT;F4)) {swap (X,s[now]);return;} if(r1>r2) swap (X,s[now]); if((F1&GT;F2) ^ (r1>R2))    Pushdown (LS[NOW],LEFT,MID,X); ElsePushdown (rs[now],mid+1, right,x);}voidModifyLong LongNowLong LongLeftLong LongRightLong LongLLong Longr,seg x) {    if((left==l) && (right==r) {pushdown (now,left,right,x); return; }    Long LongMid= (left+right) >>1; if(r<=mid) Modify (LS[NOW],LEFT,MID,L,R,X); Else if(l>=mid+1) Modify (rs[now],mid+1, right,l,r,x); Else{Modify (ls[now],left,mid,l,mid,x); Modify (Rs[now],mid+1, right,mid+1, r,x); }}intMain () {scanf ("%lld", &m); n=39989; Build (Root,1, N);  for(Long LongI=1; i<=m;i++) {scanf ("%lld",&type); if(type==0) {scanf ("%lld", &a); A= (a+lastans-1)%39989+1; MX=0; ans=0; Ask (Root,1, N,a); Lastans=ans;printf ("%lld\n", Lastans); }        Else{cnt++; scanf ("%lld%lld%lld%lld",&a,&b,&c,&d); A= (a+lastans-1)%39989+1; B= (b+lastans-1)%1000000000+1; C= (c+lastans-1)%39989+1;d = (d+lastans-1)%1000000000+1; if(a>c) {swap (a,c); swap (b,d);} Modify (Root,1, N,a,c,seg (a,b,c,d,cnt)); }    }    return 0;}

Bzoj 3165 Segment

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.