#include <bits/stdc++.h>
#include "rainbow.h"
template <class T>
using Vec = std::vector<T>;
// struct Count2D {
// int size;
// Vec<Vec<int>> pts;
// Vec<Vec<int>> left, right;
// Count2D() = default;
// Count2D(const int range) {
// size = 1;
// while (size < range) {
// size <<= 1;
// }
// pts.resize(2 * size);
// left.resize(size);
// right.resize(size);
// }
// void add(const int x, const int y) {
// pts[x + size].push_back(y);
// }
// void build() {
// for (int i = size; i < 2 * size; ++i) {
// std::sort(pts[i].begin(), pts[i].end());
// pts[i].erase(std::unique(pts[i].begin(), pts[i].end()), pts[i].end());
// }
// for (int i = size - 1; i > 0; --i) {
// const auto l = 2 * i;
// const auto r = 2 * i + 1;
// const auto l_sz = (int) pts[l].size();
// const auto r_sz = (int) pts[r].size();
// const auto sz = l_sz + r_sz;
// pts[i].reserve(sz);
// left[i].reserve(sz + 1);
// right[i].reserve(sz + 1);
// int s = 0, t = 0;
// while (s < l_sz || t < r_sz) {
// left[i].push_back(s);
// right[i].push_back(t);
// if (t == r_sz || (s < l_sz && pts[l][s] < pts[r][t])) {
// pts[i].push_back(pts[l][s]);
// s += 1;
// }
// else {
// pts[i].push_back(pts[r][t]);
// t += 1;
// }
// }
// left[i].push_back(l_sz);
// right[i].push_back(r_sz);
// }
// }
// int count(const int xl, const int xr, int yl, int yr) const {
// yl = std::lower_bound(pts[1].begin(), pts[1].end(), yl) - pts[1].begin();
// yr = std::lower_bound(pts[1].begin(), pts[1].end(), yr) - pts[1].begin();
// return count(xl, xr, yl, yr, 1, 0, size);
// }
// int count(const int xl, const int xr, const int yl, const int yr, const int k, const int l, const int r) const {
// if (xl <= l && r <= xr) {
// return yr - yl;
// }
// if (xr <= l || r <= xl) {
// return 0;
// }
// const auto m = (l + r) / 2;
// return count(xl, xr, left[k][yl], left[k][yr], 2 * k, l, m) + count(xl, xr, right[k][yl], right[k][yr], 2 * k + 1, m, r);
// }
// };
struct Count2D {
Count2D(const int _ = 0) { }
std::set<std::pair<int, int>> set;
void add(const int x, const int y) {
set.emplace(x, y);
}
void build() {
}
int count(const int xl, const int xr, const int yl, const int yr) const {
int ret = 0;
for (const auto [x, y]: set) {
if (xl <= x && x < xr && yl <= y && y < yr) {
ret += 1;
}
}
return ret;
}
};
int Row, Column;
int maxX, minX, maxY, minY;
Count2D vert, edgeR, edgeC, cycle;
void add(const int x, const int y) {
maxX = std::max(maxX, x);
minX = std::min(minX, x);
maxY = std::max(maxY, y);
minY = std::min(minY, y);
vert.add(x, y);
edgeR.add(x, y);
edgeC.add(x, y);
cycle.add(x, y);
if (x > 0) {
edgeC.add(x - 1, y);
cycle.add(x - 1, y);
}
if (y > 0) {
edgeR.add(x, y - 1);
cycle.add(x, y - 1);
}
if (x > 0 && y > 0) {
cycle.add(x - 1, y - 1);
}
}
void init(int R, int C, int sr, int sc, int M, char *S) {
Row = R;
Column = C;
maxX = -1, minX = R, maxY = -1, minY = C;
vert = Count2D(R);
edgeR = Count2D(R);
edgeC = Count2D(R);
cycle = Count2D(R);
sr -= 1;
sc -= 1;
add(sr, sc);
for (int i = 0; i < M; ++i) {
if (S[i] == 'N') sr -= 1;
if (S[i] == 'S') sr += 1;
if (S[i] == 'E') sc += 1;
if (S[i] == 'W') sc -= 1;
add(sr, sc);
}
vert.build();
edgeR.build();
edgeC.build();
cycle.build();
}
int colour(int ar, int ac, int br, int bc) {
ar -= 1;
ac -= 1;
long long V = 0, E = 0, C = 0;
V += (long long) (br - ar) * (bc - ac);
V -= vert.count(ar, br, ac, bc);
E += (long long) (br - ar) * (bc - ac - 1);
E -= edgeR.count(ar, br, ac, bc - 1);
E += (long long) (br - ar - 1) * (bc - ac);
E -= edgeC.count(ar, br - 1, ac, bc);
C += (long long) (br - ar - 1) * (bc - ac - 1);
C -= cycle.count(ar, br - 1, ac, bc - 1);
if (ar < minX && br >= maxX && ac < minY && bc >= maxY) {
C += 1;
}
return V + C - E;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
364 KB |
Output is correct |
2 |
Correct |
49 ms |
748 KB |
Output is correct |
3 |
Incorrect |
11 ms |
364 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
249 ms |
28780 KB |
Output is correct |
3 |
Correct |
237 ms |
28652 KB |
Output is correct |
4 |
Correct |
253 ms |
28652 KB |
Output is correct |
5 |
Correct |
194 ms |
21740 KB |
Output is correct |
6 |
Correct |
107 ms |
5740 KB |
Output is correct |
7 |
Correct |
173 ms |
10988 KB |
Output is correct |
8 |
Correct |
201 ms |
21960 KB |
Output is correct |
9 |
Correct |
202 ms |
20204 KB |
Output is correct |
10 |
Correct |
84 ms |
5996 KB |
Output is correct |
11 |
Correct |
184 ms |
14476 KB |
Output is correct |
12 |
Correct |
249 ms |
28716 KB |
Output is correct |
13 |
Correct |
242 ms |
28652 KB |
Output is correct |
14 |
Correct |
251 ms |
28652 KB |
Output is correct |
15 |
Correct |
191 ms |
21484 KB |
Output is correct |
16 |
Correct |
108 ms |
4588 KB |
Output is correct |
17 |
Correct |
163 ms |
10988 KB |
Output is correct |
18 |
Correct |
235 ms |
28524 KB |
Output is correct |
19 |
Correct |
198 ms |
23916 KB |
Output is correct |
20 |
Correct |
203 ms |
23916 KB |
Output is correct |
21 |
Correct |
198 ms |
21868 KB |
Output is correct |
22 |
Correct |
200 ms |
19948 KB |
Output is correct |
23 |
Correct |
86 ms |
5996 KB |
Output is correct |
24 |
Correct |
179 ms |
14188 KB |
Output is correct |
25 |
Correct |
251 ms |
28652 KB |
Output is correct |
26 |
Correct |
235 ms |
28652 KB |
Output is correct |
27 |
Correct |
248 ms |
28652 KB |
Output is correct |
28 |
Correct |
190 ms |
21484 KB |
Output is correct |
29 |
Correct |
105 ms |
4588 KB |
Output is correct |
30 |
Correct |
159 ms |
10988 KB |
Output is correct |
31 |
Correct |
230 ms |
28524 KB |
Output is correct |
32 |
Correct |
202 ms |
23916 KB |
Output is correct |
33 |
Correct |
200 ms |
23916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
364 KB |
Output is correct |
2 |
Correct |
49 ms |
748 KB |
Output is correct |
3 |
Incorrect |
11 ms |
364 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
364 KB |
Output is correct |
2 |
Correct |
49 ms |
748 KB |
Output is correct |
3 |
Incorrect |
11 ms |
364 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |