#include <bits/stdc++.h>
using namespace std;
#include "rainbow.h"
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef pair<int, int> ii;
const int len = 2e5+5;
int n, m, min_r = len, max_r = 0, min_c = len, max_c = 0;
struct bit{
vector<int> vec[len];
int row, col;
bit(int x = 0, int y = 0){
row = x;
col = y;
}
void init(){
for (int i = row; i >= 1; i--){
sort(vec[i].begin(), vec[i].end());
vec[i].erase(unique(vec[i].begin(), vec[i].end()), vec[i].end());
for (int j = i+(i&(-i)); j <= row; j += j&(-j))
for (auto &c: vec[i]) vec[j].pb(c);
}
for (int i = 1; i <= row; i++)
sort(vec[i].begin(), vec[i].end());
}
void upd(int i, int j){
vec[i].pb(j);
}
int ask(int i, int l, int r){
int ans = 0;
while (i > 0){
ans += upper_bound(vec[i].begin(), vec[i].end(), r) - lower_bound(vec[i].begin(), vec[i].end(), l);
i -= i&(-i);
}
return ans;
}
int query(int ar, int br, int ac, int bc){
return ask(br, ac, bc) - ask(ar-1, ac, bc);
}
void print(int row){
printf("row#%d:", row);
for (int j = 0; j < vec[row].size(); j++)
printf(" %d", vec[row][j]);
printf("\n");
}
};
bit vertices, rivers;
bit vertical, horizontal;
void nex_mov(int &x, int &y, char &c){
if (c == 'N')
x--;
else if (c == 'S')
x++;
else if (c == 'W')
y--;
else
y++;
}
void add_block(int x, int y){
min_r = min(min_r, x);
max_r = max(max_r, x);
min_c = min(min_c, y);
max_c = max(max_c, y);
rivers.upd(x, y);
vertices.upd(x, y);
vertices.upd(x+1, y);
vertices.upd(x, y+1);
vertices.upd(x+1, y+1);
vertical.upd(x, y);
vertical.upd(x, y+1);
horizontal.upd(x, y);
horizontal.upd(x+1, y);
}
void make_graph(int x, int y, char *moves){
int pos = 0;
while (true){
add_block(x, y);
if (moves[pos] == '\0')
break;
nex_mov(x, y, moves[pos++]);
}
}
void init(int n_, int m_, int sr, int sc, int M, char *moves) {
n = n_, m = m_;
vertices = bit(n+1, m+1);
rivers = bit(n, m);
vertical = bit(n, m+1);
horizontal = bit(n+1, m);
make_graph(sr, sc, moves);
vertices.init();
rivers.init();
vertical.init();
horizontal.init();
}
int colour(int ar, int ac, int br, int bc) {
int v = vertices.query(ar+1, br, ac+1, bc); // + 2*(length+width)
int e = vertical.query(ar, br, ac+1, bc); // + 2*length
e += horizontal.query(ar+1, br, ac, bc); // + 2*width
int r = rivers.query(ar, br, ac, bc);
int c = (ar < min_r && max_r < br && ac < min_c && max_c < bc)?2:1;
//printf("v = %d, e = %d, r = %d, c = %d\n", v, e, r, c);
return e + c - v - r;
}
Compilation message
rainbow.cpp: In member function 'void bit::print(int)':
rainbow.cpp:56:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for (int j = 0; j < vec[row].size(); j++)
| ~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
23808 KB |
Output is correct |
2 |
Correct |
29 ms |
23936 KB |
Output is correct |
3 |
Correct |
25 ms |
23808 KB |
Output is correct |
4 |
Correct |
25 ms |
23864 KB |
Output is correct |
5 |
Correct |
27 ms |
24056 KB |
Output is correct |
6 |
Correct |
24 ms |
23808 KB |
Output is correct |
7 |
Correct |
25 ms |
23808 KB |
Output is correct |
8 |
Correct |
22 ms |
23808 KB |
Output is correct |
9 |
Correct |
21 ms |
23808 KB |
Output is correct |
10 |
Correct |
22 ms |
23808 KB |
Output is correct |
11 |
Correct |
25 ms |
23928 KB |
Output is correct |
12 |
Correct |
24 ms |
23936 KB |
Output is correct |
13 |
Correct |
31 ms |
23932 KB |
Output is correct |
14 |
Correct |
30 ms |
24192 KB |
Output is correct |
15 |
Correct |
21 ms |
23808 KB |
Output is correct |
16 |
Correct |
22 ms |
23808 KB |
Output is correct |
17 |
Correct |
25 ms |
23808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
23808 KB |
Output is correct |
2 |
Correct |
25 ms |
23808 KB |
Output is correct |
3 |
Correct |
204 ms |
28140 KB |
Output is correct |
4 |
Correct |
274 ms |
30176 KB |
Output is correct |
5 |
Correct |
270 ms |
29920 KB |
Output is correct |
6 |
Correct |
223 ms |
29272 KB |
Output is correct |
7 |
Correct |
299 ms |
29776 KB |
Output is correct |
8 |
Correct |
116 ms |
29024 KB |
Output is correct |
9 |
Correct |
276 ms |
29916 KB |
Output is correct |
10 |
Correct |
275 ms |
29664 KB |
Output is correct |
11 |
Correct |
238 ms |
29016 KB |
Output is correct |
12 |
Correct |
153 ms |
29416 KB |
Output is correct |
13 |
Correct |
164 ms |
29872 KB |
Output is correct |
14 |
Correct |
163 ms |
29916 KB |
Output is correct |
15 |
Correct |
165 ms |
29152 KB |
Output is correct |
16 |
Correct |
239 ms |
28628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
23808 KB |
Output is correct |
2 |
Correct |
414 ms |
49872 KB |
Output is correct |
3 |
Correct |
211 ms |
56808 KB |
Output is correct |
4 |
Correct |
221 ms |
56920 KB |
Output is correct |
5 |
Correct |
246 ms |
48472 KB |
Output is correct |
6 |
Correct |
129 ms |
33400 KB |
Output is correct |
7 |
Correct |
159 ms |
34960 KB |
Output is correct |
8 |
Correct |
122 ms |
30380 KB |
Output is correct |
9 |
Correct |
133 ms |
31184 KB |
Output is correct |
10 |
Correct |
69 ms |
26772 KB |
Output is correct |
11 |
Correct |
110 ms |
30436 KB |
Output is correct |
12 |
Correct |
442 ms |
49868 KB |
Output is correct |
13 |
Correct |
219 ms |
56808 KB |
Output is correct |
14 |
Correct |
228 ms |
56892 KB |
Output is correct |
15 |
Correct |
237 ms |
48484 KB |
Output is correct |
16 |
Correct |
123 ms |
32020 KB |
Output is correct |
17 |
Correct |
170 ms |
38840 KB |
Output is correct |
18 |
Correct |
424 ms |
64600 KB |
Output is correct |
19 |
Correct |
438 ms |
54320 KB |
Output is correct |
20 |
Correct |
443 ms |
57680 KB |
Output is correct |
21 |
Correct |
115 ms |
30428 KB |
Output is correct |
22 |
Correct |
122 ms |
31204 KB |
Output is correct |
23 |
Correct |
85 ms |
26744 KB |
Output is correct |
24 |
Correct |
117 ms |
30436 KB |
Output is correct |
25 |
Correct |
427 ms |
49868 KB |
Output is correct |
26 |
Correct |
207 ms |
56728 KB |
Output is correct |
27 |
Correct |
238 ms |
56928 KB |
Output is correct |
28 |
Correct |
246 ms |
48476 KB |
Output is correct |
29 |
Correct |
117 ms |
31992 KB |
Output is correct |
30 |
Correct |
176 ms |
38888 KB |
Output is correct |
31 |
Correct |
403 ms |
64668 KB |
Output is correct |
32 |
Correct |
356 ms |
54364 KB |
Output is correct |
33 |
Correct |
420 ms |
57692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
23808 KB |
Output is correct |
2 |
Correct |
29 ms |
23936 KB |
Output is correct |
3 |
Correct |
25 ms |
23808 KB |
Output is correct |
4 |
Correct |
25 ms |
23864 KB |
Output is correct |
5 |
Correct |
27 ms |
24056 KB |
Output is correct |
6 |
Correct |
24 ms |
23808 KB |
Output is correct |
7 |
Correct |
25 ms |
23808 KB |
Output is correct |
8 |
Correct |
22 ms |
23808 KB |
Output is correct |
9 |
Correct |
21 ms |
23808 KB |
Output is correct |
10 |
Correct |
22 ms |
23808 KB |
Output is correct |
11 |
Correct |
25 ms |
23928 KB |
Output is correct |
12 |
Correct |
24 ms |
23936 KB |
Output is correct |
13 |
Correct |
31 ms |
23932 KB |
Output is correct |
14 |
Correct |
30 ms |
24192 KB |
Output is correct |
15 |
Correct |
21 ms |
23808 KB |
Output is correct |
16 |
Correct |
22 ms |
23808 KB |
Output is correct |
17 |
Correct |
25 ms |
23808 KB |
Output is correct |
18 |
Correct |
1113 ms |
37728 KB |
Output is correct |
19 |
Correct |
305 ms |
27768 KB |
Output is correct |
20 |
Correct |
236 ms |
27256 KB |
Output is correct |
21 |
Correct |
268 ms |
27528 KB |
Output is correct |
22 |
Correct |
291 ms |
27512 KB |
Output is correct |
23 |
Correct |
290 ms |
27512 KB |
Output is correct |
24 |
Correct |
294 ms |
27384 KB |
Output is correct |
25 |
Correct |
298 ms |
27512 KB |
Output is correct |
26 |
Correct |
356 ms |
27640 KB |
Output is correct |
27 |
Correct |
376 ms |
35320 KB |
Output is correct |
28 |
Correct |
346 ms |
34040 KB |
Output is correct |
29 |
Correct |
355 ms |
35192 KB |
Output is correct |
30 |
Correct |
902 ms |
45548 KB |
Output is correct |
31 |
Correct |
31 ms |
23936 KB |
Output is correct |
32 |
Correct |
725 ms |
36332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
23808 KB |
Output is correct |
2 |
Correct |
29 ms |
23936 KB |
Output is correct |
3 |
Correct |
25 ms |
23808 KB |
Output is correct |
4 |
Correct |
25 ms |
23864 KB |
Output is correct |
5 |
Correct |
27 ms |
24056 KB |
Output is correct |
6 |
Correct |
24 ms |
23808 KB |
Output is correct |
7 |
Correct |
25 ms |
23808 KB |
Output is correct |
8 |
Correct |
22 ms |
23808 KB |
Output is correct |
9 |
Correct |
21 ms |
23808 KB |
Output is correct |
10 |
Correct |
22 ms |
23808 KB |
Output is correct |
11 |
Correct |
25 ms |
23928 KB |
Output is correct |
12 |
Correct |
24 ms |
23936 KB |
Output is correct |
13 |
Correct |
31 ms |
23932 KB |
Output is correct |
14 |
Correct |
30 ms |
24192 KB |
Output is correct |
15 |
Correct |
21 ms |
23808 KB |
Output is correct |
16 |
Correct |
22 ms |
23808 KB |
Output is correct |
17 |
Correct |
25 ms |
23808 KB |
Output is correct |
18 |
Correct |
1113 ms |
37728 KB |
Output is correct |
19 |
Correct |
305 ms |
27768 KB |
Output is correct |
20 |
Correct |
236 ms |
27256 KB |
Output is correct |
21 |
Correct |
268 ms |
27528 KB |
Output is correct |
22 |
Correct |
291 ms |
27512 KB |
Output is correct |
23 |
Correct |
290 ms |
27512 KB |
Output is correct |
24 |
Correct |
294 ms |
27384 KB |
Output is correct |
25 |
Correct |
298 ms |
27512 KB |
Output is correct |
26 |
Correct |
356 ms |
27640 KB |
Output is correct |
27 |
Correct |
376 ms |
35320 KB |
Output is correct |
28 |
Correct |
346 ms |
34040 KB |
Output is correct |
29 |
Correct |
355 ms |
35192 KB |
Output is correct |
30 |
Correct |
902 ms |
45548 KB |
Output is correct |
31 |
Correct |
31 ms |
23936 KB |
Output is correct |
32 |
Correct |
725 ms |
36332 KB |
Output is correct |
33 |
Correct |
414 ms |
49872 KB |
Output is correct |
34 |
Correct |
211 ms |
56808 KB |
Output is correct |
35 |
Correct |
221 ms |
56920 KB |
Output is correct |
36 |
Correct |
246 ms |
48472 KB |
Output is correct |
37 |
Correct |
129 ms |
33400 KB |
Output is correct |
38 |
Correct |
159 ms |
34960 KB |
Output is correct |
39 |
Correct |
122 ms |
30380 KB |
Output is correct |
40 |
Correct |
133 ms |
31184 KB |
Output is correct |
41 |
Correct |
69 ms |
26772 KB |
Output is correct |
42 |
Correct |
110 ms |
30436 KB |
Output is correct |
43 |
Correct |
442 ms |
49868 KB |
Output is correct |
44 |
Correct |
219 ms |
56808 KB |
Output is correct |
45 |
Correct |
228 ms |
56892 KB |
Output is correct |
46 |
Correct |
237 ms |
48484 KB |
Output is correct |
47 |
Correct |
123 ms |
32020 KB |
Output is correct |
48 |
Correct |
170 ms |
38840 KB |
Output is correct |
49 |
Correct |
424 ms |
64600 KB |
Output is correct |
50 |
Correct |
438 ms |
54320 KB |
Output is correct |
51 |
Correct |
443 ms |
57680 KB |
Output is correct |
52 |
Correct |
115 ms |
30428 KB |
Output is correct |
53 |
Correct |
122 ms |
31204 KB |
Output is correct |
54 |
Correct |
85 ms |
26744 KB |
Output is correct |
55 |
Correct |
117 ms |
30436 KB |
Output is correct |
56 |
Correct |
427 ms |
49868 KB |
Output is correct |
57 |
Correct |
207 ms |
56728 KB |
Output is correct |
58 |
Correct |
238 ms |
56928 KB |
Output is correct |
59 |
Correct |
246 ms |
48476 KB |
Output is correct |
60 |
Correct |
117 ms |
31992 KB |
Output is correct |
61 |
Correct |
176 ms |
38888 KB |
Output is correct |
62 |
Correct |
403 ms |
64668 KB |
Output is correct |
63 |
Correct |
356 ms |
54364 KB |
Output is correct |
64 |
Correct |
420 ms |
57692 KB |
Output is correct |
65 |
Correct |
524 ms |
33892 KB |
Output is correct |
66 |
Correct |
581 ms |
34960 KB |
Output is correct |
67 |
Correct |
379 ms |
30324 KB |
Output is correct |
68 |
Correct |
448 ms |
34148 KB |
Output is correct |
69 |
Correct |
770 ms |
53420 KB |
Output is correct |
70 |
Correct |
918 ms |
60520 KB |
Output is correct |
71 |
Correct |
647 ms |
60516 KB |
Output is correct |
72 |
Correct |
691 ms |
52188 KB |
Output is correct |
73 |
Correct |
322 ms |
35576 KB |
Output is correct |
74 |
Correct |
408 ms |
42344 KB |
Output is correct |
75 |
Correct |
636 ms |
68160 KB |
Output is correct |
76 |
Correct |
912 ms |
58016 KB |
Output is correct |
77 |
Correct |
757 ms |
61272 KB |
Output is correct |
78 |
Correct |
204 ms |
28140 KB |
Output is correct |
79 |
Correct |
274 ms |
30176 KB |
Output is correct |
80 |
Correct |
270 ms |
29920 KB |
Output is correct |
81 |
Correct |
223 ms |
29272 KB |
Output is correct |
82 |
Correct |
299 ms |
29776 KB |
Output is correct |
83 |
Correct |
116 ms |
29024 KB |
Output is correct |
84 |
Correct |
276 ms |
29916 KB |
Output is correct |
85 |
Correct |
275 ms |
29664 KB |
Output is correct |
86 |
Correct |
238 ms |
29016 KB |
Output is correct |
87 |
Correct |
153 ms |
29416 KB |
Output is correct |
88 |
Correct |
164 ms |
29872 KB |
Output is correct |
89 |
Correct |
163 ms |
29916 KB |
Output is correct |
90 |
Correct |
165 ms |
29152 KB |
Output is correct |
91 |
Correct |
239 ms |
28628 KB |
Output is correct |