#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;
struct SegmentTree {
int n;
vector<vector<int>> t;
SegmentTree() { }
SegmentTree(int _n) {
n = _n;
t.resize(4 * n);
}
void insert(int x, int lx, int rx, int px, int py) {
if (lx == rx) {
t[x].push_back(py);
return;
}
int mx = (lx + rx) >> 1;
if (px <= mx) insert(x << 1, lx, mx, px, py);
else insert(x << 1 | 1, mx + 1, rx, px, py);
}
void build(int x, int lx, int rx) {
if (lx == rx) {
sort(t[x].begin(), t[x].end());
t[x].erase(unique(t[x].begin(), t[x].end()), t[x].end());
return;
}
int mx = (lx + rx) >> 1;
build(x << 1, lx, mx);
build(x << 1 | 1, mx + 1, rx);
merge(t[x << 1].begin(), t[x << 1].end(), t[x << 1 | 1].begin(), t[x << 1 | 1].end(), back_inserter(t[x]));
}
int sum(int x, int lx, int rx, int xl, int xr, int yl, int yr) {
if (xl > xr || yl > yr) return 0;
if (lx > xr || xl > rx) return 0;
if (xl <= lx && xr >= rx) return upper_bound(t[x].begin(), t[x].end(), yr) - lower_bound(t[x].begin(), t[x].end(), yl);
int mx = (lx + rx) >> 1;
return sum(x << 1, lx, mx, xl, xr, yl, yr) + sum(x << 1 | 1, mx + 1, rx, xl, xr, yl, yr);
}
};
int mxc, mxr, mnc, mnr;
SegmentTree point, edger, edged, f;
int N;
vector<pair<int, int>> all;
void init(int R, int C, int sr, int sc, int M, char *S) {
N = R + 5;
all = {{sr, sc}};
mxr = mnr = sr;
mxc = mnc = sc;
for (int i = 0; i < M; i++) {
if (S[i] == 'E') sc++;
if (S[i] == 'W') sc--;
if (S[i] == 'N') sr--;
if (S[i] == 'S') sr++;
all.push_back({sr, sc});
mxr = max(mxr, sr);
mnr = min(mnr, sr);
mxc = max(mxc, sc);
mnc = min(mnc, sc);
}
sort(all.begin(), all.end());
all.erase(unique(all.begin(), all.end()), all.end());
point = edger = edged = f = SegmentTree(N);
for (auto [x, y] : all) {
f.insert(1, 1, N, x, y);
edger.insert(1, 1, N, x, y);
edger.insert(1, 1, N, x + 1, y);
edged.insert(1, 1, N, x, y);
edged.insert(1, 1, N, x, y + 1);
point.insert(1, 1, N, x, y);
point.insert(1, 1, N, x + 1, y);
point.insert(1, 1, N, x, y + 1);
point.insert(1, 1, N, x + 1, y + 1);
}
point.build(1, 1, N);
edger.build(1, 1, N);
edged.build(1, 1, N);
f.build(1, 1, N);
}
int colour(int ar, int ac, int br, int bc) {
int X = 2 * (br - ar + bc - ac + 6);
int nodes = 2 * X - 8 + point.sum(1, 1, N, ar + 1, br, ac + 1, bc);
int edges = edger.sum(1, 1, N, ar + 1, br, ac, bc) + edged.sum(1, 1, N, ar, br, ac + 1, bc);
edges += 3 * X - 12;
int comp = 1;
if (ar < mnr && mxr < br && ac < mnc && mxc < bc) comp++;
int bad_faces = X - 4 + f.sum(1, 1, N, ar, br, ac, bc);
return edges - nodes + comp - bad_faces;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
456 KB |
Output is correct |
2 |
Correct |
3 ms |
604 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
448 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
516 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
680 KB |
Output is correct |
13 |
Correct |
4 ms |
604 KB |
Output is correct |
14 |
Correct |
3 ms |
860 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
440 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
440 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
96 ms |
11432 KB |
Output is correct |
4 |
Correct |
125 ms |
16264 KB |
Output is correct |
5 |
Correct |
149 ms |
16320 KB |
Output is correct |
6 |
Correct |
117 ms |
14648 KB |
Output is correct |
7 |
Correct |
132 ms |
13688 KB |
Output is correct |
8 |
Correct |
55 ms |
4556 KB |
Output is correct |
9 |
Correct |
136 ms |
16244 KB |
Output is correct |
10 |
Correct |
138 ms |
16184 KB |
Output is correct |
11 |
Correct |
127 ms |
14716 KB |
Output is correct |
12 |
Correct |
91 ms |
15616 KB |
Output is correct |
13 |
Correct |
90 ms |
16192 KB |
Output is correct |
14 |
Correct |
86 ms |
16244 KB |
Output is correct |
15 |
Correct |
90 ms |
14736 KB |
Output is correct |
16 |
Correct |
95 ms |
13092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
98 ms |
122640 KB |
Output is correct |
3 |
Correct |
227 ms |
146112 KB |
Output is correct |
4 |
Correct |
176 ms |
141080 KB |
Output is correct |
5 |
Correct |
147 ms |
123548 KB |
Output is correct |
6 |
Correct |
67 ms |
86900 KB |
Output is correct |
7 |
Correct |
73 ms |
96928 KB |
Output is correct |
8 |
Correct |
40 ms |
14796 KB |
Output is correct |
9 |
Correct |
49 ms |
13512 KB |
Output is correct |
10 |
Correct |
38 ms |
48076 KB |
Output is correct |
11 |
Correct |
57 ms |
62616 KB |
Output is correct |
12 |
Correct |
98 ms |
122712 KB |
Output is correct |
13 |
Correct |
252 ms |
146156 KB |
Output is correct |
14 |
Correct |
192 ms |
141024 KB |
Output is correct |
15 |
Correct |
150 ms |
123592 KB |
Output is correct |
16 |
Correct |
54 ms |
84680 KB |
Output is correct |
17 |
Correct |
74 ms |
97508 KB |
Output is correct |
18 |
Correct |
107 ms |
128696 KB |
Output is correct |
19 |
Correct |
156 ms |
134924 KB |
Output is correct |
20 |
Correct |
161 ms |
134904 KB |
Output is correct |
21 |
Correct |
40 ms |
14612 KB |
Output is correct |
22 |
Correct |
37 ms |
13512 KB |
Output is correct |
23 |
Correct |
36 ms |
48016 KB |
Output is correct |
24 |
Correct |
61 ms |
62796 KB |
Output is correct |
25 |
Correct |
91 ms |
122636 KB |
Output is correct |
26 |
Correct |
213 ms |
146264 KB |
Output is correct |
27 |
Correct |
174 ms |
141012 KB |
Output is correct |
28 |
Correct |
141 ms |
123484 KB |
Output is correct |
29 |
Correct |
61 ms |
84676 KB |
Output is correct |
30 |
Correct |
76 ms |
97284 KB |
Output is correct |
31 |
Correct |
108 ms |
128600 KB |
Output is correct |
32 |
Correct |
173 ms |
134856 KB |
Output is correct |
33 |
Correct |
157 ms |
135044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
456 KB |
Output is correct |
2 |
Correct |
3 ms |
604 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
448 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
516 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
680 KB |
Output is correct |
13 |
Correct |
4 ms |
604 KB |
Output is correct |
14 |
Correct |
3 ms |
860 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
440 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
584 ms |
22516 KB |
Output is correct |
19 |
Correct |
131 ms |
4464 KB |
Output is correct |
20 |
Correct |
122 ms |
4148 KB |
Output is correct |
21 |
Correct |
123 ms |
4136 KB |
Output is correct |
22 |
Correct |
140 ms |
4216 KB |
Output is correct |
23 |
Correct |
111 ms |
4436 KB |
Output is correct |
24 |
Correct |
175 ms |
3936 KB |
Output is correct |
25 |
Correct |
155 ms |
4512 KB |
Output is correct |
26 |
Correct |
151 ms |
4432 KB |
Output is correct |
27 |
Correct |
233 ms |
19556 KB |
Output is correct |
28 |
Correct |
249 ms |
12316 KB |
Output is correct |
29 |
Correct |
268 ms |
18588 KB |
Output is correct |
30 |
Correct |
434 ms |
37684 KB |
Output is correct |
31 |
Correct |
2 ms |
348 KB |
Output is correct |
32 |
Correct |
424 ms |
19588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
456 KB |
Output is correct |
2 |
Correct |
3 ms |
604 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
448 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
516 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
680 KB |
Output is correct |
13 |
Correct |
4 ms |
604 KB |
Output is correct |
14 |
Correct |
3 ms |
860 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
440 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
584 ms |
22516 KB |
Output is correct |
19 |
Correct |
131 ms |
4464 KB |
Output is correct |
20 |
Correct |
122 ms |
4148 KB |
Output is correct |
21 |
Correct |
123 ms |
4136 KB |
Output is correct |
22 |
Correct |
140 ms |
4216 KB |
Output is correct |
23 |
Correct |
111 ms |
4436 KB |
Output is correct |
24 |
Correct |
175 ms |
3936 KB |
Output is correct |
25 |
Correct |
155 ms |
4512 KB |
Output is correct |
26 |
Correct |
151 ms |
4432 KB |
Output is correct |
27 |
Correct |
233 ms |
19556 KB |
Output is correct |
28 |
Correct |
249 ms |
12316 KB |
Output is correct |
29 |
Correct |
268 ms |
18588 KB |
Output is correct |
30 |
Correct |
434 ms |
37684 KB |
Output is correct |
31 |
Correct |
2 ms |
348 KB |
Output is correct |
32 |
Correct |
424 ms |
19588 KB |
Output is correct |
33 |
Correct |
98 ms |
122640 KB |
Output is correct |
34 |
Correct |
227 ms |
146112 KB |
Output is correct |
35 |
Correct |
176 ms |
141080 KB |
Output is correct |
36 |
Correct |
147 ms |
123548 KB |
Output is correct |
37 |
Correct |
67 ms |
86900 KB |
Output is correct |
38 |
Correct |
73 ms |
96928 KB |
Output is correct |
39 |
Correct |
40 ms |
14796 KB |
Output is correct |
40 |
Correct |
49 ms |
13512 KB |
Output is correct |
41 |
Correct |
38 ms |
48076 KB |
Output is correct |
42 |
Correct |
57 ms |
62616 KB |
Output is correct |
43 |
Correct |
98 ms |
122712 KB |
Output is correct |
44 |
Correct |
252 ms |
146156 KB |
Output is correct |
45 |
Correct |
192 ms |
141024 KB |
Output is correct |
46 |
Correct |
150 ms |
123592 KB |
Output is correct |
47 |
Correct |
54 ms |
84680 KB |
Output is correct |
48 |
Correct |
74 ms |
97508 KB |
Output is correct |
49 |
Correct |
107 ms |
128696 KB |
Output is correct |
50 |
Correct |
156 ms |
134924 KB |
Output is correct |
51 |
Correct |
161 ms |
134904 KB |
Output is correct |
52 |
Correct |
40 ms |
14612 KB |
Output is correct |
53 |
Correct |
37 ms |
13512 KB |
Output is correct |
54 |
Correct |
36 ms |
48016 KB |
Output is correct |
55 |
Correct |
61 ms |
62796 KB |
Output is correct |
56 |
Correct |
91 ms |
122636 KB |
Output is correct |
57 |
Correct |
213 ms |
146264 KB |
Output is correct |
58 |
Correct |
174 ms |
141012 KB |
Output is correct |
59 |
Correct |
141 ms |
123484 KB |
Output is correct |
60 |
Correct |
61 ms |
84676 KB |
Output is correct |
61 |
Correct |
76 ms |
97284 KB |
Output is correct |
62 |
Correct |
108 ms |
128600 KB |
Output is correct |
63 |
Correct |
173 ms |
134856 KB |
Output is correct |
64 |
Correct |
157 ms |
135044 KB |
Output is correct |
65 |
Correct |
96 ms |
11432 KB |
Output is correct |
66 |
Correct |
125 ms |
16264 KB |
Output is correct |
67 |
Correct |
149 ms |
16320 KB |
Output is correct |
68 |
Correct |
117 ms |
14648 KB |
Output is correct |
69 |
Correct |
132 ms |
13688 KB |
Output is correct |
70 |
Correct |
55 ms |
4556 KB |
Output is correct |
71 |
Correct |
136 ms |
16244 KB |
Output is correct |
72 |
Correct |
138 ms |
16184 KB |
Output is correct |
73 |
Correct |
127 ms |
14716 KB |
Output is correct |
74 |
Correct |
91 ms |
15616 KB |
Output is correct |
75 |
Correct |
90 ms |
16192 KB |
Output is correct |
76 |
Correct |
86 ms |
16244 KB |
Output is correct |
77 |
Correct |
90 ms |
14736 KB |
Output is correct |
78 |
Correct |
95 ms |
13092 KB |
Output is correct |
79 |
Correct |
204 ms |
18116 KB |
Output is correct |
80 |
Correct |
248 ms |
17104 KB |
Output is correct |
81 |
Correct |
240 ms |
51632 KB |
Output is correct |
82 |
Correct |
298 ms |
66268 KB |
Output is correct |
83 |
Correct |
416 ms |
126256 KB |
Output is correct |
84 |
Correct |
742 ms |
149584 KB |
Output is correct |
85 |
Correct |
552 ms |
144548 KB |
Output is correct |
86 |
Correct |
538 ms |
127036 KB |
Output is correct |
87 |
Correct |
328 ms |
88204 KB |
Output is correct |
88 |
Correct |
330 ms |
100800 KB |
Output is correct |
89 |
Correct |
362 ms |
132212 KB |
Output is correct |
90 |
Correct |
619 ms |
138444 KB |
Output is correct |
91 |
Correct |
651 ms |
138444 KB |
Output is correct |