답안 #884572

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
884572 2023-12-07T17:09:43 Z 272hnixihom 무지개나라 (APIO17_rainbow) C++14
100 / 100
903 ms 206116 KB
#include "rainbow.h"
#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
using namespace std;

const int MAXN = 2e5, MAXSEG = (6e5 + 9) * 19 + 1;

int cnt = 1, segtree[MAXSEG], left_c[MAXSEG], right_c[MAXSEG];

struct Segtree {
	set<int> data[MAXN + 1];
	int roots[MAXN + 2];

	void add(int x, int y) { data[x].insert(y); }

	void build() {
		FOR(i, 1, MAXN + 1) {
			roots[i + 1] = roots[i];
			for (int j : data[i]) update(j, roots[i + 1]);
		}
	}

	void update(int pos, int &node, int l = 1, int r = MAXN) {
		segtree[cnt] = segtree[node] + 1;
		left_c[cnt] = left_c[node];
		right_c[cnt] = right_c[node];
		node = cnt++;

		if (l == r) return;
		int mid = (l + r) / 2;
		if (pos > mid) update(pos, right_c[node], mid + 1, r);
		else update(pos, left_c[node], l, mid);
	}

	int query(int l1, int r1, int l2, int r2) {
		if (l2 > r2) return 0;
		return query(l2, r2, roots[r1 + 1], 1, MAXN) -
		       query(l2, r2, roots[l1], 1, MAXN);
	}
	int query(int a, int b, int node, int l, int r) {
		if (a > r || b < l) return 0;
		if (a <= l && b >= r) return segtree[node];
		int mid = (l + r) / 2;
		return query(a, b, left_c[node], l, mid) +
		       query(a, b, right_c[node], mid + 1, r);
	}
} vertices, edges_horiz, edges_vert, rivers;

int mx_r, mn_r, mx_c, mn_c;

void add_river(int x, int y) {
	vertices.add(x, y);
	vertices.add(x + 1, y);
	vertices.add(x, y + 1);
	vertices.add(x + 1, y + 1);
	edges_horiz.add(x, y);
	edges_horiz.add(x + 1, y);
	edges_vert.add(x, y);
	edges_vert.add(x, y + 1);
	rivers.add(x, y);
}

void init(int R, int C, int sr, int sc, int M, char *S) {
	add_river(sr, sc);
	mx_r = mn_r = sr;
	mx_c = mn_c = sc;
	FOR(i, 0, M) {
		if (S[i] == 'N') sr--;
		if (S[i] == 'E') sc++;
		if (S[i] == 'S') sr++;
		if (S[i] == 'W') sc--;
		add_river(sr, sc);
		mx_r = max(mx_r, sr);
		mn_r = min(mn_r, sr);
		mx_c = max(mx_c, sc);
		mn_c = min(mn_c, sc);
	}
	vertices.build();
	edges_horiz.build();
	edges_vert.build();
	rivers.build();
}

int colour(int ar, int ac, int br, int bc) {
	int E = edges_horiz.query(ar + 1, br, ac, bc) +
	        edges_vert.query(ar, br, ac + 1, bc);
	int V = vertices.query(ar + 1, br, ac + 1, bc);
	int R = rivers.query(ar, br, ac, bc);
	int C = (ar >= mn_r || br <= mx_r || ac >= mn_c || bc <= mx_c ? 1 : 2);
	return E - V + C - R;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 43864 KB Output is correct
2 Correct 16 ms 44636 KB Output is correct
3 Correct 15 ms 43868 KB Output is correct
4 Correct 13 ms 43868 KB Output is correct
5 Correct 14 ms 44876 KB Output is correct
6 Correct 11 ms 43608 KB Output is correct
7 Correct 10 ms 41560 KB Output is correct
8 Correct 11 ms 43612 KB Output is correct
9 Correct 11 ms 43728 KB Output is correct
10 Correct 12 ms 43612 KB Output is correct
11 Correct 13 ms 43868 KB Output is correct
12 Correct 13 ms 44376 KB Output is correct
13 Correct 15 ms 47132 KB Output is correct
14 Correct 15 ms 47452 KB Output is correct
15 Correct 10 ms 41436 KB Output is correct
16 Correct 11 ms 43612 KB Output is correct
17 Correct 11 ms 41564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 43612 KB Output is correct
2 Correct 11 ms 41564 KB Output is correct
3 Correct 489 ms 144852 KB Output is correct
4 Correct 629 ms 205492 KB Output is correct
5 Correct 625 ms 204956 KB Output is correct
6 Correct 527 ms 171836 KB Output is correct
7 Correct 605 ms 169328 KB Output is correct
8 Correct 234 ms 47188 KB Output is correct
9 Correct 624 ms 205500 KB Output is correct
10 Correct 637 ms 204904 KB Output is correct
11 Correct 606 ms 171928 KB Output is correct
12 Correct 300 ms 198996 KB Output is correct
13 Correct 306 ms 205560 KB Output is correct
14 Correct 318 ms 205152 KB Output is correct
15 Correct 301 ms 172192 KB Output is correct
16 Correct 501 ms 161876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 41436 KB Output is correct
2 Correct 265 ms 202100 KB Output is correct
3 Correct 104 ms 201812 KB Output is correct
4 Correct 130 ms 202116 KB Output is correct
5 Correct 115 ms 165876 KB Output is correct
6 Correct 64 ms 76584 KB Output is correct
7 Correct 111 ms 106068 KB Output is correct
8 Correct 216 ms 188556 KB Output is correct
9 Correct 211 ms 173408 KB Output is correct
10 Correct 74 ms 76488 KB Output is correct
11 Correct 125 ms 123868 KB Output is correct
12 Correct 279 ms 201948 KB Output is correct
13 Correct 104 ms 201844 KB Output is correct
14 Correct 130 ms 202104 KB Output is correct
15 Correct 115 ms 165996 KB Output is correct
16 Correct 56 ms 68944 KB Output is correct
17 Correct 109 ms 106396 KB Output is correct
18 Correct 192 ms 202064 KB Output is correct
19 Correct 179 ms 202472 KB Output is correct
20 Correct 183 ms 202344 KB Output is correct
21 Correct 219 ms 188428 KB Output is correct
22 Correct 205 ms 173396 KB Output is correct
23 Correct 69 ms 76796 KB Output is correct
24 Correct 149 ms 123728 KB Output is correct
25 Correct 259 ms 202136 KB Output is correct
26 Correct 96 ms 201808 KB Output is correct
27 Correct 129 ms 202244 KB Output is correct
28 Correct 115 ms 165948 KB Output is correct
29 Correct 63 ms 68944 KB Output is correct
30 Correct 117 ms 105984 KB Output is correct
31 Correct 187 ms 202016 KB Output is correct
32 Correct 173 ms 202576 KB Output is correct
33 Correct 196 ms 202424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 43864 KB Output is correct
2 Correct 16 ms 44636 KB Output is correct
3 Correct 15 ms 43868 KB Output is correct
4 Correct 13 ms 43868 KB Output is correct
5 Correct 14 ms 44876 KB Output is correct
6 Correct 11 ms 43608 KB Output is correct
7 Correct 10 ms 41560 KB Output is correct
8 Correct 11 ms 43612 KB Output is correct
9 Correct 11 ms 43728 KB Output is correct
10 Correct 12 ms 43612 KB Output is correct
11 Correct 13 ms 43868 KB Output is correct
12 Correct 13 ms 44376 KB Output is correct
13 Correct 15 ms 47132 KB Output is correct
14 Correct 15 ms 47452 KB Output is correct
15 Correct 10 ms 41436 KB Output is correct
16 Correct 11 ms 43612 KB Output is correct
17 Correct 11 ms 41564 KB Output is correct
18 Correct 615 ms 131920 KB Output is correct
19 Correct 191 ms 51792 KB Output is correct
20 Correct 142 ms 47560 KB Output is correct
21 Correct 152 ms 47916 KB Output is correct
22 Correct 164 ms 50516 KB Output is correct
23 Correct 182 ms 51512 KB Output is correct
24 Correct 151 ms 47696 KB Output is correct
25 Correct 163 ms 48624 KB Output is correct
26 Correct 192 ms 50772 KB Output is correct
27 Correct 312 ms 114512 KB Output is correct
28 Correct 242 ms 79988 KB Output is correct
29 Correct 301 ms 109424 KB Output is correct
30 Correct 495 ms 205356 KB Output is correct
31 Correct 13 ms 43760 KB Output is correct
32 Correct 462 ms 117028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 43864 KB Output is correct
2 Correct 16 ms 44636 KB Output is correct
3 Correct 15 ms 43868 KB Output is correct
4 Correct 13 ms 43868 KB Output is correct
5 Correct 14 ms 44876 KB Output is correct
6 Correct 11 ms 43608 KB Output is correct
7 Correct 10 ms 41560 KB Output is correct
8 Correct 11 ms 43612 KB Output is correct
9 Correct 11 ms 43728 KB Output is correct
10 Correct 12 ms 43612 KB Output is correct
11 Correct 13 ms 43868 KB Output is correct
12 Correct 13 ms 44376 KB Output is correct
13 Correct 15 ms 47132 KB Output is correct
14 Correct 15 ms 47452 KB Output is correct
15 Correct 10 ms 41436 KB Output is correct
16 Correct 11 ms 43612 KB Output is correct
17 Correct 11 ms 41564 KB Output is correct
18 Correct 615 ms 131920 KB Output is correct
19 Correct 191 ms 51792 KB Output is correct
20 Correct 142 ms 47560 KB Output is correct
21 Correct 152 ms 47916 KB Output is correct
22 Correct 164 ms 50516 KB Output is correct
23 Correct 182 ms 51512 KB Output is correct
24 Correct 151 ms 47696 KB Output is correct
25 Correct 163 ms 48624 KB Output is correct
26 Correct 192 ms 50772 KB Output is correct
27 Correct 312 ms 114512 KB Output is correct
28 Correct 242 ms 79988 KB Output is correct
29 Correct 301 ms 109424 KB Output is correct
30 Correct 495 ms 205356 KB Output is correct
31 Correct 13 ms 43760 KB Output is correct
32 Correct 462 ms 117028 KB Output is correct
33 Correct 265 ms 202100 KB Output is correct
34 Correct 104 ms 201812 KB Output is correct
35 Correct 130 ms 202116 KB Output is correct
36 Correct 115 ms 165876 KB Output is correct
37 Correct 64 ms 76584 KB Output is correct
38 Correct 111 ms 106068 KB Output is correct
39 Correct 216 ms 188556 KB Output is correct
40 Correct 211 ms 173408 KB Output is correct
41 Correct 74 ms 76488 KB Output is correct
42 Correct 125 ms 123868 KB Output is correct
43 Correct 279 ms 201948 KB Output is correct
44 Correct 104 ms 201844 KB Output is correct
45 Correct 130 ms 202104 KB Output is correct
46 Correct 115 ms 165996 KB Output is correct
47 Correct 56 ms 68944 KB Output is correct
48 Correct 109 ms 106396 KB Output is correct
49 Correct 192 ms 202064 KB Output is correct
50 Correct 179 ms 202472 KB Output is correct
51 Correct 183 ms 202344 KB Output is correct
52 Correct 219 ms 188428 KB Output is correct
53 Correct 205 ms 173396 KB Output is correct
54 Correct 69 ms 76796 KB Output is correct
55 Correct 149 ms 123728 KB Output is correct
56 Correct 259 ms 202136 KB Output is correct
57 Correct 96 ms 201808 KB Output is correct
58 Correct 129 ms 202244 KB Output is correct
59 Correct 115 ms 165948 KB Output is correct
60 Correct 63 ms 68944 KB Output is correct
61 Correct 117 ms 105984 KB Output is correct
62 Correct 187 ms 202016 KB Output is correct
63 Correct 173 ms 202576 KB Output is correct
64 Correct 196 ms 202424 KB Output is correct
65 Correct 489 ms 144852 KB Output is correct
66 Correct 629 ms 205492 KB Output is correct
67 Correct 625 ms 204956 KB Output is correct
68 Correct 527 ms 171836 KB Output is correct
69 Correct 605 ms 169328 KB Output is correct
70 Correct 234 ms 47188 KB Output is correct
71 Correct 624 ms 205500 KB Output is correct
72 Correct 637 ms 204904 KB Output is correct
73 Correct 606 ms 171928 KB Output is correct
74 Correct 300 ms 198996 KB Output is correct
75 Correct 306 ms 205560 KB Output is correct
76 Correct 318 ms 205152 KB Output is correct
77 Correct 301 ms 172192 KB Output is correct
78 Correct 501 ms 161876 KB Output is correct
79 Correct 903 ms 191832 KB Output is correct
80 Correct 846 ms 176716 KB Output is correct
81 Correct 335 ms 80212 KB Output is correct
82 Correct 393 ms 127060 KB Output is correct
83 Correct 640 ms 205592 KB Output is correct
84 Correct 376 ms 205140 KB Output is correct
85 Correct 420 ms 205648 KB Output is correct
86 Correct 417 ms 169372 KB Output is correct
87 Correct 284 ms 72652 KB Output is correct
88 Correct 357 ms 109688 KB Output is correct
89 Correct 437 ms 205624 KB Output is correct
90 Correct 530 ms 206116 KB Output is correct
91 Correct 429 ms 205972 KB Output is correct