最后一个。。。
李超线段树就是用来解决平面上放线段的一些问题
可以去看这个博客
我懒得写了
一个例题:
bzoj3165: [Heoi2013]Segment
李超线段树裸题
代码如下:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define N 100005
#define ls cur<<1
#define rs cur<<1|1
using namespace std;
template<class T>inline void rd(T &x){
x=0; short f=1; char c=getchar();
while(c<'0' || c>'9') f=c=='-'?-1:1,c=getchar();
while(c<='9' && c>='0') x=x*10+c-'0',c=getchar();
x*=f;
}
const int xp=39989,yp=1e9;
const double eps=1e-8;
int q,ans,dat[xp*4+10],n;
double k[N],b[N];
inline void add(int now,int a,int bb,int c,int d){
if(a==c){k[now]=0.0;b[now]=max(bb,d);return;}
k[now]=1.0*(d-bb)/(c-a); b[now]=bb-k[now]*a;
}
inline int dcmp(double x){
if(fabs(x)<=eps) return 0;
return x>0?1:-1;
}
inline double calc(int l,int x){
return k[l]*x+b[l];
}
inline bool judge(int x,int l1,int l2){
return dcmp(calc(l1,x)-calc(l2,x))==0?(l1<l2):calc(l1,x)>calc(l2,x);
}
void update(int cur,int L,int R,int l,int r,int t){
int mid=L+R>>1;
if(l<=L && R<=r){
if(!dat[cur]) {dat[cur]=t;return;}
bool b1=judge(L,t,dat[cur]),b2=judge(R,t,dat[cur]);
if(b1 && b2) dat[cur]=t;
else if(b1!=b2){
if(judge(mid,t,dat[cur])) swap(t,dat[cur]);
if(judge(L,t,dat[cur])) update(ls,L,mid,l,r,t);
else update(rs,mid+1,R,l,r,t);
}
return;
}
if(l<=mid) update(ls,L,mid,l,r,t);
if(mid<r) update(rs,mid+1,R,l,r,t);
}
void query(int cur,int L,int R,int p){
if(!ans||(dat[cur]&&judge(p,dat[cur],ans))) ans=dat[cur];
if(L==R) return;
int mid=L+R>>1;
if(p<=mid) query(ls,L,mid,p);
else query(rs,mid+1,R,p);
}
int main(){
rd(q); int op,x0,y0,x1,y1;
while(q--){
rd(op);
if(!op){
rd(x0); x0=(x0+ans-1)%xp+1;
ans=0; query(1,1,xp,x0);
printf("%d\n",ans);
}
else{
rd(x0),rd(y0),rd(x1),rd(y1);
x0=(x0+ans-1)%xp+1,y0=(y0+ans-1)%yp+1,x1=(x1+ans-1)%xp+1,y1=(y1+ans-1)%yp+1;
++n; add(n,x0,y0,x1,y1);
if(x0>x1) swap(x0,x1);
update(1,1,xp,x0,x1,n);
}
}
return 0;
}