#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];
int cntno, val[maxn], sz[maxn], lc[maxn], rc[maxn], prior[maxn], tr[maxn], pt[maxn];
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];
}
dbl findywtf(int i, int xcur, int wtf) {
if(x[i] == x[i+1]) return y[i+wtf];
return ((dbl) y[i+1]-y[i])/((dbl) x[i+1]-x[i])*((dbl) xcur-x[i]) + y[i];
}
int create(int i) {
int no = ++cntno;
pt[no] = i;
tr[i] = no;
val[no] = i;
sz[no] = 1;
prior[no] = rand();
return no;
}
void calc(int no) {
if(no == 0) return;
sz[no] = sz[lc[no]]+1+sz[rc[no]];
}
int merge(int l, int r) {
if(l == 0) return r;
if(r == 0) return l;
if(prior[l] <= prior[r]) {
rc[l] = merge(rc[l],r);
calc(l);
return l;
}
else {
lc[r] = merge(l,lc[r]);
calc(r);
return r;
}
}
pair<int,int> splitval(int no, int curx, int y0) {
if(no == 0) return mp(0,0);
if(findy(pt[no],curx) <= y0) {
auto aux = splitval(rc[no],curx,y0);
rc[no] = aux.fr;
calc(no);
return mp(no,aux.sc);
}
else {
auto aux = splitval(lc[no],curx,y0);
lc[no] = aux.sc;
calc(no);
return mp(aux.fr,no);
}
}
void solve() {
cin >> n;
vector<pair<pair<int,int>,pair<int,int>>> pts;
bool ok = 0;
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])) ok = 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)));
}
for(int i = 1; i <= 2*n; i+= 2) {
for(int j = 1; j <= 2*n; j+= 2) {
if(i == j) continue;
if(x[i+1] < x[j] || x[j+1] < x[i]) continue;
int x1 = max(x[i],x[j]);
int x2 = min(x[i+1],x[j+1]);
if(findywtf(i,x1,0) <= findywtf(j,x1,0) && findywtf(i,x2,1) >= findywtf(j,x2,1)) ok = 1;
}
}
if(ok) {
cout << -1 << endl;
return;
}
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] = 2*n+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]] != 2*n+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
roads.cpp: In function 'void solve()':
roads.cpp:122: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]
122 | for(int j = 0; j < vec.size(); j++) {
| ~~^~~~~~~~~~~~
roads.cpp:142: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]
142 | for(int j = id+1; j < vec.size(); j++) {
| ~~^~~~~~~~~~~~
roads.cpp:152: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]
152 | for(int j = 0; j < vec.size(); j++) {
| ~~^~~~~~~~~~~~
roads.cpp:165: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]
165 | for(int j = id+1; j < vec.size(); j++) {
| ~~^~~~~~~~~~~~
roads.cpp:149:17: warning: unused variable 'xcur' [-Wunused-variable]
149 | int xcur = X.fr.fr;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Execution timed out |
1084 ms |
5528 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
4 ms |
468 KB |
Output is correct |
4 |
Correct |
333 ms |
1792 KB |
Output is correct |
5 |
Execution timed out |
1090 ms |
3024 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
337 ms |
1800 KB |
Output is correct |
5 |
Execution timed out |
1083 ms |
3024 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
5 ms |
468 KB |
Output is correct |
4 |
Correct |
342 ms |
1800 KB |
Output is correct |
5 |
Execution timed out |
1085 ms |
3024 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
5 ms |
468 KB |
Output is correct |
5 |
Correct |
346 ms |
1796 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
5 ms |
468 KB |
Output is correct |
9 |
Correct |
328 ms |
1924 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
6 ms |
468 KB |
Output is correct |
13 |
Correct |
328 ms |
1800 KB |
Output is correct |
14 |
Correct |
1 ms |
464 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
4 ms |
468 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
36 ms |
924 KB |
Output is correct |
23 |
Correct |
34 ms |
848 KB |
Output is correct |
24 |
Correct |
109 ms |
1440 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Execution timed out |
1089 ms |
5580 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |