Submission #55188

# Submission time Handle Problem Language Result Execution time Memory
55188 2018-07-06T09:08:51 Z 윤교준(#1528) None (JOI14_ho_t5) C++11
30 / 100
3000 ms 20208 KB
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[sz(V)-2])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define upmax(a,b) (a)=max((a),(b))
#define upmin(a,b) (a)=min((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;

const int MAXN = 100005;
const int MAXX = 200055;

struct EVT {
	EVT(int type, int y, int idx)
		: type(type), y(y), idx(idx) {}
	int type, y, idx;

	bool operator < (const EVT &t) const {
		if(y != t.y) return y < t.y;
		return type < t.type;
	}
};

vector<EVT> EV;

int MC[MAXX];
set<int> VX;
unordered_set<int> VC[MAXX];

int ud[MAXX];

int SX[MAXN], EX[MAXN], SY[MAXN], EY[MAXN];

ll Ans;
int N, H, W;

int uf(int i) { return i == ud[i] ? i : (ud[i] = uf(ud[i])); }
void uf(int a, int b) { ud[uf(b)] = uf(a); }

void pushf(int x, int c) {
	MC[x] = c;
	VX.insert(x);
	VC[c].insert(x);
}

void popf(int x) {
	VX.erase(x);
	VC[MC[x]].erase(x);
	MC[x] = -1;
}

void unif(int a, int b) {
	a = uf(a); b = uf(b);
	if(a == b) return;
	if(sz(VC[a]) < sz(VC[b])) swap(a, b);

	for(int x : VC[b]) {
		VC[a].insert(x);
		MC[x] = a;
	}
	VC[b].clear();
	
	uf(a, b);
}

int CC[MAXX];
int linef(int sx, int ex) {
	//printf("linef %d %d\n", sx, ex);
	vector<int> V;

	for(auto it = VX.lower_bound(sx); VX.end() != it && (*it) <= ex; it++) {
		V.pb(*it);
	}

	//for(int v : V) printf("%d ", v); puts("");

	if(sz(V) < 2) return 0;

	for(int v : V) CC[MC[v]] = 0;
	for(int v : V) CC[MC[v]]++;

	vector<int> CV;
	for(int v : V) CV.pb(MC[v]);
	sorv(CV); univ(CV);

	for(int i = 1; i < sz(CV); i++)
		unif(CV[0], CV[i]);

	int ret = 0;
	for(int v : CV) ret += CC[v]-1;
	return ret;
}

int main() {
    //freopen("input.txt", "r", stdin);
	ios::sync_with_stdio(false);

	fill(MC, MC+MAXX, -1);
	iota(ud, ud+MAXX, 0);

	cin >> W >> H >> N;
	EY[0] = EY[1] = H; SX[1] = EX[1] = W;
	SY[3] = EY[3] = H; EX[2] = EX[3] = W;
	for(int i = 0; i < N; i++)
		cin >> SX[i+4] >> SY[i+4] >> EX[i+4] >> EY[i+4];
	N += 4;

	{
		vector<int> V;
		for(int i = 0; i < N; i++) {
			V.pb(SX[i]); V.pb(EX[i]);
		}

		sorv(V); univ(V);

		for(int i = 0; i < N; i++) {
			SX[i] = (int)(lower_bound(allv(V), SX[i]) - V.begin());
			EX[i] = (int)(lower_bound(allv(V), EX[i]) - V.begin());
		}
	}
	{
		vector<int> V;
		for(int i = 0; i < N; i++) {
			V.pb(SY[i]); V.pb(EY[i]);
		}

		sorv(V); univ(V);

		for(int i = 0; i < N; i++) {
			SY[i] = (int)(lower_bound(allv(V), SY[i]) - V.begin());
			EY[i] = (int)(lower_bound(allv(V), EY[i]) - V.begin());
		}
	}

	for(int i = 0; i < N; i++) {
		if(SX[i] == EX[i]) {
			EV.eb(1, SY[i], i);
			EV.eb(3, EY[i], i);
		} else {
			EV.eb(2, SY[i], i);
		}
	}

	sorv(EV);

	for(auto &v : EV) {
		if(1 == v.type) {
			int idx = v.idx, x = SX[idx];
			pushf(x, idx);
		} else if(3 == v.type) {
			int idx = v.idx, x = SX[idx];
			popf(x);
		} else {
			int sx = SX[v.idx], ex = EX[v.idx];
			Ans += linef(sx, ex);
		}

		//printf("QUR %d %d %d\n", v.type, v.y, v.idx);
		//for(int x : VX) printf("(%d,%d) ", x, MC[x]); puts("");
		//printf("Ans=%lld\n", Ans);
	}

	cout << Ans << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 16 ms 12920 KB Output is correct
2 Correct 15 ms 12920 KB Output is correct
3 Correct 15 ms 13016 KB Output is correct
4 Correct 17 ms 13016 KB Output is correct
5 Correct 15 ms 13016 KB Output is correct
6 Correct 18 ms 13016 KB Output is correct
7 Correct 15 ms 13208 KB Output is correct
8 Correct 18 ms 13208 KB Output is correct
9 Correct 17 ms 13216 KB Output is correct
10 Correct 21 ms 13216 KB Output is correct
11 Correct 20 ms 13292 KB Output is correct
12 Correct 17 ms 13292 KB Output is correct
13 Correct 22 ms 13292 KB Output is correct
14 Correct 16 ms 13292 KB Output is correct
15 Correct 15 ms 13292 KB Output is correct
16 Correct 14 ms 13292 KB Output is correct
17 Correct 17 ms 13292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 12920 KB Output is correct
2 Correct 15 ms 12920 KB Output is correct
3 Correct 15 ms 13016 KB Output is correct
4 Correct 17 ms 13016 KB Output is correct
5 Correct 15 ms 13016 KB Output is correct
6 Correct 18 ms 13016 KB Output is correct
7 Correct 15 ms 13208 KB Output is correct
8 Correct 18 ms 13208 KB Output is correct
9 Correct 17 ms 13216 KB Output is correct
10 Correct 21 ms 13216 KB Output is correct
11 Correct 20 ms 13292 KB Output is correct
12 Correct 17 ms 13292 KB Output is correct
13 Correct 22 ms 13292 KB Output is correct
14 Correct 16 ms 13292 KB Output is correct
15 Correct 15 ms 13292 KB Output is correct
16 Correct 14 ms 13292 KB Output is correct
17 Correct 17 ms 13292 KB Output is correct
18 Correct 16 ms 13292 KB Output is correct
19 Correct 17 ms 13292 KB Output is correct
20 Correct 16 ms 13292 KB Output is correct
21 Correct 20 ms 13292 KB Output is correct
22 Correct 17 ms 13292 KB Output is correct
23 Correct 18 ms 13292 KB Output is correct
24 Correct 19 ms 13292 KB Output is correct
25 Correct 19 ms 13292 KB Output is correct
26 Correct 19 ms 13308 KB Output is correct
27 Correct 24 ms 13308 KB Output is correct
28 Correct 18 ms 13308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 13308 KB Output is correct
2 Correct 20 ms 13308 KB Output is correct
3 Correct 33 ms 13308 KB Output is correct
4 Correct 17 ms 13308 KB Output is correct
5 Correct 42 ms 13708 KB Output is correct
6 Correct 175 ms 16216 KB Output is correct
7 Correct 285 ms 19336 KB Output is correct
8 Correct 315 ms 19336 KB Output is correct
9 Correct 295 ms 19440 KB Output is correct
10 Correct 230 ms 19440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 19440 KB Output is correct
2 Correct 19 ms 19440 KB Output is correct
3 Correct 446 ms 19440 KB Output is correct
4 Correct 13 ms 19440 KB Output is correct
5 Correct 17 ms 19440 KB Output is correct
6 Execution timed out 3042 ms 20208 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 12920 KB Output is correct
2 Correct 15 ms 12920 KB Output is correct
3 Correct 15 ms 13016 KB Output is correct
4 Correct 17 ms 13016 KB Output is correct
5 Correct 15 ms 13016 KB Output is correct
6 Correct 18 ms 13016 KB Output is correct
7 Correct 15 ms 13208 KB Output is correct
8 Correct 18 ms 13208 KB Output is correct
9 Correct 17 ms 13216 KB Output is correct
10 Correct 21 ms 13216 KB Output is correct
11 Correct 20 ms 13292 KB Output is correct
12 Correct 17 ms 13292 KB Output is correct
13 Correct 22 ms 13292 KB Output is correct
14 Correct 16 ms 13292 KB Output is correct
15 Correct 15 ms 13292 KB Output is correct
16 Correct 14 ms 13292 KB Output is correct
17 Correct 17 ms 13292 KB Output is correct
18 Correct 16 ms 13292 KB Output is correct
19 Correct 17 ms 13292 KB Output is correct
20 Correct 16 ms 13292 KB Output is correct
21 Correct 20 ms 13292 KB Output is correct
22 Correct 17 ms 13292 KB Output is correct
23 Correct 18 ms 13292 KB Output is correct
24 Correct 19 ms 13292 KB Output is correct
25 Correct 19 ms 13292 KB Output is correct
26 Correct 19 ms 13308 KB Output is correct
27 Correct 24 ms 13308 KB Output is correct
28 Correct 18 ms 13308 KB Output is correct
29 Correct 16 ms 13308 KB Output is correct
30 Correct 20 ms 13308 KB Output is correct
31 Correct 33 ms 13308 KB Output is correct
32 Correct 17 ms 13308 KB Output is correct
33 Correct 42 ms 13708 KB Output is correct
34 Correct 175 ms 16216 KB Output is correct
35 Correct 285 ms 19336 KB Output is correct
36 Correct 315 ms 19336 KB Output is correct
37 Correct 295 ms 19440 KB Output is correct
38 Correct 230 ms 19440 KB Output is correct
39 Correct 15 ms 19440 KB Output is correct
40 Correct 19 ms 19440 KB Output is correct
41 Correct 446 ms 19440 KB Output is correct
42 Correct 13 ms 19440 KB Output is correct
43 Correct 17 ms 19440 KB Output is correct
44 Execution timed out 3042 ms 20208 KB Time limit exceeded
45 Halted 0 ms 0 KB -