# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
493858 |
2021-12-13T08:23:28 Z |
LittleCube |
Roads (CEOI20_roads) |
C++14 |
|
303 ms |
12152 KB |
#include <bits/extc++.h>
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
int N, vis[200005];
pll p[100005][2];
pii ans[100005];
vector<pii> v;
int curx = -1e8;
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;
signed main()
{
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)
{/*
if (p[p1.F][p1.S].F == p[p2.F][p2.S].F)
{
if (p1.F == p2.F)
return p1.S < p2.S;
return p1.S > p2.S;
}
else*/
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)
{
//cout << "remove " << v[i].F << '\n';
auto iter = sweep.erase(sweep.find(v[i].F));
sweep[iter->F] = v[i];
}
else
{
//cout << "insert " << v[i].F << '\n';
auto iter = sweep.upper_bound(v[i].F);
ans[v[i].F] = sweep[iter->F];
//cout << "...with answer " << ans[v[i].F].F << " " << ans[v[i].F].S << '\n';
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";
}
/*
4
1 1 3 2
1 3 5 3
6 1 5 5
1 4 4 5
*/
Compilation message
roads.cpp: In function 'int main()':
roads.cpp:65: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]
65 | for (int i = 0; i < v.size(); i++)
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
135 ms |
3320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
4 ms |
332 KB |
Output is correct |
4 |
Correct |
20 ms |
1476 KB |
Output is correct |
5 |
Correct |
39 ms |
2612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
19 ms |
1472 KB |
Output is correct |
5 |
Correct |
40 ms |
2616 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
4 ms |
440 KB |
Output is correct |
9 |
Correct |
23 ms |
1532 KB |
Output is correct |
10 |
Correct |
290 ms |
11804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
3 ms |
332 KB |
Output is correct |
4 |
Correct |
26 ms |
1488 KB |
Output is correct |
5 |
Correct |
42 ms |
2632 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
3 ms |
404 KB |
Output is correct |
9 |
Correct |
28 ms |
1516 KB |
Output is correct |
10 |
Correct |
107 ms |
6016 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
3 ms |
332 KB |
Output is correct |
5 |
Correct |
24 ms |
1480 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
22 ms |
1468 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
29 ms |
1552 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
9 ms |
716 KB |
Output is correct |
23 |
Correct |
10 ms |
716 KB |
Output is correct |
24 |
Correct |
21 ms |
1156 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
98 ms |
3312 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
3 ms |
332 KB |
Output is correct |
6 |
Correct |
21 ms |
1460 KB |
Output is correct |
7 |
Correct |
43 ms |
2668 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
308 KB |
Output is correct |
10 |
Correct |
3 ms |
332 KB |
Output is correct |
11 |
Correct |
23 ms |
1464 KB |
Output is correct |
12 |
Correct |
303 ms |
11684 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
20 ms |
1552 KB |
Output is correct |
17 |
Correct |
106 ms |
6028 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
9 ms |
644 KB |
Output is correct |
27 |
Correct |
9 ms |
716 KB |
Output is correct |
28 |
Correct |
25 ms |
1128 KB |
Output is correct |
29 |
Correct |
171 ms |
7340 KB |
Output is correct |
30 |
Correct |
226 ms |
10952 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
196 ms |
8156 KB |
Output is correct |
33 |
Correct |
201 ms |
8100 KB |
Output is correct |
34 |
Correct |
278 ms |
10660 KB |
Output is correct |
35 |
Correct |
295 ms |
11156 KB |
Output is correct |
36 |
Correct |
298 ms |
12152 KB |
Output is correct |