Submission #667621

#TimeUsernameProblemLanguageResultExecution timeMemory
667621dozerRoads (CEOI20_roads)C++14
30 / 100
92 ms15012 KiB
#include <bits/stdc++.h>
using namespace std;
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define pb push_back
#define endl "\n"
#define sp " "
#define pii pair<int, int>
#define st first
#define nd second
#define N 100005
#define L(node) node * 2
#define R(node) node * 2 + 1
#define int long long

const int INF = 1e9 + 7;
const int modulo = 1e9 + 7;
int adj[N], x[N], y[N], done[N];

int32_t main()
{
	//fileio();
	fastio();

	int n;
	cin>>n;
	vector<int> vec;
	for (int i = 1; i <= n; i++)
	{
		int x1, x2, y1, y2;
		cin>>x1>>y1>>x2>>y2;
		int u = 2 * i - 1, v = 2 * i;
		x[u] = x1, y[u] = y1;
		x[v] = x2, y[v] = y2;

		adj[u] = v;
		adj[v] = u;

		vec.pb(u);
		vec.pb(v);
	}

	sort(vec.begin(), vec.end(), [&](int a, int b){
		return make_pair(y[a], x[a]) < make_pair(y[b], x[b]); 
	});
	//for (auto i : vec) cout<<i<<sp;
	//cout<<endl;
	vector<array<int, 4>> ans;
	set<pii> s;
	done[adj[vec.front()]] = 1;
	for (auto i : vec)
	{
		if (done[i] == 0 && !s.empty())
		{
			//cout<<i<<endl;
			auto it = s.lower_bound({x[i], -modulo});
			if (it == s.end()) it--;
			pii tmp = *it;
			ans.pb({x[i], y[i], tmp.st, -tmp.nd});
			done[i] = 1;
			done[adj[i]] = 1;
		}
		s.insert({x[i], -y[i]});
	}

	for (auto i : ans)
	{
		for (int j = 0; j < 4; j++) cout<<i[j]<<sp;
		cout<<endl;
	}

	cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...