#include<iostream>
#include<algorithm>
#include<cstdio>
#include<set>
#pragma GCC optimize("Ofast")
using namespace std;
const int N=1e5+5;
int XX,n,num;
struct mount
{
double k,b;
int x1,y1,x2,y2;
double fc(){return k*XX+b;}
}m[N];
struct note
{
int x,y,id; bool flag;
bool operator<(note b)const
{
return x<b.x;
}
}tot[N<<1];
struct cmp
{
bool operator()(mount a,mount b)
{
return a.fc()<b.fc();
}
};set<mount,cmp> s;
int main()
{
ios::sync_with_stdio(0),cin.tie(0);
cin>>n; int ans=1;
for(int i=1;i<=n;++i)
{
int x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2;
double k=double(y2-y1)/(x2-x1),b=y1-k*x1;
m[i]={k,b,x1,y1,x2,y2}; tot[++num]={x1,y1,i,0}; tot[++num]={x2,y2,i,1};
}
sort(tot+1,tot+1+num); auto now=m[1];
for(int i=1;i<=num;++i)
{
XX=tot[i].x;
if(now.x2==tot[i].x)
{
while(tot[i].x==now.x2)
{
if(tot[i].y!=now.y2)
{
//if(!tot[i].flag)s.insert(m[tot[i].id]);
//else s.erase(m[tot[i].id]);
(!tot[i].flag)?(s.insert(m[tot[i].id])):(s.erase(m[tot[i].id]));
}
++i;
}
auto nxt=s.lower_bound(now);
if(nxt==s.begin())break;
--nxt; ++ans; s.erase(now); now=*nxt; --i;
}
else
{
if(!tot[i].flag)s.insert(m[tot[i].id]);
else s.erase(m[tot[i].id]);
}
}
cout<<ans<<'\n';
return 0;
}
这个代码中的这个部分用不了
while(tot[i].x==now.x2)
{
if(tot[i].y!=now.y2)
{
//if(!tot[i].flag)s.insert(m[tot[i].id]);
//else s.erase(m[tot[i].id]);
(!tot[i].flag)?(s.insert(m[tot[i].id])):(s.erase(m[tot[i].id]));
}
++i;
}
应该如何解决