|
线段树+离散化
- #include<cstring>
- #include<iostream>
- #include<cstdio>
- #include<algorithm>
- using namespace std;
- const int maxn=100005;
- bool hash[maxn];
- int cov[maxn<<4];
- double a[maxn*3];
- int cnt;
- struct node
- {
- double li,ri,z;
- }dian[maxn];
- int BinSea(double key,int n)
- {
- int l=0,r=n-1;
- while(l<=r)
- {
- int mid=(l+r)/2;
- if(a[mid]==key) return mid;
- else if(a[mid]<key) l=mid+1;
- else r=mid-1;
- }
- return -1;
- }
- void Pushdown(int p)
- {
- if(cov[p]!=-1){
- cov[p<<1]=cov[p<<1|1]=cov[p];
- cov[p]=-1;
- }
- }
- void Update(int p,int l,int r,int x,int y,int c)
- {
- if(x<=l&&y>=r)
- {
- cov[p]=c;
- return;
- }
- Pushdown(p);
- int mid=(l+r)>>1;
- if(x<=mid) Update(p<<1,l,mid,x,y,c);
- if(y>mid) Update(p<<1|1,mid+1,r,x,y,c);
- }
- void Query(int p,int l,int r)
- {
- if(cov[p]!=-1)
- {
- if(!hash[cov[p]])
- {
- cnt++;
- hash[cov[p]]=true;
- }
- return;
- }
- if(l==r) return;
- int mid=(l+r)>>1;
- Query(p<<1,l,mid);
- Query(p<<1|1,mid+1,r);
- }
- bool cmp(node x,node y)
- {
- return x.z>y.z;
- }
- int main()
- {
- int n,k;
- scanf("%d",&n);
- for(int i=0;i<n;i++)
- {
- double x,y,lon;
- scanf("%lf%lf%lf",&x,&y,&lon);
- dian[i].li=x/(y+lon),dian[i].ri=(x+lon)/y;
- dian[i].z=x+lon+y;
- a[k++]=dian[i].li;
- a[k++]=dian[i].ri;
- }
- sort(dian,dian+n,cmp);
- sort(a,a+k);
- int h=1;
- for(int i=1;i<k;i++)
- if(a[i]!=a[i-1])
- a[h++]=a[i];
- for(int i=h-1;i>0;i--)
- if((a[i]-a[i-1])>0.00000000001)
- a[h++]=a[i-1]+(a[i]-a[i-1])/2;
- sort(a,a+h);
- memset(cov,-1,sizeof(cov));
- for(int i=0;i<n;i++)
- {
- int l=BinSea(dian[i].li,h);
- int r=BinSea(dian[i].ri,h);
- Update(1,0,h-1,l,r,i);
- }
- cnt=0;
- memset(hash,false,sizeof(hash));
- Query(1,0,h-1);
- printf("%d\n",cnt);
- return 0;
- }
复制代码 |
|