# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
466433 |
2021-08-19T08:59:30 Z |
ivan_tudor |
Roads (CEOI20_roads) |
C++14 |
|
66 ms |
6448 KB |
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+ 5;
struct points{
int x, y;
int type;
int id;
bool operator <(points oth) const{
if(y == oth.y)
return id < oth.id;
return y < oth.y;
}
};
set<points> act;
pair<int, int> upper[N], lower[N];
bool cmp(points a, points b){
if(a.x == b.x){
if(a.type == b.type)
return a.y > b.y;
return a.type < b.type;
}
return a.x < b.x;
}
int v[N][4];
pair<int, int> general = {INT_MIN, INT_MIN};
int main()
{
//freopen(".in","r",stdin);
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int n;
cin>>n;
vector<points> ev;
for(int i =1 ; i <=n; i++){
int x1, y1, x2, y2;
cin>>x1>>y1>>x2>>y2;
if(x1 >x2){
swap(x1, x2);
swap(y1, y2);
}
v[i][0] = x1;
v[i][1] = y1;
v[i][2] = x2;
v[i][3] = y2;
if(x1 == x2){
ev.push_back({x1, y1, 2, i});
ev.push_back({x1, y1, -1, i});
}
else{
ev.push_back({x1, y1, 1, i});
ev.push_back({x2, y2, 0, i});
}
}
sort(ev.begin(), ev.end(), cmp);
for(auto e : ev){
if(e.type == 1){
pair<int, int> last = {INT_MIN, INT_MIN};
auto nxt = act.upper_bound({e});
if(nxt != act.end()){
last = upper[(*nxt).id];
upper[(*nxt).id] = {e.x, e.y};
}
if(nxt != act.begin()){
nxt = prev(nxt);
if(lower[(*nxt).id].first > last.first)
last = lower[(*nxt).id];
lower[(*nxt).id] = {e.x, e.y};
}
if(last.first == INT_MIN)
last = general;
if(last.first != INT_MIN){
cout<<last.first<<" "<<last.second<<" "<<e.x<<" "<<e.y<<"\n";
}
act.insert({e.x, e.y, 0, e.id});
upper[e.id] = {e.x, e.y};
lower[e.id] = {e.x, e.y};
}
else if(e.type == 0){
auto itr = act.find({v[e.id][0], v[e.id][1], 0, e.id});
assert(itr != act.end());
auto nxt = next(itr);
if(nxt != act.end()){
upper[(*nxt).id] = {e.x, e.y};
}
if(itr != act.begin()){
nxt = prev(itr);
lower[(*nxt).id] = {e.x, e.y};
}
act.erase({v[e.id][0], v[e.id][1], 0, e.id});
}
else if(e.type == -1){
int ys = v[e.id][1], yf = v[e.id][3];
if(ys > yf)
swap(ys, yf);
pair<int, int> last = {INT_MIN, INT_MIN};
int tp = 0;
auto nxt = act.upper_bound({0, yf, 0, e.id});
if(nxt != act.end()){
last = upper[(*nxt).id];
tp = 1;
upper[(*nxt).id] = {e.x, yf};
}
if(nxt != act.begin()){
nxt = prev(nxt);
if(lower[(*nxt).id].first > last.first)
last = lower[(*nxt).id], tp = 2;
lower[(*nxt).id] = {e.x, ys};
}
if(tp == 1){
cout<<last.first<<" "<<last.second<<" "<<e.x<<" "<<yf<<"\n";
}
else if(tp == 2){
cout<<last.first<<" "<<last.second<<" "<<e.x<<" "<<ys<<"\n";
}
else if(general.first != INT_MIN)
cout<<general.first<<" "<<general.second<<" "<<e.x<<" "<<ys<<"\n";
lower[e.id] = {e.x, yf};
upper[e.id] = {e.x, ys};
act.insert({e.x, v[e.id][1], 0, e.id});
}
else if(e.type == 2){
act.erase({e.x, v[e.id][1], 0, e.id});
}
general = {e.x, e.y};
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Failed |
53 ms |
4324 KB |
Condition failed: "pf == Sline.end() || !Cross(S[*pi], S[*pf])" |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
464 KB |
Output is correct |
4 |
Correct |
13 ms |
1612 KB |
Output is correct |
5 |
Correct |
25 ms |
2888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
13 ms |
1624 KB |
Output is correct |
5 |
Correct |
27 ms |
2908 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
388 KB |
Output is correct |
9 |
Failed |
13 ms |
1588 KB |
Condition failed: "pf == Sline.end() || !Cross(S[*pa], S[*pf])" |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
13 ms |
1624 KB |
Output is correct |
5 |
Correct |
25 ms |
2840 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
13 ms |
1620 KB |
Output is correct |
10 |
Correct |
66 ms |
6448 KB |
Output is correct |
11 |
Failed |
1 ms |
332 KB |
Condition failed: "!Cross(S[*pi], S[*pa])" |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
12 ms |
1616 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Failed |
13 ms |
1612 KB |
Condition failed: "pf == Sline.end() || !Cross(S[*pa], S[*pf])" |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Failed |
52 ms |
4304 KB |
Condition failed: "pf == Sline.end() || !Cross(S[*pi], S[*pf])" |
3 |
Halted |
0 ms |
0 KB |
- |