#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ldb long double
#define pb push_back
#define mp make_pair
struct pt{ll x,y;pt(ll a=0,ll b=0):x(a),y(b){}};
bool operator < (pt a,pt b){return mp(a.x,a.y)<mp(b.x,b.y);}
const int N=100050;
const int lim=1e8;
pt a[N][2];
ll tme;
ldb sec(int i){
if(tme==a[i][0].x)return a[i][0].y;
ldb k=(ldb)(a[i][1].y-a[i][0].y)/(a[i][1].x-a[i][0].x);
ldb n=a[i][0].y-a[i][0].x*k;
return tme*k+n;
}
struct seg{
int idx;
mutable pt rig;
seg(){}
seg(int i):idx(i){}
};
bool operator < (seg a,seg b){
return sec(a.idx)<sec(b.idx);
}
set<seg> all;
int main(){
int n;
scanf("%i",&n);
vector<pair<pt,int>> evs;
for(int i=1;i<=n;i++){
scanf("%lld %lld %lld %lld",&a[i][0].x,&a[i][0].y,&a[i][1].x,&a[i][1].y);
if(a[i][1]<a[i][0])swap(a[i][0],a[i][1]);
evs.pb({a[i][0],i});
evs.pb({a[i][1],-i});
}
a[n+1][0]=pt(-lim,-lim);
a[n+1][1]=pt(lim,-lim);
a[n+2][0]=pt(-lim,lim);
a[n+2][1]=pt(lim,lim);
tme=-lim;
all.insert(seg(n+1));
all.begin()->rig=pt(-lim,-lim);
all.insert(seg(n+2));
sort(evs.begin(),evs.end());
for(auto e:evs){
pt p=e.first;
int i=abs(e.second);
tme=p.x;
if(e.second>0){
all.insert(seg(i));
auto it=all.find((seg(i)));
it->rig=p;
pt now=prev(it)->rig;
prev(it)->rig=p;
if(now.x!=-lim)printf("%lld %lld %lld %lld\n",now.x,now.y,p.x,p.y);
}else{
auto it=all.find(seg(i));
prev(it)->rig=p;
all.erase(it);
}
}
return 0;
}
Compilation message
roads.cpp: In function 'int main()':
roads.cpp:31:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
31 | scanf("%i",&n);
| ~~~~~^~~~~~~~~
roads.cpp:34:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
34 | scanf("%lld %lld %lld %lld",&a[i][0].x,&a[i][0].y,&a[i][1].x,&a[i][1].y);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3456 KB |
Output is correct |
2 |
Correct |
70 ms |
6636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3456 KB |
Output is correct |
2 |
Correct |
2 ms |
3456 KB |
Output is correct |
3 |
Correct |
4 ms |
3584 KB |
Output is correct |
4 |
Correct |
16 ms |
4348 KB |
Output is correct |
5 |
Correct |
30 ms |
5112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3456 KB |
Output is correct |
2 |
Correct |
2 ms |
3456 KB |
Output is correct |
3 |
Correct |
4 ms |
3584 KB |
Output is correct |
4 |
Correct |
16 ms |
4348 KB |
Output is correct |
5 |
Correct |
30 ms |
5112 KB |
Output is correct |
6 |
Correct |
2 ms |
3456 KB |
Output is correct |
7 |
Correct |
2 ms |
3456 KB |
Output is correct |
8 |
Correct |
4 ms |
3584 KB |
Output is correct |
9 |
Correct |
17 ms |
4348 KB |
Output is correct |
10 |
Correct |
205 ms |
11228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3456 KB |
Output is correct |
2 |
Correct |
2 ms |
3456 KB |
Output is correct |
3 |
Correct |
4 ms |
3584 KB |
Output is correct |
4 |
Correct |
17 ms |
4348 KB |
Output is correct |
5 |
Correct |
31 ms |
5112 KB |
Output is correct |
6 |
Correct |
2 ms |
3456 KB |
Output is correct |
7 |
Correct |
3 ms |
3584 KB |
Output is correct |
8 |
Correct |
4 ms |
3616 KB |
Output is correct |
9 |
Correct |
16 ms |
4348 KB |
Output is correct |
10 |
Correct |
74 ms |
7396 KB |
Output is correct |
11 |
Correct |
3 ms |
3456 KB |
Output is correct |
12 |
Correct |
2 ms |
3488 KB |
Output is correct |
13 |
Correct |
2 ms |
3456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3456 KB |
Output is correct |
2 |
Correct |
2 ms |
3456 KB |
Output is correct |
3 |
Correct |
3 ms |
3456 KB |
Output is correct |
4 |
Correct |
4 ms |
3584 KB |
Output is correct |
5 |
Correct |
16 ms |
4348 KB |
Output is correct |
6 |
Correct |
2 ms |
3456 KB |
Output is correct |
7 |
Correct |
2 ms |
3456 KB |
Output is correct |
8 |
Correct |
4 ms |
3584 KB |
Output is correct |
9 |
Correct |
17 ms |
4348 KB |
Output is correct |
10 |
Correct |
2 ms |
3456 KB |
Output is correct |
11 |
Correct |
2 ms |
3456 KB |
Output is correct |
12 |
Correct |
3 ms |
3584 KB |
Output is correct |
13 |
Correct |
16 ms |
4348 KB |
Output is correct |
14 |
Correct |
2 ms |
3456 KB |
Output is correct |
15 |
Correct |
2 ms |
3456 KB |
Output is correct |
16 |
Correct |
3 ms |
3488 KB |
Output is correct |
17 |
Correct |
2 ms |
3456 KB |
Output is correct |
18 |
Correct |
3 ms |
3456 KB |
Output is correct |
19 |
Correct |
3 ms |
3456 KB |
Output is correct |
20 |
Correct |
3 ms |
3584 KB |
Output is correct |
21 |
Correct |
2 ms |
3456 KB |
Output is correct |
22 |
Correct |
9 ms |
3776 KB |
Output is correct |
23 |
Correct |
8 ms |
3776 KB |
Output is correct |
24 |
Correct |
18 ms |
4092 KB |
Output is correct |
25 |
Correct |
2 ms |
3456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3488 KB |
Output is correct |
2 |
Correct |
71 ms |
6644 KB |
Output is correct |
3 |
Correct |
2 ms |
3456 KB |
Output is correct |
4 |
Correct |
2 ms |
3456 KB |
Output is correct |
5 |
Correct |
4 ms |
3584 KB |
Output is correct |
6 |
Correct |
16 ms |
4348 KB |
Output is correct |
7 |
Correct |
30 ms |
5112 KB |
Output is correct |
8 |
Correct |
2 ms |
3456 KB |
Output is correct |
9 |
Correct |
3 ms |
3456 KB |
Output is correct |
10 |
Correct |
4 ms |
3584 KB |
Output is correct |
11 |
Correct |
17 ms |
4348 KB |
Output is correct |
12 |
Correct |
206 ms |
11228 KB |
Output is correct |
13 |
Correct |
2 ms |
3456 KB |
Output is correct |
14 |
Correct |
2 ms |
3456 KB |
Output is correct |
15 |
Correct |
4 ms |
3584 KB |
Output is correct |
16 |
Correct |
16 ms |
4348 KB |
Output is correct |
17 |
Correct |
77 ms |
7524 KB |
Output is correct |
18 |
Correct |
2 ms |
3456 KB |
Output is correct |
19 |
Correct |
2 ms |
3456 KB |
Output is correct |
20 |
Correct |
3 ms |
3456 KB |
Output is correct |
21 |
Correct |
3 ms |
3456 KB |
Output is correct |
22 |
Correct |
2 ms |
3456 KB |
Output is correct |
23 |
Correct |
3 ms |
3456 KB |
Output is correct |
24 |
Correct |
3 ms |
3584 KB |
Output is correct |
25 |
Correct |
2 ms |
3456 KB |
Output is correct |
26 |
Correct |
9 ms |
3776 KB |
Output is correct |
27 |
Correct |
10 ms |
3776 KB |
Output is correct |
28 |
Correct |
15 ms |
4092 KB |
Output is correct |
29 |
Correct |
116 ms |
9184 KB |
Output is correct |
30 |
Correct |
170 ms |
11612 KB |
Output is correct |
31 |
Correct |
2 ms |
3456 KB |
Output is correct |
32 |
Correct |
132 ms |
8804 KB |
Output is correct |
33 |
Correct |
130 ms |
8676 KB |
Output is correct |
34 |
Correct |
175 ms |
10584 KB |
Output is correct |
35 |
Correct |
182 ms |
10712 KB |
Output is correct |
36 |
Correct |
203 ms |
13016 KB |
Output is correct |