답안 #476739

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
476739 2021-09-28T12:20:13 Z Saboon Roads (CEOI20_roads) C++17
0 / 100
6 ms 6732 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> point;
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
const int N = 1e7;
int SweepX;

struct Segment{
	int x1, y1;
	int x2, y2;
	long double shib;
	Segment(int x1_ = 0, int y1_ = 0, int x2_ = 0, int y2_ = 0){
		x1 = x1_, y1 = y1_, x2 = x2_, y2 = y2_;
		if (x1 > x2)
			swap(x1,x2), swap(y1,y2);
		shib = 1.*(y2-y1)/(x2-x1);
	}
	long double getY(int x)const{
		assert(x1 <= x and x <= x2);
		if (x1 == x2)
			return y1;
		return y1 + shib*(x-x1);
	}
	bool operator < (const Segment &other)const{
		return this->getY(SweepX) < other.getY(SweepX);
	}
} seg[maxn];

map<point,point> mp;

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<pair<point,int>> p;
	for (int i = 1; i <= n; i++){
		int x1,y1,x2,y2;
		cin >> x1>>y1>>x2>>y2;
		if (x1 > x2 or (x1 == x2 and y1 > y2))
			swap(x1,x2), swap(y1,y2);
		p.push_back({{x1,y1}, -i});
		p.push_back({{x2,y2}, i});
		seg[i] = Segment(x1,y1,x2,y2);
	}
	sort(p.begin(),p.end());
	set<Segment> S;
	SweepX = -N-1;
	for (int it = 0; it < 2*n; it++){
		if (SweepX != p[it].first.first){
			for (int j = it-1; p[j].first.first == SweepX and j >= 0; j--)
				if (p[j].second > 0)
					S.erase(seg[p[j].second]);
			SweepX = p[it].first.first;
		}
		if (p[it].second > 0)
			continue;
		if (it != 0){
			if (S.empty())
				cout << p[it-1].first.first << " " << p[it-1].first.second << " " << p[it].first.first << " " << p[it].first.second << '\n';
			else{
				Segment me = Segment(p[it].first.first, p[it].first.second, p[it].first.first, p[it].first.second);
				auto Q = S.lower_bound(me);
				if (Q == S.end())
					Q --;
				if ((*Q).x1 != (*Q).x2){
					point bef = make_pair((*Q).x1, (*Q).y1);
					cout << p[it].first.first << " " << p[it].first.second << " " << mp[bef].first << " " << mp[bef].second << '\n';
					mp[bef] = p[it].first;
				}
				else{
					point bef = make_pair((*Q).x2, (*Q).y2);
					cout << p[it].first.first << " " << p[it].first.second << " " << mp[bef].first << " " << mp[bef].second << '\n';
				}
			}
		}
		mp[p[it].first] = p[it].first;
		S.insert(seg[-p[it].second]);
	}
}
# 결과 실행 시간 메모리 Grader output
1 Failed 3 ms 6476 KB Condition failed: "pf == Sline.end() || !Cross(S[*pa], S[*pf])"
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6476 KB Output is correct
2 Correct 3 ms 6604 KB Output is correct
3 Failed 5 ms 6732 KB Condition failed: "iA != P2I.end()"
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6476 KB Output is correct
2 Correct 4 ms 6604 KB Output is correct
3 Failed 5 ms 6732 KB Condition failed: "iA != P2I.end()"
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6580 KB Output is correct
2 Correct 4 ms 6584 KB Output is correct
3 Failed 6 ms 6716 KB Condition failed: "iA != P2I.end()"
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Failed 5 ms 6476 KB Condition failed: "pf == Sline.end() || !Cross(S[*pa], S[*pf])"
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Failed 5 ms 6476 KB Condition failed: "pf == Sline.end() || !Cross(S[*pa], S[*pf])"
2 Halted 0 ms 0 KB -