/*
author : SilentVisitor;
created on 12.01.22 12.52 A.M.
*/
#include<bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#include "algo/debug.h"
#else
#define debug(...) 69420
#endif
#define deb(...) union
#define ll long long
#define i64 ll64_t
#define F first
#define S second
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sz(s) s.size()
vector<char> data = {'a', 'e', 'i', 'o', 'u'};
int N, vis[200005];
pll p[100005][2];
pii ans[100005];
vector<pii> v;
struct sort_by_y
{
double intersect(int a, int x) const
{
if (p[a][0].F == p[a][1].F)
return (p[a][0].S + p[a][1].S) / 2;
return p[a][0].S + double(p[a][1].S - p[a][0].S) * double(x - p[a][0].F) / double(p[a][1].F - p[a][0].F);
}
bool operator()(int a, int b) const
{
int curx = max(p[a][0].F, p[b][0].F);
if (p[a][0].F == p[a][1].F)
curx = p[a][0].F;
if (p[b][0].F == p[b][1].F)
curx = p[b][0].F;
return intersect(a, curx) < intersect(b, curx);
}
};
map<int, pii, sort_by_y> sweep;
void solve(){
cin >> N;
for (int i = 1; i <= N; i++)
cin >> p[i][0].F >> p[i][0].S >> p[i][1].F >> p[i][1].S;
for (int i = 1; i <= N; i++)
if (p[i][0] > p[i][1])
swap(p[i][0], p[i][1]);
for (int i = 1; i <= N; i++)
{
v.emplace_back(pii{i, 0});
v.emplace_back(pii{i, 1});
}
p[0][0] = pii{-1e8, 1e8}, p[0][1] = pii{1e8, 1e8};
sort(v.begin(), v.end(), [&](pii p1, pii p2)
{
return p[p1.F][p1.S]/*.F*/ < p[p2.F][p2.S]/*.F*/;
});
sweep[0] = {0, 0};
for (int i = 0; i < v.size(); i++)
{
if (v[i].S == 1)
{
auto iter = sweep.erase(sweep.find(v[i].F));
sweep[iter->F] = v[i];
}
else
{
auto iter = sweep.upper_bound(v[i].F);
ans[v[i].F] = sweep[iter->F];
sweep[v[i].F] = v[i];
iter = sweep.upper_bound(v[i].F);
sweep[iter->F] = v[i];
}
}
for (int i = 1; i <= N; i++)
if(ans[i] != pii{0, 0})
cout << p[i][0].F << " " << p[i][0].S << " " << p[ans[i].F][ans[i].S].F << " " << p[ans[i].F][ans[i].S].S << "\n";
}
main(void){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
Compilation message
roads.cpp: In function 'void solve()':
roads.cpp:68:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for (int i = 0; i < v.size(); i++)
| ~~^~~~~~~~~~
roads.cpp: At global scope:
roads.cpp:91:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
91 | main(void){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
66 ms |
4352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
11 ms |
1208 KB |
Output is correct |
5 |
Correct |
20 ms |
2088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
11 ms |
1204 KB |
Output is correct |
5 |
Correct |
23 ms |
2060 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
472 KB |
Output is correct |
9 |
Correct |
12 ms |
1500 KB |
Output is correct |
10 |
Correct |
197 ms |
11820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
10 ms |
1240 KB |
Output is correct |
5 |
Correct |
22 ms |
2144 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
10 ms |
1624 KB |
Output is correct |
10 |
Correct |
53 ms |
6040 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
11 ms |
1500 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
472 KB |
Output is correct |
9 |
Correct |
12 ms |
1624 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
11 ms |
1496 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
6 ms |
744 KB |
Output is correct |
23 |
Correct |
7 ms |
724 KB |
Output is correct |
24 |
Correct |
12 ms |
1132 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
67 ms |
4296 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
11 ms |
1624 KB |
Output is correct |
7 |
Correct |
24 ms |
2716 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
472 KB |
Output is correct |
11 |
Correct |
12 ms |
1516 KB |
Output is correct |
12 |
Correct |
190 ms |
11900 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
11 ms |
1616 KB |
Output is correct |
17 |
Correct |
64 ms |
6032 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
3 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
9 ms |
728 KB |
Output is correct |
27 |
Correct |
6 ms |
696 KB |
Output is correct |
28 |
Correct |
13 ms |
1164 KB |
Output is correct |
29 |
Correct |
140 ms |
7324 KB |
Output is correct |
30 |
Correct |
176 ms |
10920 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
131 ms |
8244 KB |
Output is correct |
33 |
Correct |
142 ms |
8212 KB |
Output is correct |
34 |
Correct |
178 ms |
10804 KB |
Output is correct |
35 |
Correct |
217 ms |
11200 KB |
Output is correct |
36 |
Correct |
252 ms |
12128 KB |
Output is correct |