可进行点和线段的离散化
template<class T>
struct line
{
T a,b;
};
template<class T>
struct helper
{
T v;//原值
int index;//原值的位置
static int cmp(const void*a,const void*b)
{
T r=((helper<T>*)a)->v-((helper<T>*)b)->v;
if(r==0)
return ((helper<T>*)a)->index-((helper<T>*)b)->index;
return r;
}
};
template<class T>
struct lisan
{
helper<T>* h;//h[i]表示离散化后的有序数组的第i项
int* anti;//anti[i]表示离散化后的i值在h中的位置
int* get(T* v,int n)//将v数组离散化成int数组并返回,将映射关系储存在h和anti中
{
h=new helper<T>[n];
anti=new int[n];
fill(anti,anti+n,-1);
for(int i=0;i<n;i++)
h[i].v=v[i],h[i].index=i;
qsort(h,n,sizeof(helper<T>),helper<T>::cmp);
int* res=new int[n];
for(int i=0,j=0;i<n;i++){
if(i!=0&&h[i].v!=h[i-1].v)j++;
res[h[i].index]=j;
if(anti[j]==-1)anti[j]=i;
}