求助:#8 WA
查看原帖
求助:#8 WA
300078
pengyule楼主2022/9/27 18:48
#include <bits/stdc++.h>
using namespace std;
inline int read(){
	register char ch=getchar();register int x=0,f=1;
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x*f;
}
const int N=2e5+5;
int n,now,U,ours,inx[N],outx[N],iny[N],outy[N],ans2[N],In[N];
struct Seg {
	int a,b,c,d,id;
}seg[N];
struct oper {
	int x,id,type;
}op[N];
double whenx(int x,int x_1,int y_1,int x_2,int y_2){
	return 1.0*(y_1-y_2)*(x-x_2)/(x_1-x_2)+y_2;
}
bool operator<(Seg a,Seg b){
	return whenx(now,a.a,a.b,a.c,a.d)<whenx(now,b.a,b.b,b.c,b.d);
}
bool operator==(Seg a,Seg b){
	return a.id==b.id;
}
set<Seg>S;
vector<int>G1[N],g1[N],G2[N],g2[N];
queue<int>Q;
inline void adde1(int u,int v){//cerr<<u<<'-'<<v<<',';
	G1[u].emplace_back(v);
	g1[v].emplace_back(u);
	inx[v]++,outx[u]++;
}
inline void adde2(int u,int v){
	G2[u].emplace_back(v);
	g2[v].emplace_back(u);
	iny[v]++,outy[u]++;
}
void Over(int id){
	printf("%d\n",id);
	for(int i=1;i<=n;i++)printf("%d 1\n",ans2[i]);
	exit(0); 
}
signed main(){
	//freopen("10.in","r",stdin);freopen("move.out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++)seg[i].a=read(),seg[i].b=read(),seg[i].c=read(),seg[i].d=read(),seg[i].id=i;
	for(int i=1;i<=n;i++)op[++U]=oper{min(seg[i].a,seg[i].c),i,1},op[++U]=oper{max(seg[i].a,seg[i].c),i,-1};
	sort(op+1,op+U+1,[](oper a,oper b){return a.x==b.x?a.type<b.type:a.x<b.x;});
	for(int i=1;i<=n;i++)G1[i].clear(),g1[i].clear();
	now=op[1].x;
	for(int o=1;o<=U;o++,now=op[o].x){
		if(op[o].type==-1){
			S.erase(S.lower_bound(seg[op[o].id]));
		}
		else {
			set<Seg>::iterator it=S.lower_bound(seg[op[o].id]);
			if(it!=S.end())adde1(it->id,op[o].id);
			if(it!=S.begin())adde1(op[o].id,prev(it)->id);
			S.insert(seg[op[o].id]);
		}
	}
	for(int i=1;i<=n;i++)In[i]=inx[i];
	for(int i=1;i<=n;i++)if(!In[i])Q.push(i);
	while(!Q.empty()){
		int x=Q.front();Q.pop();
		ans2[++ours]=x;
		for(int y:G1[x])if(!--In[y])Q.push(y);
	}
	for(int i=1;i<=n;i++)swap(seg[i].a,seg[i].b),swap(seg[i].c,seg[i].d);
	U=0;for(int i=1;i<=n;i++)op[++U]=oper{min(seg[i].a,seg[i].c),i,1},op[++U]=oper{max(seg[i].a,seg[i].c),i,-1};
	sort(op+1,op+U+1,[](oper a,oper b){return a.x==b.x?a.type<b.type:a.x<b.x;});
	for(int i=1;i<=n;i++)G2[i].clear(),g2[i].clear();
	now=op[1].x;
	for(int o=1;o<=U;o++,now=op[o].x){
		if(op[o].type==-1){
			S.erase(S.lower_bound(seg[op[o].id]));
		}
		else {
			set<Seg>::iterator it=S.lower_bound(seg[op[o].id]);
			if(it!=S.end())adde2(it->id,op[o].id);
			if(it!=S.begin())adde2(op[o].id,prev(it)->id);
			S.insert(seg[op[o].id]);
		}
	}
	for(int i=1,x,p;i<=n;i++){
		x=read(),p=read();
		if(p==0){
			if(outy[x])Over(i);
			for(int y:g2[x])outy[y]--;
			for(int y:G1[x])inx[y]--;
			for(int y:g1[x])outx[y]--;
		}if(p==1){
			if(inx[x])Over(i);
			for(int y:G1[x])inx[y]--;
			for(int y:G2[x])iny[y]--;
			for(int y:g2[x])outy[y]--;
		}if(p==2){
			if(iny[x])Over(i);
			for(int y:G2[x])iny[y]--;
			for(int y:G1[x])inx[y]--;
			for(int y:g1[x])outx[y]--;
		}if(p==3){
			if(outx[x])Over(i);
			for(int y:g1[x])outx[y]--;
			for(int y:G2[x])iny[y]--;
			for(int y:g2[x])outy[y]--;
		}
	}//Over(4);
}
2022/9/27 18:48
加载中...