Submission #230240

# Submission time Handle Problem Language Result Execution time Memory
230240 2020-05-09T09:37:01 Z onjo0127 None (JOI14_ho_t5) C++11
100 / 100
1166 ms 12132 KB
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
const int _N = 100009;

struct line {
	int p, l, r;
};

long long ans;
int W, H, N, A[_N], B[_N], C[_N], D[_N], pa[_N], lc;
set<pii> S;
line L[_N];

int getx(vector<int> &S, int x) { return lower_bound(S.begin(), S.end(), x) - S.begin() + 1; }

int root(int x) {
	if(pa[x] == x) return x;
	return pa[x] = root(pa[x]);
}
void merg(int u, int v) {
	u = root(u); v = root(v);
	if(u != v) pa[u] = v;
}

void dnc_y(int s, int e, vector<int> &VL, vector<int> &HL) {
	if(VL.empty() || HL.empty()) return;
	vector<int> MV, NV, LH, RH;
	int m = s+e >> 1;
	for(auto& it: VL) {
		if(L[it].r < s || e < L[it].l) continue;
		if(L[it].l <= s && e <= L[it].r) MV.push_back(it);
		else NV.push_back(it);
	}
	for(auto& it: HL) {
		if(L[it].p <= m) LH.push_back(it);
		else RH.push_back(it);
	}
	if(s != e) {
		dnc_y(s, m, NV, LH);
		dnc_y(m+1, e, NV, RH);
	}
	if(MV.size()) {
		ans += (ll)MV.size() * (ll)HL.size();
		for(auto& it: MV) merg(it, HL[0]);
		for(auto& it: HL) merg(it, HL[0]);
	}
}

void dnc_x(int s, int e, vector<int> &VL, vector<int> &HL) {
	if(VL.empty() || HL.empty()) return;
	vector<int> LV, RV, NH, MH;
	int m = s+e >> 1;
	for(auto& it: VL) {
		if(L[it].p <= m) LV.push_back(it);
		else RV.push_back(it);
	}
	for(auto& it: HL) {
		if(L[it].r < s || e < L[it].l) continue;
		if(L[it].l <= s && e <= L[it].r) MH.push_back(it);
		else NH.push_back(it);
	}
	if(s != e) {
		dnc_x(s, m, LV, NH);
		dnc_x(m+1, e, RV, NH);
	}
	dnc_y(1, H, VL, MH);
}

int main() {
	vector<int> XS, YS;
	scanf("%d%d%d",&W,&H,&N);
	XS.push_back(0); XS.push_back(W);
	YS.push_back(0); YS.push_back(H);
	for(int i=0; i<N; i++) {
		scanf("%d%d%d%d", &A[i], &B[i], &C[i], &D[i]);
		XS.push_back(A[i]); XS.push_back(C[i]);
		YS.push_back(B[i]); YS.push_back(D[i]);
	}
	sort(XS.begin(), XS.end()); XS.resize(unique(XS.begin(), XS.end()) - XS.begin());
	sort(YS.begin(), YS.end()); YS.resize(unique(YS.begin(), YS.end()) - YS.begin());
	W = getx(XS, W); H = getx(YS, H);
	for(int i=0; i<N; i++) {
		A[i] = getx(XS, A[i]);
		B[i] = getx(YS, B[i]);
		C[i] = getx(XS, C[i]);
		D[i] = getx(YS, D[i]);
	}
	vector<int> VL, HL;
	L[++lc] = {1, 1, H}; VL.push_back(lc);
	L[++lc] = {W, 1, H}; VL.push_back(lc);
	L[++lc] = {1, 1, W}; HL.push_back(lc);
	L[++lc] = {H, 1, W}; HL.push_back(lc);
	for(int i=0; i<N; i++) {
		if(A[i] == C[i]) {
			L[++lc] = {A[i], B[i], D[i]};
			VL.push_back(lc);
		}
		if(B[i] == D[i]) {
			L[++lc] = {B[i], A[i], C[i]};
			HL.push_back(lc);
		}
	}
	for(int i=1; i<=lc; i++) pa[i] = i;
	ans = -N-4;
	dnc_x(1, W, VL, HL);
	for(int i=1; i<=lc; i++) if(root(i) == i) ++ans;
	ans += S.size();
	printf("%lld", ans);
	return 0;
}

Compilation message

2014_ho_t5.cpp: In function 'void dnc_y(int, int, std::vector<int>&, std::vector<int>&)':
2014_ho_t5.cpp:30:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int m = s+e >> 1;
          ~^~
2014_ho_t5.cpp: In function 'void dnc_x(int, int, std::vector<int>&, std::vector<int>&)':
2014_ho_t5.cpp:54:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int m = s+e >> 1;
          ~^~
2014_ho_t5.cpp: In function 'int main()':
2014_ho_t5.cpp:73:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d",&W,&H,&N);
  ~~~~~^~~~~~~~~~~~~~~~~~~
2014_ho_t5.cpp:77:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d%d", &A[i], &B[i], &C[i], &D[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 7 ms 384 KB Output is correct
8 Correct 10 ms 512 KB Output is correct
9 Correct 7 ms 512 KB Output is correct
10 Correct 9 ms 384 KB Output is correct
11 Correct 9 ms 384 KB Output is correct
12 Correct 7 ms 384 KB Output is correct
13 Correct 10 ms 384 KB Output is correct
14 Correct 7 ms 384 KB Output is correct
15 Correct 7 ms 512 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 7 ms 384 KB Output is correct
8 Correct 10 ms 512 KB Output is correct
9 Correct 7 ms 512 KB Output is correct
10 Correct 9 ms 384 KB Output is correct
11 Correct 9 ms 384 KB Output is correct
12 Correct 7 ms 384 KB Output is correct
13 Correct 10 ms 384 KB Output is correct
14 Correct 7 ms 384 KB Output is correct
15 Correct 7 ms 512 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 9 ms 512 KB Output is correct
22 Correct 8 ms 384 KB Output is correct
23 Correct 10 ms 384 KB Output is correct
24 Correct 9 ms 512 KB Output is correct
25 Correct 10 ms 384 KB Output is correct
26 Correct 7 ms 384 KB Output is correct
27 Correct 10 ms 384 KB Output is correct
28 Correct 10 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 384 KB Output is correct
2 Correct 7 ms 384 KB Output is correct
3 Correct 7 ms 384 KB Output is correct
4 Correct 9 ms 384 KB Output is correct
5 Correct 58 ms 1152 KB Output is correct
6 Correct 264 ms 3564 KB Output is correct
7 Correct 518 ms 6752 KB Output is correct
8 Correct 542 ms 6772 KB Output is correct
9 Correct 345 ms 6752 KB Output is correct
10 Correct 219 ms 6916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 11 ms 384 KB Output is correct
3 Correct 89 ms 1276 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 10 ms 384 KB Output is correct
6 Correct 1120 ms 7568 KB Output is correct
7 Correct 16 ms 1408 KB Output is correct
8 Correct 118 ms 9828 KB Output is correct
9 Correct 237 ms 11992 KB Output is correct
10 Correct 228 ms 12040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 7 ms 384 KB Output is correct
8 Correct 10 ms 512 KB Output is correct
9 Correct 7 ms 512 KB Output is correct
10 Correct 9 ms 384 KB Output is correct
11 Correct 9 ms 384 KB Output is correct
12 Correct 7 ms 384 KB Output is correct
13 Correct 10 ms 384 KB Output is correct
14 Correct 7 ms 384 KB Output is correct
15 Correct 7 ms 512 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 9 ms 512 KB Output is correct
22 Correct 8 ms 384 KB Output is correct
23 Correct 10 ms 384 KB Output is correct
24 Correct 9 ms 512 KB Output is correct
25 Correct 10 ms 384 KB Output is correct
26 Correct 7 ms 384 KB Output is correct
27 Correct 10 ms 384 KB Output is correct
28 Correct 10 ms 512 KB Output is correct
29 Correct 8 ms 384 KB Output is correct
30 Correct 7 ms 384 KB Output is correct
31 Correct 7 ms 384 KB Output is correct
32 Correct 9 ms 384 KB Output is correct
33 Correct 58 ms 1152 KB Output is correct
34 Correct 264 ms 3564 KB Output is correct
35 Correct 518 ms 6752 KB Output is correct
36 Correct 542 ms 6772 KB Output is correct
37 Correct 345 ms 6752 KB Output is correct
38 Correct 219 ms 6916 KB Output is correct
39 Correct 5 ms 384 KB Output is correct
40 Correct 11 ms 384 KB Output is correct
41 Correct 89 ms 1276 KB Output is correct
42 Correct 5 ms 384 KB Output is correct
43 Correct 10 ms 384 KB Output is correct
44 Correct 1120 ms 7568 KB Output is correct
45 Correct 16 ms 1408 KB Output is correct
46 Correct 118 ms 9828 KB Output is correct
47 Correct 237 ms 11992 KB Output is correct
48 Correct 228 ms 12040 KB Output is correct
49 Correct 9 ms 384 KB Output is correct
50 Correct 8 ms 512 KB Output is correct
51 Correct 8 ms 384 KB Output is correct
52 Correct 527 ms 5608 KB Output is correct
53 Correct 227 ms 5356 KB Output is correct
54 Correct 444 ms 5804 KB Output is correct
55 Correct 1165 ms 10860 KB Output is correct
56 Correct 521 ms 10300 KB Output is correct
57 Correct 969 ms 11416 KB Output is correct
58 Correct 1166 ms 10720 KB Output is correct
59 Correct 193 ms 11372 KB Output is correct
60 Correct 233 ms 12132 KB Output is correct
61 Correct 222 ms 11816 KB Output is correct
62 Correct 199 ms 11204 KB Output is correct
63 Correct 1110 ms 11200 KB Output is correct
64 Correct 359 ms 10472 KB Output is correct
65 Correct 1024 ms 11060 KB Output is correct
66 Correct 1068 ms 10976 KB Output is correct
67 Correct 892 ms 10808 KB Output is correct
68 Correct 845 ms 10724 KB Output is correct
69 Correct 497 ms 11124 KB Output is correct
70 Correct 492 ms 11080 KB Output is correct
71 Correct 163 ms 9824 KB Output is correct
72 Correct 178 ms 9440 KB Output is correct