BZOJ3165: [Heoi2013]Segment

    xiaoxiao2021-03-26  11

    所以题意已经告诉了这题是线段树?


    线段树每个节点维护覆盖区间的最上的线段,每次插入线段,对于一个被其完整覆盖的区间,如果这个线段与之前覆盖它的无交点取较上者,否则随便取一个,另一个传到两个孩子,询问就每层的线段比较一下

    复杂度:O(能过) 别打我我不想证也不太会证


    #include<set> #include<map> #include<deque> #include<queue> #include<stack> #include<cmath> #include<ctime> #include<bitset> #include<string> #include<vector> #include<cstdio> #include<cstdlib> #include<cstring> #include<climits> #include<complex> #include<iostream> #include<algorithm> #define ll long long #define inf 1e9 using namespace std; void up(int &x,int y){if(y>x)x=y;} void down(int &x,int y){if(y<x)x=y;} const int maxn = 110000; const int m1 = 39989; const int m2 = 1e9; struct seg { int x0,y0,x1,y1; seg(){} seg(int _x0,int _y0,int _x1,int _y1){x0=_x0;x1=_x1;y0=_y0;y1=_y1;} }se[maxn]; int tot; int n,mx[maxn],mid[maxn]; int tr[m1<<3]; void ins(int x,int l,int r,int lx,int rx,int id) { if(lx<=l&&r<=rx) { if(!tr[x]) tr[x]=id; else { seg tx=se[tr[x]],ti=se[id]; double k0=(double)(ti.y1-ti.y0)/(double)(ti.x1-ti.x0); double k1=(double)(tx.y1-tx.y0)/(double)(tx.x1-tx.x0); double y1=(double)ti.y0+k0*(l-ti.x0),y2=(double)ti.y0+k0*(r-ti.x0); double y3=(double)tx.y0+k1*(l-tx.x0),y4=(double)tx.y0+k1*(r-tx.x0); if(y1<=y3&&y2<=y4) return ; else if(y1>=y3&&y2>=y4) tr[x]=id; else ins(x<<1,l,(l+r)>>1,lx,rx,id),ins((x<<1)|1,((l+r)>>1)+1,r,lx,rx,id); } return ; } int mid=(l+r)>>1, lc=x<<1,rc=lc|1; if(rx<=mid) ins(lc,l,mid,lx,rx,id); else if(lx>mid) ins(rc,mid+1,r,lx,rx,id); else ins(lc,l,mid,lx,mid,id),ins(rc,mid+1,r,mid+1,rx,id); } double hmax; int hid; void query(int x,int l,int r,int loc) { if(tr[x]) { seg tx=se[tr[x]]; double k=(double)(tx.y1-tx.y0)/(double)(tx.x1-tx.x0); if(hmax<tx.y0+k*(double)(loc-tx.x0)) hmax=tx.y0+k*(double)(loc-tx.x0),hid=tr[x]; } if(l==r) return ; int mid=(l+r)>>1,lc=x<<1,rc=lc|1; if(loc<=mid) query(lc,l,mid,loc); else query(rc,mid+1,r,loc); } int main() { int lastans=0; scanf("%d",&n); while(n--) { int x; scanf("%d",&x); if(x) { int x0,y0,x1,y1; scanf("%d%d%d%d",&x0,&y0,&x1,&y1); x0=(x0+lastans-1)%m1+1; x1=(x1+lastans-1)%m1+1; y0=(y0+lastans-1)%m2+1; y1=(y1+lastans-1)%m2+1; if(x0>x1) swap(x0,x1),swap(y0,y1); tot++; se[tot]=seg(x0,y0,x1,y1); if(x0==x1) { up(y0,y1); if(mx[x0]<y0) mx[x0]=y0,mid[x0]=tot; } else ins(1,1,m1,x0,x1,tot); } else { int k; scanf("%d",&k); k=(k+lastans-1)%m1+1; hmax=mx[k]; hid=mid[k]; query(1,1,m1,k); printf("%d\n",hid); lastans=hid; } } return 0; }
    转载请注明原文地址: https://ju.6miu.com/read-650060.html

    最新回复(0)