#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
9 ms |
1408 KB |
Output is correct |
3 |
Correct |
3 ms |
640 KB |
Output is correct |
4 |
Correct |
4 ms |
640 KB |
Output is correct |
5 |
Correct |
11 ms |
1664 KB |
Output is correct |
6 |
Correct |
1 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 |
2176 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 |
316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
316 KB |
Output is correct |
3 |
Correct |
485 ms |
58008 KB |
Output is correct |
4 |
Correct |
748 ms |
94896 KB |
Output is correct |
5 |
Correct |
777 ms |
92680 KB |
Output is correct |
6 |
Correct |
624 ms |
71064 KB |
Output is correct |
7 |
Correct |
677 ms |
70116 KB |
Output is correct |
8 |
Correct |
93 ms |
1144 KB |
Output is correct |
9 |
Correct |
778 ms |
93916 KB |
Output is correct |
10 |
Correct |
776 ms |
92808 KB |
Output is correct |
11 |
Correct |
635 ms |
71832 KB |
Output is correct |
12 |
Correct |
640 ms |
86804 KB |
Output is correct |
13 |
Correct |
685 ms |
93952 KB |
Output is correct |
14 |
Correct |
680 ms |
93192 KB |
Output is correct |
15 |
Correct |
562 ms |
71892 KB |
Output is correct |
16 |
Correct |
590 ms |
66460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
580 ms |
84240 KB |
Output is correct |
3 |
Correct |
1195 ms |
301192 KB |
Output is correct |
4 |
Correct |
1342 ms |
262400 KB |
Output is correct |
5 |
Correct |
1004 ms |
206192 KB |
Output is correct |
6 |
Correct |
277 ms |
31020 KB |
Output is correct |
7 |
Correct |
482 ms |
56740 KB |
Output is correct |
8 |
Correct |
714 ms |
91016 KB |
Output is correct |
9 |
Correct |
758 ms |
84376 KB |
Output is correct |
10 |
Correct |
213 ms |
22828 KB |
Output is correct |
11 |
Correct |
560 ms |
73660 KB |
Output is correct |
12 |
Correct |
564 ms |
84104 KB |
Output is correct |
13 |
Correct |
1329 ms |
301040 KB |
Output is correct |
14 |
Correct |
1411 ms |
262064 KB |
Output is correct |
15 |
Correct |
1033 ms |
206092 KB |
Output is correct |
16 |
Correct |
237 ms |
23548 KB |
Output is correct |
17 |
Correct |
450 ms |
62116 KB |
Output is correct |
18 |
Correct |
987 ms |
156936 KB |
Output is correct |
19 |
Correct |
1396 ms |
267616 KB |
Output is correct |
20 |
Correct |
1364 ms |
267404 KB |
Output is correct |
21 |
Correct |
704 ms |
90992 KB |
Output is correct |
22 |
Correct |
734 ms |
84444 KB |
Output is correct |
23 |
Correct |
219 ms |
22956 KB |
Output is correct |
24 |
Correct |
595 ms |
73496 KB |
Output is correct |
25 |
Correct |
558 ms |
84112 KB |
Output is correct |
26 |
Correct |
1236 ms |
300936 KB |
Output is correct |
27 |
Correct |
1453 ms |
262024 KB |
Output is correct |
28 |
Correct |
1040 ms |
206104 KB |
Output is correct |
29 |
Correct |
230 ms |
23596 KB |
Output is correct |
30 |
Correct |
462 ms |
62112 KB |
Output is correct |
31 |
Correct |
924 ms |
157064 KB |
Output is correct |
32 |
Correct |
1313 ms |
267792 KB |
Output is correct |
33 |
Correct |
1310 ms |
267668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
9 ms |
1408 KB |
Output is correct |
3 |
Correct |
3 ms |
640 KB |
Output is correct |
4 |
Correct |
4 ms |
640 KB |
Output is correct |
5 |
Correct |
11 ms |
1664 KB |
Output is correct |
6 |
Correct |
1 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 |
2176 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 |
316 KB |
Output is correct |
18 |
Correct |
1061 ms |
91244 KB |
Output is correct |
19 |
Correct |
187 ms |
4216 KB |
Output is correct |
20 |
Correct |
155 ms |
1768 KB |
Output is correct |
21 |
Correct |
177 ms |
2424 KB |
Output is correct |
22 |
Correct |
194 ms |
3320 KB |
Output is correct |
23 |
Correct |
174 ms |
4088 KB |
Output is correct |
24 |
Correct |
234 ms |
2140 KB |
Output is correct |
25 |
Correct |
197 ms |
2808 KB |
Output is correct |
26 |
Correct |
196 ms |
3832 KB |
Output is correct |
27 |
Correct |
661 ms |
61472 KB |
Output is correct |
28 |
Correct |
455 ms |
30764 KB |
Output is correct |
29 |
Correct |
627 ms |
57872 KB |
Output is correct |
30 |
Correct |
1373 ms |
157708 KB |
Output is correct |
31 |
Correct |
4 ms |
384 KB |
Output is correct |
32 |
Correct |
807 ms |
61820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
9 ms |
1408 KB |
Output is correct |
3 |
Correct |
3 ms |
640 KB |
Output is correct |
4 |
Correct |
4 ms |
640 KB |
Output is correct |
5 |
Correct |
11 ms |
1664 KB |
Output is correct |
6 |
Correct |
1 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 |
2176 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 |
316 KB |
Output is correct |
18 |
Correct |
1061 ms |
91244 KB |
Output is correct |
19 |
Correct |
187 ms |
4216 KB |
Output is correct |
20 |
Correct |
155 ms |
1768 KB |
Output is correct |
21 |
Correct |
177 ms |
2424 KB |
Output is correct |
22 |
Correct |
194 ms |
3320 KB |
Output is correct |
23 |
Correct |
174 ms |
4088 KB |
Output is correct |
24 |
Correct |
234 ms |
2140 KB |
Output is correct |
25 |
Correct |
197 ms |
2808 KB |
Output is correct |
26 |
Correct |
196 ms |
3832 KB |
Output is correct |
27 |
Correct |
661 ms |
61472 KB |
Output is correct |
28 |
Correct |
455 ms |
30764 KB |
Output is correct |
29 |
Correct |
627 ms |
57872 KB |
Output is correct |
30 |
Correct |
1373 ms |
157708 KB |
Output is correct |
31 |
Correct |
4 ms |
384 KB |
Output is correct |
32 |
Correct |
807 ms |
61820 KB |
Output is correct |
33 |
Correct |
580 ms |
84240 KB |
Output is correct |
34 |
Correct |
1195 ms |
301192 KB |
Output is correct |
35 |
Correct |
1342 ms |
262400 KB |
Output is correct |
36 |
Correct |
1004 ms |
206192 KB |
Output is correct |
37 |
Correct |
277 ms |
31020 KB |
Output is correct |
38 |
Correct |
482 ms |
56740 KB |
Output is correct |
39 |
Correct |
714 ms |
91016 KB |
Output is correct |
40 |
Correct |
758 ms |
84376 KB |
Output is correct |
41 |
Correct |
213 ms |
22828 KB |
Output is correct |
42 |
Correct |
560 ms |
73660 KB |
Output is correct |
43 |
Correct |
564 ms |
84104 KB |
Output is correct |
44 |
Correct |
1329 ms |
301040 KB |
Output is correct |
45 |
Correct |
1411 ms |
262064 KB |
Output is correct |
46 |
Correct |
1033 ms |
206092 KB |
Output is correct |
47 |
Correct |
237 ms |
23548 KB |
Output is correct |
48 |
Correct |
450 ms |
62116 KB |
Output is correct |
49 |
Correct |
987 ms |
156936 KB |
Output is correct |
50 |
Correct |
1396 ms |
267616 KB |
Output is correct |
51 |
Correct |
1364 ms |
267404 KB |
Output is correct |
52 |
Correct |
704 ms |
90992 KB |
Output is correct |
53 |
Correct |
734 ms |
84444 KB |
Output is correct |
54 |
Correct |
219 ms |
22956 KB |
Output is correct |
55 |
Correct |
595 ms |
73496 KB |
Output is correct |
56 |
Correct |
558 ms |
84112 KB |
Output is correct |
57 |
Correct |
1236 ms |
300936 KB |
Output is correct |
58 |
Correct |
1453 ms |
262024 KB |
Output is correct |
59 |
Correct |
1040 ms |
206104 KB |
Output is correct |
60 |
Correct |
230 ms |
23596 KB |
Output is correct |
61 |
Correct |
462 ms |
62112 KB |
Output is correct |
62 |
Correct |
924 ms |
157064 KB |
Output is correct |
63 |
Correct |
1313 ms |
267792 KB |
Output is correct |
64 |
Correct |
1310 ms |
267668 KB |
Output is correct |
65 |
Correct |
1006 ms |
91784 KB |
Output is correct |
66 |
Correct |
1044 ms |
85208 KB |
Output is correct |
67 |
Correct |
448 ms |
23552 KB |
Output is correct |
68 |
Correct |
839 ms |
74136 KB |
Output is correct |
69 |
Correct |
698 ms |
84880 KB |
Output is correct |
70 |
Correct |
1596 ms |
301756 KB |
Output is correct |
71 |
Correct |
1714 ms |
262848 KB |
Output is correct |
72 |
Correct |
1216 ms |
206908 KB |
Output is correct |
73 |
Correct |
326 ms |
24232 KB |
Output is correct |
74 |
Correct |
519 ms |
63004 KB |
Output is correct |
75 |
Correct |
1040 ms |
157708 KB |
Output is correct |
76 |
Correct |
1625 ms |
268244 KB |
Output is correct |
77 |
Correct |
1666 ms |
268196 KB |
Output is correct |
78 |
Correct |
485 ms |
58008 KB |
Output is correct |
79 |
Correct |
748 ms |
94896 KB |
Output is correct |
80 |
Correct |
777 ms |
92680 KB |
Output is correct |
81 |
Correct |
624 ms |
71064 KB |
Output is correct |
82 |
Correct |
677 ms |
70116 KB |
Output is correct |
83 |
Correct |
93 ms |
1144 KB |
Output is correct |
84 |
Correct |
778 ms |
93916 KB |
Output is correct |
85 |
Correct |
776 ms |
92808 KB |
Output is correct |
86 |
Correct |
635 ms |
71832 KB |
Output is correct |
87 |
Correct |
640 ms |
86804 KB |
Output is correct |
88 |
Correct |
685 ms |
93952 KB |
Output is correct |
89 |
Correct |
680 ms |
93192 KB |
Output is correct |
90 |
Correct |
562 ms |
71892 KB |
Output is correct |
91 |
Correct |
590 ms |
66460 KB |
Output is correct |