#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int32_t, int32_t> pi;
typedef vector <int> vi;
typedef vector <pi> vpi;
typedef pair<pi, ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define mp make_pair
#define FOR(i,s,e) for(int i=s;i<=int(e);++i)
#define DEC(i,s,e) for(int i=s;i>=int(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define maxn 400010
#define INF (ll)(1e9+10)
#define MOD 1000000007
typedef pair <vi, int> pvi;
typedef pair <int,pi> ipi;
typedef vector <pii> vpii;
typedef pair <pi,pi> pipi;
int N;
pi l, r;
ld isect(pipi line, int x){
if (line.s.f == line.f.f) return line.f.s;
ld m = ld(line.s.s - line.f.s) / ld(line.s.f - line.f.f);
return m * ld(x - line.f.f) + line.f.s;
}
vector <pipi> v;
struct cmp{
bool operator()(ipi x, ipi y){
int i = x.f, j = y.f;
return isect(v[i], max(v[i].f.f, v[j].f.f)) < isect(v[j], max(v[i].f.f, v[j].f.f));
}
};
struct DS : set <ipi, cmp> { // (index, rmost)
void add(int x){
//~ cout << "ADD " << x << '\n';
auto z = insert(ipi(x, v[x].f)).f;
if (z != begin()){
--z;
ipi n = ipi(z->f, max(z->s, v[x].f));
erase(z);
insert(n);
}
}
void remove(int x){
//~ cout << "REMOVE " << x << '\n';
iterator z = --upper_bound(ipi(x, pi(-1,-1)));
pi rmost = z->s;
assert(z != end());
z = erase(z);
if (z != begin()){
z--;
ipi n = ipi(z->f, max({z->s, rmost, v[x].s}));
erase(z);
insert(n);
}
}
ipi qry(int x){
auto z = lower_bound(ipi(x, v[x].f));
//~ if (z == begin()){
//~ cout << "BAD " << z->f << ' ' << z->s.f << ' ' << z->s.s << '\n';
//~ exit(0);
//~ }
assert(z != begin());
return *(--z);
}
};
int32_t main(){
fast;
cin >> N;
FOR(i,1,N){
cin >> l.f >> l.s >> r.f >> r.s;
if (l > r) swap(l, r);
v.pb(pipi(l, r));
}
v.pb(pipi(pi(-INF, -INF), pi(INF, -INF)));
sort(all(v));
vector <pii> v2;
FOR(i,1,v.size()-1){
v2.pb(pii(pi(v[i].f.f, i), 1));
v2.pb(pii(pi(v[i].s.f+1, i), 0));
}
sort(all(v2), [](pii i,pii j){
if (i.f.f != j.f.f) return i.f.f < j.f.f;
if (i.s != j.s) return i.s < j.s;
return i.f.s < j.f.s;
});
//~ cout << isect(v[1], v[1].f.f);
//~ FOR(i,1,v.size()-1){
//~ if (!cmp()(ipi(0, pi(-1,-1)), ipi(i, pi(-1,-1)))){
//~ cout << isect(v[0], v[i].f.f) << ' ' << isect(v[i], v[i].f.f) << '\n';
//~ }
//~ }
//~ return 0;
DS st; st.add(0);
//~ pi x = st.qry(1);
//~ cout << v[0].f.f << ' ' << v[0].f.s << '\n';
//~ return 0;
vector <pipi> ans;
aFOR(i, v2){
int x = i.f.s;
if (i.s == 1){
//~ if (x == (int)v.size()-1) cout << st.qry(x).f << '\n';
pi rmost = st.qry(x).s;
if (rmost.f != -INF) ans.pb(pipi(v[x].f, rmost));
st.add(x);
}else st.remove(x);
}
aFOR(i,ans){
cout << i.f.f << ' ' << i.f.s << ' ' << i.s.f << ' ' << i.s.s << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
78 ms |
5428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Failed |
2 ms |
340 KB |
Condition failed: "pf == Sline.end() || !Cross(S[*pi], S[*pf])" |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Failed |
2 ms |
340 KB |
Condition failed: "pf == Sline.end() || !Cross(S[*pi], S[*pf])" |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Failed |
2 ms |
340 KB |
Condition failed: "pf == Sline.end() || !Cross(S[*pi], S[*pf])" |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Failed |
2 ms |
468 KB |
Condition failed: "pf == Sline.end() || !Cross(S[*pi], S[*pf])" |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
71 ms |
5496 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Failed |
1 ms |
468 KB |
Condition failed: "pf == Sline.end() || !Cross(S[*pi], S[*pf])" |
6 |
Halted |
0 ms |
0 KB |
- |