#include <bits/stdc++.h>
#include <rainbow.h>
#define taskname "test"
#define fi first
#define se second
#define pb push_back
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
using ll = long long;
using pii = pair <int, int>;
ll min(const ll &a, const ll &b){
return (a < b) ? a : b;
}
ll max(const ll &a, const ll &b){
return (a > b) ? a : b;
}
const ll Mod = 1000000007;
const int maxR = 2e5 + 1;
int n;
struct bit2d{
vector <vector <int>> node, bit;
int sizee;
void set_size(int n){
node.resize(n + 1);
bit.resize(n + 1);
sizee = n;
}
void fakeUpdate(int x, int y){
for (; x <= sizee; x += x & -x){
node[x].pb(y);
}
}
void build(){
for (int x = 1; x <= sizee; ++x){
sort(node[x].begin(), node[x].end());
node[x].resize(unique(node[x].begin(), node[x].end()) - node[x].begin());
bit[x].resize(node[x].size() + 1);
}
}
void update(int x, int yy){
for (int i = x; i <= sizee; i += i & -i){
int y = upper_bound(node[i].begin(), node[i].end(), yy) - node[i].begin();
for (int j = y; j < bit[i].size(); j += j & -j){
++bit[i][j];
}
}
}
int get(int x, int yy){
int sum = 0;
for (int i = x; i > 0; i -= i & -i){
int y = upper_bound(node[i].begin(), node[i].end(), yy) - node[i].begin();
for (int j = y; j > 0; j -= j & -j){
sum += bit[i][j];
}
}
return sum;
}
int get(int x1, int y1, int x2, int y2){
if (x1 > x2 || y1 > y2) return 0;
return get(x2, y2) + get(x1 - 1, y1 - 1) - get(x2, y1 - 1) - get(x1 - 1, y2);
}
};
bit2d vertices, horizontal_edges, vertical_edges, rivers; //unique
set <pii> r, c, b, v;
void add(int i, int j){
b.insert({i, j});
r.insert({i, j});
r.insert({i + 1, j});
c.insert({i, j});
c.insert({i, j + 1});
v.insert({i, j});
v.insert({i + 1, j});
v.insert({i, j + 1});
v.insert({i + 1, j + 1});
}
int minr, maxr, minc, maxc;
void init(int R, int C, int sr, int sc, int M, char *s) {
rivers.set_size(R + 1);
horizontal_edges.set_size(R + 1);
vertical_edges.set_size(R + 1);
vertices.set_size(R + 1);
minr = maxr = sr; minc = maxc = sc;
add(sr, sc);
for (int i = 0; i < M; ++i){
if (s[i] == 'W') --sc;
if (s[i] == 'E') ++sc;
if (s[i] == 'N') --sr;
if (s[i] == 'S') ++sr;
add(sr, sc);
minr = min(minr, sr);
minc = min(minc, sc);
maxr = max(maxr, sr);
maxc = max(maxc, sc);
}
//get space to allocate and update
for (const auto &i: b){
rivers.fakeUpdate(i.fi, i.se);
}
for (const auto &i: r){
horizontal_edges.fakeUpdate(i.fi, i.se);
}
for (const auto &i: c){
vertical_edges.fakeUpdate(i.fi, i.se);
}
for (const auto &i: v){
vertices.fakeUpdate(i.fi, i.se);
}
rivers.build();
horizontal_edges.build();
vertical_edges.build();
vertices.build();
for (const auto &i: b){
rivers.update(i.fi, i.se);
}
for (const auto &i: r){
horizontal_edges.update(i.fi, i.se);
}
for (const auto &i: c){
vertical_edges.update(i.fi, i.se);
}
for (const auto &i: v){
vertices.update(i.fi, i.se);
}
}
//statement??? "colour" is supposed to be plural
int colour(int ar, int ac, int br, int bc){
int C = 1 + (ar < minr && br > maxr && ac < minc && bc > maxc);
int E = horizontal_edges.get(ar + 1, ac, br, bc) + vertical_edges.get(ar, ac + 1, br, bc);
int V = vertices.get(ar + 1, ac + 1, br, bc);
int R = rivers.get(ar, ac, br, bc);
return E + C - R - V;
}
Compilation message
rainbow.cpp: In member function 'void bit2d::update(int, int)':
rainbow.cpp:48:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for (int j = y; j < bit[i].size(); j += j & -j){
| ~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
5 ms |
596 KB |
Output is correct |
3 |
Correct |
2 ms |
320 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
5 ms |
700 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
0 ms |
308 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
4 ms |
468 KB |
Output is correct |
12 |
Correct |
4 ms |
596 KB |
Output is correct |
13 |
Correct |
6 ms |
852 KB |
Output is correct |
14 |
Correct |
7 ms |
980 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
292 ms |
24420 KB |
Output is correct |
4 |
Correct |
459 ms |
38264 KB |
Output is correct |
5 |
Correct |
469 ms |
38000 KB |
Output is correct |
6 |
Correct |
439 ms |
30064 KB |
Output is correct |
7 |
Correct |
467 ms |
29808 KB |
Output is correct |
8 |
Correct |
70 ms |
3956 KB |
Output is correct |
9 |
Correct |
460 ms |
38372 KB |
Output is correct |
10 |
Correct |
478 ms |
37948 KB |
Output is correct |
11 |
Correct |
466 ms |
29988 KB |
Output is correct |
12 |
Correct |
357 ms |
35588 KB |
Output is correct |
13 |
Correct |
389 ms |
38228 KB |
Output is correct |
14 |
Correct |
396 ms |
37880 KB |
Output is correct |
15 |
Correct |
394 ms |
29960 KB |
Output is correct |
16 |
Correct |
347 ms |
28440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
882 ms |
131372 KB |
Output is correct |
3 |
Correct |
470 ms |
121672 KB |
Output is correct |
4 |
Correct |
760 ms |
128520 KB |
Output is correct |
5 |
Correct |
487 ms |
110260 KB |
Output is correct |
6 |
Correct |
226 ms |
74100 KB |
Output is correct |
7 |
Correct |
378 ms |
82576 KB |
Output is correct |
8 |
Correct |
355 ms |
32784 KB |
Output is correct |
9 |
Correct |
330 ms |
30376 KB |
Output is correct |
10 |
Correct |
135 ms |
39308 KB |
Output is correct |
11 |
Correct |
259 ms |
50772 KB |
Output is correct |
12 |
Correct |
864 ms |
131440 KB |
Output is correct |
13 |
Correct |
480 ms |
121756 KB |
Output is correct |
14 |
Correct |
751 ms |
128532 KB |
Output is correct |
15 |
Correct |
469 ms |
110244 KB |
Output is correct |
16 |
Correct |
218 ms |
71956 KB |
Output is correct |
17 |
Correct |
411 ms |
86108 KB |
Output is correct |
18 |
Correct |
823 ms |
131068 KB |
Output is correct |
19 |
Correct |
682 ms |
127056 KB |
Output is correct |
20 |
Correct |
788 ms |
133120 KB |
Output is correct |
21 |
Correct |
355 ms |
32836 KB |
Output is correct |
22 |
Correct |
348 ms |
30412 KB |
Output is correct |
23 |
Correct |
134 ms |
39320 KB |
Output is correct |
24 |
Correct |
274 ms |
50848 KB |
Output is correct |
25 |
Correct |
864 ms |
131384 KB |
Output is correct |
26 |
Correct |
458 ms |
121616 KB |
Output is correct |
27 |
Correct |
784 ms |
128556 KB |
Output is correct |
28 |
Correct |
476 ms |
110216 KB |
Output is correct |
29 |
Correct |
215 ms |
71896 KB |
Output is correct |
30 |
Correct |
411 ms |
86100 KB |
Output is correct |
31 |
Correct |
843 ms |
131132 KB |
Output is correct |
32 |
Correct |
672 ms |
127092 KB |
Output is correct |
33 |
Correct |
812 ms |
132948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
5 ms |
596 KB |
Output is correct |
3 |
Correct |
2 ms |
320 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
5 ms |
700 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
0 ms |
308 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
4 ms |
468 KB |
Output is correct |
12 |
Correct |
4 ms |
596 KB |
Output is correct |
13 |
Correct |
6 ms |
852 KB |
Output is correct |
14 |
Correct |
7 ms |
980 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
721 ms |
27120 KB |
Output is correct |
19 |
Correct |
225 ms |
4828 KB |
Output is correct |
20 |
Correct |
155 ms |
3924 KB |
Output is correct |
21 |
Correct |
158 ms |
4140 KB |
Output is correct |
22 |
Correct |
188 ms |
4332 KB |
Output is correct |
23 |
Correct |
192 ms |
4728 KB |
Output is correct |
24 |
Correct |
185 ms |
4036 KB |
Output is correct |
25 |
Correct |
176 ms |
4332 KB |
Output is correct |
26 |
Correct |
228 ms |
4524 KB |
Output is correct |
27 |
Correct |
427 ms |
21616 KB |
Output is correct |
28 |
Correct |
359 ms |
13068 KB |
Output is correct |
29 |
Correct |
410 ms |
19996 KB |
Output is correct |
30 |
Correct |
739 ms |
50476 KB |
Output is correct |
31 |
Correct |
3 ms |
340 KB |
Output is correct |
32 |
Correct |
508 ms |
23040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
5 ms |
596 KB |
Output is correct |
3 |
Correct |
2 ms |
320 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
5 ms |
700 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
0 ms |
308 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
4 ms |
468 KB |
Output is correct |
12 |
Correct |
4 ms |
596 KB |
Output is correct |
13 |
Correct |
6 ms |
852 KB |
Output is correct |
14 |
Correct |
7 ms |
980 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
721 ms |
27120 KB |
Output is correct |
19 |
Correct |
225 ms |
4828 KB |
Output is correct |
20 |
Correct |
155 ms |
3924 KB |
Output is correct |
21 |
Correct |
158 ms |
4140 KB |
Output is correct |
22 |
Correct |
188 ms |
4332 KB |
Output is correct |
23 |
Correct |
192 ms |
4728 KB |
Output is correct |
24 |
Correct |
185 ms |
4036 KB |
Output is correct |
25 |
Correct |
176 ms |
4332 KB |
Output is correct |
26 |
Correct |
228 ms |
4524 KB |
Output is correct |
27 |
Correct |
427 ms |
21616 KB |
Output is correct |
28 |
Correct |
359 ms |
13068 KB |
Output is correct |
29 |
Correct |
410 ms |
19996 KB |
Output is correct |
30 |
Correct |
739 ms |
50476 KB |
Output is correct |
31 |
Correct |
3 ms |
340 KB |
Output is correct |
32 |
Correct |
508 ms |
23040 KB |
Output is correct |
33 |
Correct |
882 ms |
131372 KB |
Output is correct |
34 |
Correct |
470 ms |
121672 KB |
Output is correct |
35 |
Correct |
760 ms |
128520 KB |
Output is correct |
36 |
Correct |
487 ms |
110260 KB |
Output is correct |
37 |
Correct |
226 ms |
74100 KB |
Output is correct |
38 |
Correct |
378 ms |
82576 KB |
Output is correct |
39 |
Correct |
355 ms |
32784 KB |
Output is correct |
40 |
Correct |
330 ms |
30376 KB |
Output is correct |
41 |
Correct |
135 ms |
39308 KB |
Output is correct |
42 |
Correct |
259 ms |
50772 KB |
Output is correct |
43 |
Correct |
864 ms |
131440 KB |
Output is correct |
44 |
Correct |
480 ms |
121756 KB |
Output is correct |
45 |
Correct |
751 ms |
128532 KB |
Output is correct |
46 |
Correct |
469 ms |
110244 KB |
Output is correct |
47 |
Correct |
218 ms |
71956 KB |
Output is correct |
48 |
Correct |
411 ms |
86108 KB |
Output is correct |
49 |
Correct |
823 ms |
131068 KB |
Output is correct |
50 |
Correct |
682 ms |
127056 KB |
Output is correct |
51 |
Correct |
788 ms |
133120 KB |
Output is correct |
52 |
Correct |
355 ms |
32836 KB |
Output is correct |
53 |
Correct |
348 ms |
30412 KB |
Output is correct |
54 |
Correct |
134 ms |
39320 KB |
Output is correct |
55 |
Correct |
274 ms |
50848 KB |
Output is correct |
56 |
Correct |
864 ms |
131384 KB |
Output is correct |
57 |
Correct |
458 ms |
121616 KB |
Output is correct |
58 |
Correct |
784 ms |
128556 KB |
Output is correct |
59 |
Correct |
476 ms |
110216 KB |
Output is correct |
60 |
Correct |
215 ms |
71896 KB |
Output is correct |
61 |
Correct |
411 ms |
86100 KB |
Output is correct |
62 |
Correct |
843 ms |
131132 KB |
Output is correct |
63 |
Correct |
672 ms |
127092 KB |
Output is correct |
64 |
Correct |
812 ms |
132948 KB |
Output is correct |
65 |
Correct |
292 ms |
24420 KB |
Output is correct |
66 |
Correct |
459 ms |
38264 KB |
Output is correct |
67 |
Correct |
469 ms |
38000 KB |
Output is correct |
68 |
Correct |
439 ms |
30064 KB |
Output is correct |
69 |
Correct |
467 ms |
29808 KB |
Output is correct |
70 |
Correct |
70 ms |
3956 KB |
Output is correct |
71 |
Correct |
460 ms |
38372 KB |
Output is correct |
72 |
Correct |
478 ms |
37948 KB |
Output is correct |
73 |
Correct |
466 ms |
29988 KB |
Output is correct |
74 |
Correct |
357 ms |
35588 KB |
Output is correct |
75 |
Correct |
389 ms |
38228 KB |
Output is correct |
76 |
Correct |
396 ms |
37880 KB |
Output is correct |
77 |
Correct |
394 ms |
29960 KB |
Output is correct |
78 |
Correct |
347 ms |
28440 KB |
Output is correct |
79 |
Correct |
654 ms |
36240 KB |
Output is correct |
80 |
Correct |
665 ms |
33844 KB |
Output is correct |
81 |
Correct |
420 ms |
42788 KB |
Output is correct |
82 |
Correct |
501 ms |
54248 KB |
Output is correct |
83 |
Correct |
1242 ms |
134956 KB |
Output is correct |
84 |
Correct |
785 ms |
125172 KB |
Output is correct |
85 |
Correct |
1172 ms |
132100 KB |
Output is correct |
86 |
Correct |
778 ms |
113988 KB |
Output is correct |
87 |
Correct |
411 ms |
75480 KB |
Output is correct |
88 |
Correct |
604 ms |
89604 KB |
Output is correct |
89 |
Correct |
1037 ms |
134556 KB |
Output is correct |
90 |
Correct |
1014 ms |
130500 KB |
Output is correct |
91 |
Correct |
1000 ms |
136600 KB |
Output is correct |