This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
const int maxn = 1e6+10;
int n, x[maxn], y[maxn], trp[maxn];
int cntno, val[maxn];
void create(int i) {
int no = ++cntno;
trp[i] = no;
val[i] = i;
}
dbl findy(int i, int xcur) {
if(x[i] == x[i+1]) return y[i];
return ((dbl) y[i+1]-y[i])/((dbl) x[i+1]-x[i])*((dbl) xcur-x[i]) + y[i];
}
void solve() {
cin >> n;
vector<pair<pair<int,int>,pair<int,int>>> pts;
for(int i = 1; i <= 2*n; i+=2) {
cin >> x[i] >> y[i];
cin >> x[i+1] >> y[i+1];
if(mp(x[i],y[i]) > mp(x[i+1],y[i+1])) {
swap(x[i],x[i+1]);
swap(y[i],y[i+1]);
}
pts.pb(mp(mp(x[i],y[i]),mp(i,1)));
pts.pb(mp(mp(x[i+1],y[i+1]),mp(i,-1)));
}
sort(all(pts));
x[2*n+1] = -inf1;
x[2*n+2] = inf1;
y[2*n+1] = -inf1;
y[2*n+2] = -inf1;
val[2*n+1] = -1;
vector<int> vec;
vec.pb(2*n+1);
for(auto X : pts) {
if(X.sc.sc == 1) {
int i = X.sc.fr;
int xcur = X.fr.fr;
int id = 0; // vec[id] is the last one under i
for(int j = 0; j < vec.size(); j++) {
if(findy(vec[j],xcur) <= y[i]) {
id = j;
}
else {
break;
}
}
if(val[vec[id]] != -1) {
cout << x[i] << " " << y[i] << " " << x[val[vec[id]]] << " " << y[val[vec[id]]] << endl;
}
val[vec[id]] = i;
val[i] = i;
vector<int> newvec;
for(int j = 0; j <= id; j++) {
newvec.pb(vec[j]);
}
newvec.pb(i);
for(int j = id+1; j < vec.size(); j++) {
newvec.pb(vec[j]);
}
swap(vec,newvec);
}
else {
int i = X.sc.fr;
int xcur = X.fr.fr;
int id = 0;
for(int j = 0; j < vec.size(); j++) {
if(vec[j] == i) {
id = j;
break;
}
}
assert(id != 0);
val[vec[id-1]] = i+1;
vector<int> newvec;
for(int j = 0; j < id; j++) {
newvec.pb(vec[j]);
}
for(int j = id+1; j < vec.size(); j++) {
newvec.pb(vec[j]);
}
swap(vec,newvec);
}
}
}
int32_t main() {
ios::sync_with_stdio(false); cin.tie(0);
// freopen("in.in", "r", stdin);
// freopen("out.out", "w", stdout);
int tt = 1;
// cin >> tt;
while(tt--) {
solve();
}
}
Compilation message (stderr)
roads.cpp: In function 'void solve()':
roads.cpp:60:30: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for(int j = 0; j < vec.size(); j++) {
| ~~^~~~~~~~~~~~
roads.cpp:80:33: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | for(int j = id+1; j < vec.size(); j++) {
| ~~^~~~~~~~~~~~
roads.cpp:90:30: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | for(int j = 0; j < vec.size(); j++) {
| ~~^~~~~~~~~~~~
roads.cpp:103:33: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
103 | for(int j = id+1; j < vec.size(); j++) {
| ~~^~~~~~~~~~~~
roads.cpp:87:17: warning: unused variable 'xcur' [-Wunused-variable]
87 | int xcur = X.fr.fr;
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |