#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) begin(x), end(x)
#define SZ(x) (int)(x).size()
#define cps(x) sort(all(x)), (x).erase(unique(all(x)), end(x))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#include "rainbow.h"
int r, c;
map <array <int, 2>, int> used[3];
struct Node {
int n;
vector <int> xv, val, val_cell;
vector <array <int, 2>> pt;
void add(int x, int v) {
xv.pb(x);
pt.pb({x, v});
}
int pos(int x) {
return (int)(lower_bound(all(xv), x) - begin(xv));
}
void build() {
cps(xv);
n = SZ(xv);
val.resize(n), val_cell.resize(n);
for (auto & i : pt) {
int x = pos(i[0]);
if (i[1] == 0) val[x]--;
if (i[1] == 1) val[x]++;
if (i[1] == 2) val_cell[x]++;
}
for (int i = 1; i < n; i++) {
val[i] += val[i - 1];
val_cell[i] += val_cell[i - 1];
}
}
int get(int l, int r) {
l = pos(l), r = pos(r + 1) - 1;
if (l > r) return 0;
if (l == 0) return val[r];
return val[r] - val[l - 1];
}
int get_cell(int l, int r) {
l = pos(l), r = pos(r + 1) - 1;
if (l > r) return 0;
if (l == 0) return val_cell[r];
return val_cell[r] - val_cell[l - 1];
}
};
struct SegTree {
int n;
vector <int> xv;
vector <array <int, 3>> pt;
vector <Node> nd;
int pos(int x) {
return (int)(lower_bound(all(xv), x) - xv.begin());
}
void add(int x, int y, int v) {
for (x += n; x > 0; x >>= 1) nd[x].add(y, v);
}
void build() {
for (auto & i : pt) xv.pb(i[0]);
cps(xv);
n = 1;
while (n < SZ(xv)) n <<= 1;
nd.resize(n << 1);
for (auto & i : pt) {
int x = pos(i[0]);
add(x, i[1], i[2]);
}
for (int i = 1; i < (n << 1); i++) nd[i].build();
}
int get(int l, int r, int l2, int r2) {
l = pos(l), r = pos(r + 1);
if (l > r || l2 > r2) return 0;
int res = 0;
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if (r & 1) res += nd[--r].get(l2, r2);
if (l & 1) res += nd[l++].get(l2, r2);
}
return res;
}
int get_cell(int l, int r, int l2, int r2) {
l = pos(l), r = pos(r + 1);
if (l > r || l2 > r2) return 0;
int res = 0;
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if (r & 1) res += nd[--r].get_cell(l2, r2);
if (l & 1) res += nd[l++].get_cell(l2, r2);
}
return res;
}
};
SegTree plane;
void set_pt(int x, int y) {
if (used[0].count({x, y})) return;
used[0][{x, y}] = 1;
plane.pt.pb({x, y, 0});
}
void set_edge(int x, int y) {
if (used[1].count({x, y})) return;
used[1][{x, y}] = 1;
plane.pt.pb({x, y, 1});
}
void set_cell(int x, int y) {
if (used[2].count({x, y})) return;
used[2][{x, y}] = 1;
plane.pt.pb({x, y, 2});
}
void add(int x, int y) {
x *= 2, y *= 2;
set_cell(x - 1, y - 1);
set_pt(x, y), set_pt(x - 2, y), set_pt(x, y - 2), set_pt(x - 2, y - 2);
set_edge(x, y - 1), set_edge(x - 1, y), set_edge(x - 1, y - 2), set_edge(x - 2, y - 1);
}
void init(int R, int C, int sr, int sc, int M, char *S) {
r = R, c = C;
int x = sr, y = sc;
add(x, y);
for (int i = 0; i < M; i++) {
if (S[i] == 'N') x--;
if (S[i] == 'S') x++;
if (S[i] == 'W') y--;
if (S[i] == 'E') y++;
add(x, y);
}
plane.build();
}
int colour(int ar, int ac, int br, int bc) {
ar--, ac--;
ar *= 2, ac *= 2, br *= 2, bc *= 2;
int cells = plane.get_cell(ar, br, ac, bc);
int nb_cells = plane.get_cell(ar + 2, br - 2, ac + 2, bc - 2);
int C = 2;
if (cells > nb_cells || cells == 0) C = 1;
return C + plane.get(ar + 1, br - 1, ac + 1, bc - 1) - cells;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
9 ms |
1460 KB |
Output is correct |
3 |
Correct |
3 ms |
640 KB |
Output is correct |
4 |
Correct |
4 ms |
640 KB |
Output is correct |
5 |
Correct |
10 ms |
1664 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
768 KB |
Output is correct |
12 |
Correct |
7 ms |
1152 KB |
Output is correct |
13 |
Correct |
12 ms |
2120 KB |
Output is correct |
14 |
Correct |
14 ms |
2432 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
518 ms |
57736 KB |
Output is correct |
4 |
Correct |
806 ms |
94852 KB |
Output is correct |
5 |
Correct |
839 ms |
92816 KB |
Output is correct |
6 |
Correct |
650 ms |
71020 KB |
Output is correct |
7 |
Correct |
682 ms |
70040 KB |
Output is correct |
8 |
Correct |
93 ms |
1144 KB |
Output is correct |
9 |
Correct |
801 ms |
93832 KB |
Output is correct |
10 |
Correct |
764 ms |
92808 KB |
Output is correct |
11 |
Correct |
647 ms |
71580 KB |
Output is correct |
12 |
Correct |
645 ms |
86932 KB |
Output is correct |
13 |
Correct |
660 ms |
94088 KB |
Output is correct |
14 |
Correct |
665 ms |
93116 KB |
Output is correct |
15 |
Correct |
588 ms |
71832 KB |
Output is correct |
16 |
Correct |
631 ms |
66328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
586 ms |
84212 KB |
Output is correct |
3 |
Correct |
1223 ms |
301140 KB |
Output is correct |
4 |
Correct |
1448 ms |
261956 KB |
Output is correct |
5 |
Correct |
1078 ms |
206248 KB |
Output is correct |
6 |
Correct |
295 ms |
31020 KB |
Output is correct |
7 |
Correct |
444 ms |
56740 KB |
Output is correct |
8 |
Correct |
757 ms |
90992 KB |
Output is correct |
9 |
Correct |
775 ms |
84468 KB |
Output is correct |
10 |
Correct |
213 ms |
22824 KB |
Output is correct |
11 |
Correct |
619 ms |
73628 KB |
Output is correct |
12 |
Correct |
596 ms |
84112 KB |
Output is correct |
13 |
Correct |
1214 ms |
300948 KB |
Output is correct |
14 |
Correct |
1376 ms |
262124 KB |
Output is correct |
15 |
Correct |
1065 ms |
206252 KB |
Output is correct |
16 |
Correct |
226 ms |
23596 KB |
Output is correct |
17 |
Correct |
441 ms |
62048 KB |
Output is correct |
18 |
Correct |
1049 ms |
157028 KB |
Output is correct |
19 |
Correct |
1488 ms |
267548 KB |
Output is correct |
20 |
Correct |
1442 ms |
267456 KB |
Output is correct |
21 |
Correct |
791 ms |
91068 KB |
Output is correct |
22 |
Correct |
715 ms |
84504 KB |
Output is correct |
23 |
Correct |
207 ms |
22828 KB |
Output is correct |
24 |
Correct |
597 ms |
73508 KB |
Output is correct |
25 |
Correct |
576 ms |
84104 KB |
Output is correct |
26 |
Correct |
1238 ms |
301268 KB |
Output is correct |
27 |
Correct |
1407 ms |
262136 KB |
Output is correct |
28 |
Correct |
1039 ms |
206232 KB |
Output is correct |
29 |
Correct |
224 ms |
23596 KB |
Output is correct |
30 |
Correct |
444 ms |
62116 KB |
Output is correct |
31 |
Correct |
956 ms |
156964 KB |
Output is correct |
32 |
Correct |
1426 ms |
267528 KB |
Output is correct |
33 |
Correct |
1423 ms |
267400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
9 ms |
1460 KB |
Output is correct |
3 |
Correct |
3 ms |
640 KB |
Output is correct |
4 |
Correct |
4 ms |
640 KB |
Output is correct |
5 |
Correct |
10 ms |
1664 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
768 KB |
Output is correct |
12 |
Correct |
7 ms |
1152 KB |
Output is correct |
13 |
Correct |
12 ms |
2120 KB |
Output is correct |
14 |
Correct |
14 ms |
2432 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
1111 ms |
91160 KB |
Output is correct |
19 |
Correct |
191 ms |
4216 KB |
Output is correct |
20 |
Correct |
159 ms |
1784 KB |
Output is correct |
21 |
Correct |
172 ms |
2424 KB |
Output is correct |
22 |
Correct |
177 ms |
3320 KB |
Output is correct |
23 |
Correct |
193 ms |
4284 KB |
Output is correct |
24 |
Correct |
212 ms |
2296 KB |
Output is correct |
25 |
Correct |
224 ms |
2808 KB |
Output is correct |
26 |
Correct |
210 ms |
3704 KB |
Output is correct |
27 |
Correct |
672 ms |
61324 KB |
Output is correct |
28 |
Correct |
469 ms |
30760 KB |
Output is correct |
29 |
Correct |
645 ms |
57888 KB |
Output is correct |
30 |
Correct |
1336 ms |
157704 KB |
Output is correct |
31 |
Correct |
4 ms |
384 KB |
Output is correct |
32 |
Correct |
867 ms |
61756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
9 ms |
1460 KB |
Output is correct |
3 |
Correct |
3 ms |
640 KB |
Output is correct |
4 |
Correct |
4 ms |
640 KB |
Output is correct |
5 |
Correct |
10 ms |
1664 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
768 KB |
Output is correct |
12 |
Correct |
7 ms |
1152 KB |
Output is correct |
13 |
Correct |
12 ms |
2120 KB |
Output is correct |
14 |
Correct |
14 ms |
2432 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
1111 ms |
91160 KB |
Output is correct |
19 |
Correct |
191 ms |
4216 KB |
Output is correct |
20 |
Correct |
159 ms |
1784 KB |
Output is correct |
21 |
Correct |
172 ms |
2424 KB |
Output is correct |
22 |
Correct |
177 ms |
3320 KB |
Output is correct |
23 |
Correct |
193 ms |
4284 KB |
Output is correct |
24 |
Correct |
212 ms |
2296 KB |
Output is correct |
25 |
Correct |
224 ms |
2808 KB |
Output is correct |
26 |
Correct |
210 ms |
3704 KB |
Output is correct |
27 |
Correct |
672 ms |
61324 KB |
Output is correct |
28 |
Correct |
469 ms |
30760 KB |
Output is correct |
29 |
Correct |
645 ms |
57888 KB |
Output is correct |
30 |
Correct |
1336 ms |
157704 KB |
Output is correct |
31 |
Correct |
4 ms |
384 KB |
Output is correct |
32 |
Correct |
867 ms |
61756 KB |
Output is correct |
33 |
Correct |
586 ms |
84212 KB |
Output is correct |
34 |
Correct |
1223 ms |
301140 KB |
Output is correct |
35 |
Correct |
1448 ms |
261956 KB |
Output is correct |
36 |
Correct |
1078 ms |
206248 KB |
Output is correct |
37 |
Correct |
295 ms |
31020 KB |
Output is correct |
38 |
Correct |
444 ms |
56740 KB |
Output is correct |
39 |
Correct |
757 ms |
90992 KB |
Output is correct |
40 |
Correct |
775 ms |
84468 KB |
Output is correct |
41 |
Correct |
213 ms |
22824 KB |
Output is correct |
42 |
Correct |
619 ms |
73628 KB |
Output is correct |
43 |
Correct |
596 ms |
84112 KB |
Output is correct |
44 |
Correct |
1214 ms |
300948 KB |
Output is correct |
45 |
Correct |
1376 ms |
262124 KB |
Output is correct |
46 |
Correct |
1065 ms |
206252 KB |
Output is correct |
47 |
Correct |
226 ms |
23596 KB |
Output is correct |
48 |
Correct |
441 ms |
62048 KB |
Output is correct |
49 |
Correct |
1049 ms |
157028 KB |
Output is correct |
50 |
Correct |
1488 ms |
267548 KB |
Output is correct |
51 |
Correct |
1442 ms |
267456 KB |
Output is correct |
52 |
Correct |
791 ms |
91068 KB |
Output is correct |
53 |
Correct |
715 ms |
84504 KB |
Output is correct |
54 |
Correct |
207 ms |
22828 KB |
Output is correct |
55 |
Correct |
597 ms |
73508 KB |
Output is correct |
56 |
Correct |
576 ms |
84104 KB |
Output is correct |
57 |
Correct |
1238 ms |
301268 KB |
Output is correct |
58 |
Correct |
1407 ms |
262136 KB |
Output is correct |
59 |
Correct |
1039 ms |
206232 KB |
Output is correct |
60 |
Correct |
224 ms |
23596 KB |
Output is correct |
61 |
Correct |
444 ms |
62116 KB |
Output is correct |
62 |
Correct |
956 ms |
156964 KB |
Output is correct |
63 |
Correct |
1426 ms |
267528 KB |
Output is correct |
64 |
Correct |
1423 ms |
267400 KB |
Output is correct |
65 |
Correct |
1018 ms |
91784 KB |
Output is correct |
66 |
Correct |
1112 ms |
85148 KB |
Output is correct |
67 |
Correct |
481 ms |
23848 KB |
Output is correct |
68 |
Correct |
835 ms |
74264 KB |
Output is correct |
69 |
Correct |
702 ms |
84872 KB |
Output is correct |
70 |
Correct |
1476 ms |
301832 KB |
Output is correct |
71 |
Correct |
1576 ms |
262840 KB |
Output is correct |
72 |
Correct |
1215 ms |
207004 KB |
Output is correct |
73 |
Correct |
337 ms |
24360 KB |
Output is correct |
74 |
Correct |
533 ms |
62764 KB |
Output is correct |
75 |
Correct |
1066 ms |
157836 KB |
Output is correct |
76 |
Correct |
1695 ms |
268444 KB |
Output is correct |
77 |
Correct |
1746 ms |
268128 KB |
Output is correct |
78 |
Correct |
518 ms |
57736 KB |
Output is correct |
79 |
Correct |
806 ms |
94852 KB |
Output is correct |
80 |
Correct |
839 ms |
92816 KB |
Output is correct |
81 |
Correct |
650 ms |
71020 KB |
Output is correct |
82 |
Correct |
682 ms |
70040 KB |
Output is correct |
83 |
Correct |
93 ms |
1144 KB |
Output is correct |
84 |
Correct |
801 ms |
93832 KB |
Output is correct |
85 |
Correct |
764 ms |
92808 KB |
Output is correct |
86 |
Correct |
647 ms |
71580 KB |
Output is correct |
87 |
Correct |
645 ms |
86932 KB |
Output is correct |
88 |
Correct |
660 ms |
94088 KB |
Output is correct |
89 |
Correct |
665 ms |
93116 KB |
Output is correct |
90 |
Correct |
588 ms |
71832 KB |
Output is correct |
91 |
Correct |
631 ms |
66328 KB |
Output is correct |