답안 #732456

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
732456 2023-04-29T04:30:50 Z SanguineChameleon 무지개나라 (APIO17_rainbow) C++17
100 / 100
828 ms 85120 KB
#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;

struct BIT {
	set<pair<int, int>> S;
	vector<vector<int>> bit;
	int R, C;

	void init(int _R, int _C) {
		R = _R;
		C = _C;
		bit.resize(R + 1);
	}

	void add(int x, int y) {
		if (x < 1 || x > R || y < 1 || y > C || S.find({x, y}) != S.end()) {
			return;
		}
		S.insert({x, y});
		for (int i = x; i <= R; i += i & (-i)) {
			bit[i].emplace_back(y);
		}
	}

	void build() {
		for (int i = 1; i <= R; i++) {
			sort(bit[i].begin(), bit[i].end());
		}
	}

	int get(int x, int y) {
		int res = 0;
		for (int i = x; i > 0; i -= i & (-i)) {
			res += upper_bound(bit[i].begin(), bit[i].end(), y) - bit[i].begin();
		}
		return res;
	}

	long long get(int lx, int ly, int rx, int ry) {
		return 1LL * (rx - lx + 1) * (ry - ly + 1) - get(rx, ry) + get(rx, ly - 1) + get(lx - 1, ry) - get(lx - 1, ly - 1);
	}

} V, row_E, col_E, F;

int max_X, min_X, max_Y, min_Y;

void add(int cx, int cy) {
	max_X = max(max_X, cx);
	min_X = min(min_X, cx);
	max_Y = max(max_Y, cy);
	min_Y = min(min_Y, cy);
	V.add(cx, cy);
	row_E.add(cx - 1, cy);
	row_E.add(cx, cy);
	col_E.add(cx, cy - 1);
	col_E.add(cx, cy);
	F.add(cx - 1, cy - 1);
	F.add(cx - 1, cy);
	F.add(cx, cy - 1);
	F.add(cx, cy);
}

void init(int R, int C, int cx, int cy, int M, char *S) {
	V.init(R, C);
	row_E.init(R, C);
	col_E.init(R, C);
	F.init(R, C);
	max_X = cx;
	min_X = cx;
	max_Y = cy;
	min_Y = cy;
	add(cx, cy);
	for (int i = 0; i < M; i++) {
		if (S[i] == 'N') {
			cx--;
		}
		if (S[i] == 'E') {
			cy++;
		}
		if (S[i] == 'S') {
			cx++;
		}
		if (S[i] == 'W') {
			cy--;
		}
		add(cx, cy);
	}
	V.build();
	row_E.build();
	col_E.build();
	F.build();
}

int colour(int lx, int ly, int rx, int ry) {
	return V.get(lx, ly, rx, ry) - row_E.get(lx, ly, rx - 1, ry) - col_E.get(lx, ly, rx, ry - 1) + F.get(lx, ly, rx - 1, ry - 1) + (lx < min_X && max_X < rx && ly < min_Y && max_Y < ry);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 4 ms 596 KB Output is correct
3 Correct 2 ms 392 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 6 ms 596 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 5 ms 724 KB Output is correct
14 Correct 7 ms 852 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 213 ms 17232 KB Output is correct
4 Correct 291 ms 27588 KB Output is correct
5 Correct 319 ms 27132 KB Output is correct
6 Correct 247 ms 20556 KB Output is correct
7 Correct 259 ms 19632 KB Output is correct
8 Correct 55 ms 976 KB Output is correct
9 Correct 334 ms 27444 KB Output is correct
10 Correct 288 ms 27140 KB Output is correct
11 Correct 248 ms 20564 KB Output is correct
12 Correct 253 ms 26776 KB Output is correct
13 Correct 231 ms 27540 KB Output is correct
14 Correct 238 ms 27148 KB Output is correct
15 Correct 209 ms 20648 KB Output is correct
16 Correct 220 ms 18676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 391 ms 67416 KB Output is correct
3 Correct 403 ms 77684 KB Output is correct
4 Correct 393 ms 77496 KB Output is correct
5 Correct 323 ms 61420 KB Output is correct
6 Correct 146 ms 29652 KB Output is correct
7 Correct 218 ms 37484 KB Output is correct
8 Correct 232 ms 25388 KB Output is correct
9 Correct 233 ms 23896 KB Output is correct
10 Correct 89 ms 16868 KB Output is correct
11 Correct 173 ms 27932 KB Output is correct
12 Correct 388 ms 67332 KB Output is correct
13 Correct 377 ms 77740 KB Output is correct
14 Correct 392 ms 77432 KB Output is correct
15 Correct 318 ms 61408 KB Output is correct
16 Correct 124 ms 27616 KB Output is correct
17 Correct 233 ms 41120 KB Output is correct
18 Correct 539 ms 81576 KB Output is correct
19 Correct 338 ms 67424 KB Output is correct
20 Correct 361 ms 70012 KB Output is correct
21 Correct 217 ms 25364 KB Output is correct
22 Correct 246 ms 24032 KB Output is correct
23 Correct 96 ms 17020 KB Output is correct
24 Correct 186 ms 27852 KB Output is correct
25 Correct 388 ms 67336 KB Output is correct
26 Correct 381 ms 77804 KB Output is correct
27 Correct 394 ms 77404 KB Output is correct
28 Correct 324 ms 61480 KB Output is correct
29 Correct 125 ms 27676 KB Output is correct
30 Correct 233 ms 41088 KB Output is correct
31 Correct 546 ms 81488 KB Output is correct
32 Correct 344 ms 67588 KB Output is correct
33 Correct 359 ms 69804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 4 ms 596 KB Output is correct
3 Correct 2 ms 392 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 6 ms 596 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 5 ms 724 KB Output is correct
14 Correct 7 ms 852 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 821 ms 22664 KB Output is correct
19 Correct 232 ms 1868 KB Output is correct
20 Correct 175 ms 1132 KB Output is correct
21 Correct 201 ms 1352 KB Output is correct
22 Correct 217 ms 1612 KB Output is correct
23 Correct 213 ms 1884 KB Output is correct
24 Correct 216 ms 1172 KB Output is correct
25 Correct 233 ms 1408 KB Output is correct
26 Correct 241 ms 1728 KB Output is correct
27 Correct 370 ms 17612 KB Output is correct
28 Correct 318 ms 9536 KB Output is correct
29 Correct 350 ms 16124 KB Output is correct
30 Correct 828 ms 44544 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 635 ms 18892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 4 ms 596 KB Output is correct
3 Correct 2 ms 392 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 6 ms 596 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 5 ms 724 KB Output is correct
14 Correct 7 ms 852 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 821 ms 22664 KB Output is correct
19 Correct 232 ms 1868 KB Output is correct
20 Correct 175 ms 1132 KB Output is correct
21 Correct 201 ms 1352 KB Output is correct
22 Correct 217 ms 1612 KB Output is correct
23 Correct 213 ms 1884 KB Output is correct
24 Correct 216 ms 1172 KB Output is correct
25 Correct 233 ms 1408 KB Output is correct
26 Correct 241 ms 1728 KB Output is correct
27 Correct 370 ms 17612 KB Output is correct
28 Correct 318 ms 9536 KB Output is correct
29 Correct 350 ms 16124 KB Output is correct
30 Correct 828 ms 44544 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 635 ms 18892 KB Output is correct
33 Correct 391 ms 67416 KB Output is correct
34 Correct 403 ms 77684 KB Output is correct
35 Correct 393 ms 77496 KB Output is correct
36 Correct 323 ms 61420 KB Output is correct
37 Correct 146 ms 29652 KB Output is correct
38 Correct 218 ms 37484 KB Output is correct
39 Correct 232 ms 25388 KB Output is correct
40 Correct 233 ms 23896 KB Output is correct
41 Correct 89 ms 16868 KB Output is correct
42 Correct 173 ms 27932 KB Output is correct
43 Correct 388 ms 67332 KB Output is correct
44 Correct 377 ms 77740 KB Output is correct
45 Correct 392 ms 77432 KB Output is correct
46 Correct 318 ms 61408 KB Output is correct
47 Correct 124 ms 27616 KB Output is correct
48 Correct 233 ms 41120 KB Output is correct
49 Correct 539 ms 81576 KB Output is correct
50 Correct 338 ms 67424 KB Output is correct
51 Correct 361 ms 70012 KB Output is correct
52 Correct 217 ms 25364 KB Output is correct
53 Correct 246 ms 24032 KB Output is correct
54 Correct 96 ms 17020 KB Output is correct
55 Correct 186 ms 27852 KB Output is correct
56 Correct 388 ms 67336 KB Output is correct
57 Correct 381 ms 77804 KB Output is correct
58 Correct 394 ms 77404 KB Output is correct
59 Correct 324 ms 61480 KB Output is correct
60 Correct 125 ms 27676 KB Output is correct
61 Correct 233 ms 41088 KB Output is correct
62 Correct 546 ms 81488 KB Output is correct
63 Correct 344 ms 67588 KB Output is correct
64 Correct 359 ms 69804 KB Output is correct
65 Correct 213 ms 17232 KB Output is correct
66 Correct 291 ms 27588 KB Output is correct
67 Correct 319 ms 27132 KB Output is correct
68 Correct 247 ms 20556 KB Output is correct
69 Correct 259 ms 19632 KB Output is correct
70 Correct 55 ms 976 KB Output is correct
71 Correct 334 ms 27444 KB Output is correct
72 Correct 288 ms 27140 KB Output is correct
73 Correct 248 ms 20564 KB Output is correct
74 Correct 253 ms 26776 KB Output is correct
75 Correct 231 ms 27540 KB Output is correct
76 Correct 238 ms 27148 KB Output is correct
77 Correct 209 ms 20648 KB Output is correct
78 Correct 220 ms 18676 KB Output is correct
79 Correct 510 ms 26084 KB Output is correct
80 Correct 611 ms 24712 KB Output is correct
81 Correct 411 ms 17468 KB Output is correct
82 Correct 526 ms 28500 KB Output is correct
83 Correct 644 ms 68232 KB Output is correct
84 Correct 800 ms 78636 KB Output is correct
85 Correct 705 ms 78752 KB Output is correct
86 Correct 599 ms 64968 KB Output is correct
87 Correct 287 ms 31212 KB Output is correct
88 Correct 411 ms 44700 KB Output is correct
89 Correct 732 ms 85120 KB Output is correct
90 Correct 716 ms 71188 KB Output is correct
91 Correct 620 ms 73396 KB Output is correct