답안 #588587

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
588587 2022-07-03T15:36:52 Z jiahng Roads (CEOI20_roads) C++14
100 / 100
206 ms 16156 KB
#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';
		iterator z;
		if (v[x].f.f == v[x].s.f) z = insert(ipi(x, v[x].s)).f;
		else z = insert(ipi(x, v[x].f)).f;
		if (z != begin()){
			--z;
			ipi n = ipi(z->f, max(z->s, v[x].f));
			if (v[x].f.f == v[x].s.f) n.s = max(n.s, v[x].s);
			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, 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 4536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 292 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 10 ms 1792 KB Output is correct
5 Correct 23 ms 3256 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 Correct 1 ms 340 KB Output is correct
4 Correct 11 ms 1744 KB Output is correct
5 Correct 21 ms 3172 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 2 ms 368 KB Output is correct
9 Correct 12 ms 1744 KB Output is correct
10 Correct 190 ms 14416 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 Correct 1 ms 340 KB Output is correct
4 Correct 11 ms 1760 KB Output is correct
5 Correct 22 ms 3184 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 12 ms 1744 KB Output is correct
10 Correct 52 ms 7312 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 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 Correct 1 ms 340 KB Output is correct
5 Correct 10 ms 1740 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 20 ms 1692 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 11 ms 1744 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 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 2 ms 340 KB Output is correct
21 Correct 1 ms 316 KB Output is correct
22 Correct 9 ms 844 KB Output is correct
23 Correct 8 ms 852 KB Output is correct
24 Correct 15 ms 1360 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 72 ms 4488 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 2 ms 356 KB Output is correct
6 Correct 10 ms 1744 KB Output is correct
7 Correct 22 ms 3164 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 464 KB Output is correct
11 Correct 16 ms 1708 KB Output is correct
12 Correct 206 ms 14520 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 13 ms 1812 KB Output is correct
17 Correct 60 ms 7288 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 328 KB Output is correct
24 Correct 2 ms 352 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 7 ms 848 KB Output is correct
27 Correct 12 ms 852 KB Output is correct
28 Correct 17 ms 1272 KB Output is correct
29 Correct 121 ms 9812 KB Output is correct
30 Correct 183 ms 12148 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 161 ms 9540 KB Output is correct
33 Correct 138 ms 9564 KB Output is correct
34 Correct 188 ms 13376 KB Output is correct
35 Correct 201 ms 13760 KB Output is correct
36 Correct 206 ms 16156 KB Output is correct