# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1111839 |
2024-11-13T04:14:59 Z |
doducanh |
Roads (CEOI20_roads) |
C++14 |
|
138 ms |
13248 KB |
///breaker
#pragma GCC optimize("O2")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define ii pair<int,int>
#define mp make_pair
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define bit(x,i) ((x>>i)&1)
#define lc (id<<1)
#define rc ((id<<1)^1)
const int inf=1e7;
const int maxn=1e5+7;
int x;
struct segment
{
int x1,y1,x2,y2,rx,ry;
int id;
double get_y() const{
return (x1==x2? y1 : y1 + (double)(y2 - y1) / (x2 - x1) * (x - x1));
}
bool operator<(segment const &s) const { return get_y() < s.get_y(); }
}a[maxn];
struct event
{
int x,y,type,id;
};
bool cmp(const event &a,const event &b)
{
return (a.x<b.x||(a.x==b.x&&a.y<b.y));
}
int n;
vector<event>events;
void sol(void){
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i].x1>>a[i].y1>>a[i].x2>>a[i].y2;
if (a[i].x2 < a[i].x1 || (a[i].x1 == a[i].x2 && a[i].y2 < a[i].y1))
swap(a[i].x1, a[i].x2), swap(a[i].y1, a[i].y2);
a[i].id=i;
events.push_back({a[i].x1,a[i].y1,0,i});
events.push_back({a[i].x2,a[i].y2,1,i});
}
sort(events.begin(),events.end(),cmp);
a[n].x1=-inf,a[n].x2=inf,a[n].y1=-inf,a[n].y2=-inf;
a[n].rx=-inf,a[n].ry=-inf;
a[n].id=n;
auto compare_segment = [](auto const &i, auto const &j)
{ return a[i] < a[j]; };
set<int, decltype(compare_segment)> s(compare_segment);
s.insert(n);
for(event tmp:events){
x=tmp.x;
if(tmp.type==0){
auto it=s.lower_bound(tmp.id);
it--;
if(a[*it].rx!=-inf){
cout<<a[*it].rx<<" "<<a[*it].ry<<" "<<a[tmp.id].x1<<" "<<a[tmp.id].y1<<"\n";
}
a[*it].rx=a[tmp.id].x1;
a[*it].ry=a[tmp.id].y1;
it=s.insert(tmp.id).fi;
a[*it].rx=a[tmp.id].x1;
a[*it].ry=a[tmp.id].y1;
}
else{
auto it=s.find(tmp.id);
it=--s.erase(it);
a[*it].rx=a[tmp.id].x2;
a[*it].ry=a[tmp.id].y2;
}
}
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t=1;
while(t--){
sol();
}
// you should actually read the stuff at the bottom
return 0;
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
42 ms |
6656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
592 KB |
Output is correct |
4 |
Correct |
11 ms |
3540 KB |
Output is correct |
5 |
Correct |
17 ms |
4556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
592 KB |
Output is correct |
4 |
Correct |
13 ms |
3540 KB |
Output is correct |
5 |
Correct |
19 ms |
4556 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
504 KB |
Output is correct |
8 |
Correct |
2 ms |
592 KB |
Output is correct |
9 |
Correct |
10 ms |
3540 KB |
Output is correct |
10 |
Correct |
119 ms |
13240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
592 KB |
Output is correct |
4 |
Correct |
9 ms |
3540 KB |
Output is correct |
5 |
Correct |
16 ms |
4488 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
476 KB |
Output is correct |
8 |
Correct |
2 ms |
592 KB |
Output is correct |
9 |
Correct |
8 ms |
3556 KB |
Output is correct |
10 |
Correct |
39 ms |
7596 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
2 ms |
508 KB |
Output is correct |
5 |
Correct |
8 ms |
3540 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
592 KB |
Output is correct |
9 |
Correct |
10 ms |
3540 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
480 KB |
Output is correct |
13 |
Correct |
8 ms |
3540 KB |
Output is correct |
14 |
Correct |
1 ms |
504 KB |
Output is correct |
15 |
Correct |
1 ms |
504 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
2 ms |
508 KB |
Output is correct |
21 |
Correct |
1 ms |
504 KB |
Output is correct |
22 |
Correct |
5 ms |
848 KB |
Output is correct |
23 |
Correct |
7 ms |
1104 KB |
Output is correct |
24 |
Correct |
10 ms |
3284 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
48 ms |
6860 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
592 KB |
Output is correct |
6 |
Correct |
10 ms |
3540 KB |
Output is correct |
7 |
Correct |
18 ms |
4556 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
2 ms |
592 KB |
Output is correct |
11 |
Correct |
10 ms |
3540 KB |
Output is correct |
12 |
Correct |
138 ms |
13248 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
2 ms |
592 KB |
Output is correct |
16 |
Correct |
9 ms |
3540 KB |
Output is correct |
17 |
Correct |
40 ms |
7624 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
2 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
7 ms |
948 KB |
Output is correct |
27 |
Correct |
5 ms |
1016 KB |
Output is correct |
28 |
Correct |
10 ms |
3284 KB |
Output is correct |
29 |
Correct |
66 ms |
7864 KB |
Output is correct |
30 |
Correct |
82 ms |
12396 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
83 ms |
9160 KB |
Output is correct |
33 |
Correct |
79 ms |
9152 KB |
Output is correct |
34 |
Correct |
110 ms |
12736 KB |
Output is correct |
35 |
Correct |
109 ms |
12904 KB |
Output is correct |
36 |
Correct |
105 ms |
12868 KB |
Output is correct |