답안 #162093

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
162093 2019-11-06T10:54:51 Z Minnakhmetov 무지개나라 (APIO17_rainbow) C++14
100 / 100
1987 ms 175568 KB
#include "rainbow.h"
#include <bits/stdc++.h>

using namespace std;

#define all(aaa) aaa.begin(), aaa.end()

const int N = 2e5 + 5, INF = 1e9;

struct ST {
	vector<pair<int, int>> pts;
	vector<int> t[N * 4];

	void init() {
		if (!pts.empty()) {
			sort(all(pts));
			pts.erase(unique(all(pts)), pts.end());
			build(1, 0, (int)pts.size() - 1);	
		}
	}

	void build(int v, int L, int R) {
		if (L == R) {
			t[v] = {pts[L].second};
		}
		else {
			int m = (L + R) >> 1;
			build(v * 2, L, m);
			build(v * 2 + 1, m + 1, R);
			merge(all(t[v * 2]), all(t[v * 2 + 1]), back_inserter(t[v]));
		}
	}

	int que(int lx, int rx, int ly, int ry, int v, int L, int R) {
		if (rx < pts[L].first || lx > pts[R].first)
			return 0;
		if (lx <= pts[L].first && pts[R].first <= rx) {
			return upper_bound(all(t[v]), ry) - lower_bound(all(t[v]), ly);
		}
		int m = (L + R) >> 1;
		return que(lx, rx, ly, ry, v * 2, L, m)
			+ que(lx, rx, ly, ry, v * 2 + 1, m + 1, R);
	}

	int que(int lx, int rx, int ly, int ry) {
		if (pts.empty())
			return 0;
		return que(lx, rx, ly, ry, 1, 0, pts.size() - 1);
	}

} teh, tev, tf, tv;

string dir = "NSEW";
const int dx[4] = {-1, 1, 0, 0},
		  dy[4] = {0, 0, 1, -1},
		  sdx[4] = {1, 1, 0, 0},
		  sdy[4] = {0, 1, 0, 1};

int r, c;
int mnx, mny, mxx, mxy;
set<pair<int, int>> st;

void init(int R, int C, int sr, int sc, int M, char *S) {
	r = R;
	c = C;

	mnx = sr;
	mxx = sr;
	mny = sc;
	mxy = sc;

	int x = sr, y = sc;
	st.insert({x, y});

	for (int i = 0; i < M; i++) {
		int k = find(all(dir), S[i]) - dir.begin();
		x += dx[k];
		y += dy[k];
		st.insert({x, y});

		mnx = min(mnx, x);
		mxx = max(mxx, x);
		mny = min(mny, y);
		mxy = max(mxy, y);
	}

	for (auto p : st) {
		tf.pts.push_back(p);
		tev.pts.push_back({p.first, p.second});
		tev.pts.push_back({p.first - 1, p.second});
		teh.pts.push_back({p.first, p.second});
		teh.pts.push_back({p.first, p.second - 1});

		for (int i = 0; i < 4; i++) {
			tv.pts.push_back({p.first - sdx[i], p.second - sdy[i]});
		}
	}

	tev.init();
	teh.init();
	tv.init();
	tf.init();
}

int colour(int ar, int ac, int br, int bc) {
	int ans = 1;

	if (ar < mnx && mxx < br &&
		ac < mny && mxy < bc) {
		ans++;
	}

	// ans = 0;
	ans += tev.que(ar, br - 1, ac, bc);
	ans += teh.que(ar, br, ac, bc - 1);
	ans -= tv.que(ar, br - 1, ac, bc - 1);
	ans -= tf.que(ar, br, ac, bc);

	// // count of edges

	// for (int i = ar; i < br; i++) {
	// 	for (int j = ac; j <= bc; j++) {
	// 		ans += (a[i][j] || a[i + 1][j]);
	// 	}
	// }

	// for (int i = ar; i <= br; i++) {
	// 	for (int j = ac; j < bc; j++) {
	// 		ans += (a[i][j + 1] || a[i][j]);
	// 	}
	// }

	// // count of vertices
	// for (int i = ar; i < br; i++) {
	// 	for (int j = ac; j < bc; j++) {
	// 		if (a[i][j] || a[i + 1][j] 
	// 			|| a[i][j + 1] || a[i + 1][j + 1])
	// 			ans--;
	// 	}
	// }

	// // count of useless
	// for (int i = ar; i <= br; i++) {
	// 	for (int j = ac; j <= bc; j++) {
	// 		ans -= a[i][j];
	// 	}
	// }
	
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 75640 KB Output is correct
2 Correct 89 ms 76156 KB Output is correct
3 Correct 76 ms 75748 KB Output is correct
4 Correct 75 ms 75640 KB Output is correct
5 Correct 82 ms 76280 KB Output is correct
6 Correct 73 ms 75512 KB Output is correct
7 Correct 83 ms 75512 KB Output is correct
8 Correct 75 ms 75484 KB Output is correct
9 Correct 82 ms 75512 KB Output is correct
10 Correct 82 ms 75512 KB Output is correct
11 Correct 77 ms 75768 KB Output is correct
12 Correct 80 ms 76024 KB Output is correct
13 Correct 93 ms 76536 KB Output is correct
14 Correct 84 ms 76764 KB Output is correct
15 Correct 75 ms 75512 KB Output is correct
16 Correct 80 ms 75428 KB Output is correct
17 Correct 74 ms 75512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 75428 KB Output is correct
2 Correct 74 ms 75512 KB Output is correct
3 Correct 513 ms 129800 KB Output is correct
4 Correct 723 ms 170836 KB Output is correct
5 Correct 720 ms 170628 KB Output is correct
6 Correct 604 ms 154820 KB Output is correct
7 Correct 620 ms 149336 KB Output is correct
8 Correct 153 ms 79196 KB Output is correct
9 Correct 724 ms 171024 KB Output is correct
10 Correct 733 ms 170584 KB Output is correct
11 Correct 628 ms 154616 KB Output is correct
12 Correct 670 ms 166344 KB Output is correct
13 Correct 595 ms 171056 KB Output is correct
14 Correct 638 ms 170268 KB Output is correct
15 Correct 558 ms 154820 KB Output is correct
16 Correct 580 ms 150668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 75512 KB Output is correct
2 Correct 475 ms 167344 KB Output is correct
3 Correct 444 ms 167428 KB Output is correct
4 Correct 480 ms 171808 KB Output is correct
5 Correct 345 ms 145732 KB Output is correct
6 Correct 151 ms 91864 KB Output is correct
7 Correct 226 ms 108932 KB Output is correct
8 Correct 420 ms 160320 KB Output is correct
9 Correct 396 ms 153368 KB Output is correct
10 Correct 153 ms 94168 KB Output is correct
11 Correct 264 ms 121492 KB Output is correct
12 Correct 460 ms 167428 KB Output is correct
13 Correct 451 ms 167552 KB Output is correct
14 Correct 466 ms 171908 KB Output is correct
15 Correct 351 ms 145860 KB Output is correct
16 Correct 143 ms 89696 KB Output is correct
17 Correct 222 ms 108868 KB Output is correct
18 Correct 471 ms 171952 KB Output is correct
19 Correct 469 ms 171940 KB Output is correct
20 Correct 459 ms 171800 KB Output is correct
21 Correct 432 ms 160476 KB Output is correct
22 Correct 403 ms 153216 KB Output is correct
23 Correct 154 ms 94176 KB Output is correct
24 Correct 265 ms 121484 KB Output is correct
25 Correct 441 ms 167428 KB Output is correct
26 Correct 432 ms 167508 KB Output is correct
27 Correct 468 ms 171776 KB Output is correct
28 Correct 472 ms 145988 KB Output is correct
29 Correct 142 ms 89696 KB Output is correct
30 Correct 226 ms 108856 KB Output is correct
31 Correct 459 ms 171992 KB Output is correct
32 Correct 463 ms 171780 KB Output is correct
33 Correct 462 ms 171780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 75640 KB Output is correct
2 Correct 89 ms 76156 KB Output is correct
3 Correct 76 ms 75748 KB Output is correct
4 Correct 75 ms 75640 KB Output is correct
5 Correct 82 ms 76280 KB Output is correct
6 Correct 73 ms 75512 KB Output is correct
7 Correct 83 ms 75512 KB Output is correct
8 Correct 75 ms 75484 KB Output is correct
9 Correct 82 ms 75512 KB Output is correct
10 Correct 82 ms 75512 KB Output is correct
11 Correct 77 ms 75768 KB Output is correct
12 Correct 80 ms 76024 KB Output is correct
13 Correct 93 ms 76536 KB Output is correct
14 Correct 84 ms 76764 KB Output is correct
15 Correct 75 ms 75512 KB Output is correct
16 Correct 80 ms 75428 KB Output is correct
17 Correct 74 ms 75512 KB Output is correct
18 Correct 1987 ms 124096 KB Output is correct
19 Correct 376 ms 81048 KB Output is correct
20 Correct 329 ms 79392 KB Output is correct
21 Correct 382 ms 79828 KB Output is correct
22 Correct 403 ms 79936 KB Output is correct
23 Correct 363 ms 81016 KB Output is correct
24 Correct 407 ms 79608 KB Output is correct
25 Correct 424 ms 79996 KB Output is correct
26 Correct 531 ms 80180 KB Output is correct
27 Correct 884 ms 118740 KB Output is correct
28 Correct 550 ms 95960 KB Output is correct
29 Correct 706 ms 112496 KB Output is correct
30 Correct 1500 ms 175448 KB Output is correct
31 Correct 76 ms 75640 KB Output is correct
32 Correct 1372 ms 118872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 75640 KB Output is correct
2 Correct 89 ms 76156 KB Output is correct
3 Correct 76 ms 75748 KB Output is correct
4 Correct 75 ms 75640 KB Output is correct
5 Correct 82 ms 76280 KB Output is correct
6 Correct 73 ms 75512 KB Output is correct
7 Correct 83 ms 75512 KB Output is correct
8 Correct 75 ms 75484 KB Output is correct
9 Correct 82 ms 75512 KB Output is correct
10 Correct 82 ms 75512 KB Output is correct
11 Correct 77 ms 75768 KB Output is correct
12 Correct 80 ms 76024 KB Output is correct
13 Correct 93 ms 76536 KB Output is correct
14 Correct 84 ms 76764 KB Output is correct
15 Correct 75 ms 75512 KB Output is correct
16 Correct 80 ms 75428 KB Output is correct
17 Correct 74 ms 75512 KB Output is correct
18 Correct 1987 ms 124096 KB Output is correct
19 Correct 376 ms 81048 KB Output is correct
20 Correct 329 ms 79392 KB Output is correct
21 Correct 382 ms 79828 KB Output is correct
22 Correct 403 ms 79936 KB Output is correct
23 Correct 363 ms 81016 KB Output is correct
24 Correct 407 ms 79608 KB Output is correct
25 Correct 424 ms 79996 KB Output is correct
26 Correct 531 ms 80180 KB Output is correct
27 Correct 884 ms 118740 KB Output is correct
28 Correct 550 ms 95960 KB Output is correct
29 Correct 706 ms 112496 KB Output is correct
30 Correct 1500 ms 175448 KB Output is correct
31 Correct 76 ms 75640 KB Output is correct
32 Correct 1372 ms 118872 KB Output is correct
33 Correct 475 ms 167344 KB Output is correct
34 Correct 444 ms 167428 KB Output is correct
35 Correct 480 ms 171808 KB Output is correct
36 Correct 345 ms 145732 KB Output is correct
37 Correct 151 ms 91864 KB Output is correct
38 Correct 226 ms 108932 KB Output is correct
39 Correct 420 ms 160320 KB Output is correct
40 Correct 396 ms 153368 KB Output is correct
41 Correct 153 ms 94168 KB Output is correct
42 Correct 264 ms 121492 KB Output is correct
43 Correct 460 ms 167428 KB Output is correct
44 Correct 451 ms 167552 KB Output is correct
45 Correct 466 ms 171908 KB Output is correct
46 Correct 351 ms 145860 KB Output is correct
47 Correct 143 ms 89696 KB Output is correct
48 Correct 222 ms 108868 KB Output is correct
49 Correct 471 ms 171952 KB Output is correct
50 Correct 469 ms 171940 KB Output is correct
51 Correct 459 ms 171800 KB Output is correct
52 Correct 432 ms 160476 KB Output is correct
53 Correct 403 ms 153216 KB Output is correct
54 Correct 154 ms 94176 KB Output is correct
55 Correct 265 ms 121484 KB Output is correct
56 Correct 441 ms 167428 KB Output is correct
57 Correct 432 ms 167508 KB Output is correct
58 Correct 468 ms 171776 KB Output is correct
59 Correct 472 ms 145988 KB Output is correct
60 Correct 142 ms 89696 KB Output is correct
61 Correct 226 ms 108856 KB Output is correct
62 Correct 459 ms 171992 KB Output is correct
63 Correct 463 ms 171780 KB Output is correct
64 Correct 462 ms 171780 KB Output is correct
65 Correct 990 ms 164012 KB Output is correct
66 Correct 1128 ms 157052 KB Output is correct
67 Correct 698 ms 97776 KB Output is correct
68 Correct 901 ms 125060 KB Output is correct
69 Correct 572 ms 171056 KB Output is correct
70 Correct 1127 ms 171124 KB Output is correct
71 Correct 742 ms 175568 KB Output is correct
72 Correct 674 ms 149316 KB Output is correct
73 Correct 237 ms 93152 KB Output is correct
74 Correct 309 ms 112596 KB Output is correct
75 Correct 571 ms 175496 KB Output is correct
76 Correct 928 ms 175524 KB Output is correct
77 Correct 1008 ms 175264 KB Output is correct
78 Correct 513 ms 129800 KB Output is correct
79 Correct 723 ms 170836 KB Output is correct
80 Correct 720 ms 170628 KB Output is correct
81 Correct 604 ms 154820 KB Output is correct
82 Correct 620 ms 149336 KB Output is correct
83 Correct 153 ms 79196 KB Output is correct
84 Correct 724 ms 171024 KB Output is correct
85 Correct 733 ms 170584 KB Output is correct
86 Correct 628 ms 154616 KB Output is correct
87 Correct 670 ms 166344 KB Output is correct
88 Correct 595 ms 171056 KB Output is correct
89 Correct 638 ms 170268 KB Output is correct
90 Correct 558 ms 154820 KB Output is correct
91 Correct 580 ms 150668 KB Output is correct