#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
struct BIT2D{
set<pair<int, int>> S;
vector<vector<int>> bit;
int R, C;
void init(int _R, int _C){
R = _R;
C = _C;
bit.resize(R+1);
}
void upd(int x, int y){ // updatea la posicion {x, y} con += 1
if(x < 1 || x > R || y < 1 || y > C || S.find({x, y}) != S.end()) return;
S.insert({x, y});
for(int i = x; i<=R; i+= i&(-i)){
bit[i].emplace_back(y);
}
}
void build(){
for(int i = 1; i<=R; ++i){
sort(bit[i].begin(), bit[i].end());
}
}
int qry(int x, int y){
int res = 0;
for(int i = x; i>0; i -= i&(-i)){
res += upper_bound(bit[i].begin(), bit[i].end(), y) - bit[i].begin();
}
return res;
}
ll qry(int lx, int ly, int rx, int ry){
return 1LL * (rx-lx+1) * (ry-ly+1) - qry(rx, ry) + qry(rx, ly-1) + qry(lx-1, ry) - qry(lx-1, ly-1);
}
}V, rowE, colE, F;
int max_X, min_X, max_Y, min_Y;
void add(int cx, int cy){
max_X = max(max_X, cx);
min_X = min(min_X, cx);
max_Y = max(max_Y, cy);
min_Y = min(min_Y, cy);
V.upd(cx, cy);
rowE.upd(cx-1, cy);
rowE.upd(cx, cy);
colE.upd(cx, cy-1);
colE.upd(cx, cy);
F.upd(cx-1, cy-1);
F.upd(cx-1, cy);
F.upd(cx, cy-1);
F.upd(cx, cy);
}
void init(int R, int C, int cx, int cy, int M, char *S){
V.init(R, C);
rowE.init(R, C);
colE.init(R, C);
F.init(R, C);
max_X = min_X = cx;
max_Y = min_Y = cy;
add(cx, cy);
for(int i = 0; i<M; ++i){
if(S[i] == 'N'){
cx--;
}else if(S[i] == 'E'){
cy++;
}else if(S[i] == 'W'){
cy--;
}else{
cx++;
}
add(cx, cy);
}
V.build();
rowE.build();
colE.build();
F.build();
}
int colour(int lx, int ly, int rx, int ry){
return V.qry(lx, ly, rx, ry) - rowE.qry(lx, ly, rx-1, ry) - colE.qry(lx, ly, rx, ry-1) + F.qry(lx, ly, rx-1, ry-1) + (lx < min_X && max_X < rx && ly < min_Y && max_Y < ry);
}
/*
int main(){
#ifdef _DEBUG
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0);
init(6, 4, 3, 3, 9, "NWESSWEWS");
cout << colours(2, 3, 2, 3) << "\n";
cout << colours(3, 2, 4, 4) << "\n";
cout << colours(5, 3, 6, 4) << "\n";
cout << colours(1, 2, 5, 3) << "\n";
}
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
320 KB |
Output is correct |
2 |
Correct |
6 ms |
596 KB |
Output is correct |
3 |
Correct |
3 ms |
320 KB |
Output is correct |
4 |
Correct |
3 ms |
340 KB |
Output is correct |
5 |
Correct |
6 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
3 ms |
444 KB |
Output is correct |
12 |
Correct |
4 ms |
468 KB |
Output is correct |
13 |
Correct |
6 ms |
852 KB |
Output is correct |
14 |
Correct |
8 ms |
980 KB |
Output is correct |
15 |
Correct |
1 ms |
308 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 |
213 ms |
20064 KB |
Output is correct |
4 |
Correct |
299 ms |
30460 KB |
Output is correct |
5 |
Correct |
300 ms |
30176 KB |
Output is correct |
6 |
Correct |
274 ms |
23436 KB |
Output is correct |
7 |
Correct |
280 ms |
22548 KB |
Output is correct |
8 |
Correct |
58 ms |
3924 KB |
Output is correct |
9 |
Correct |
320 ms |
30348 KB |
Output is correct |
10 |
Correct |
302 ms |
30036 KB |
Output is correct |
11 |
Correct |
295 ms |
23428 KB |
Output is correct |
12 |
Correct |
259 ms |
29508 KB |
Output is correct |
13 |
Correct |
247 ms |
30400 KB |
Output is correct |
14 |
Correct |
236 ms |
30080 KB |
Output is correct |
15 |
Correct |
275 ms |
23380 KB |
Output is correct |
16 |
Correct |
226 ms |
21608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
308 KB |
Output is correct |
2 |
Correct |
439 ms |
67416 KB |
Output is correct |
3 |
Correct |
393 ms |
77948 KB |
Output is correct |
4 |
Correct |
416 ms |
77512 KB |
Output is correct |
5 |
Correct |
338 ms |
61536 KB |
Output is correct |
6 |
Correct |
139 ms |
29704 KB |
Output is correct |
7 |
Correct |
230 ms |
37624 KB |
Output is correct |
8 |
Correct |
224 ms |
25464 KB |
Output is correct |
9 |
Correct |
243 ms |
24116 KB |
Output is correct |
10 |
Correct |
90 ms |
16992 KB |
Output is correct |
11 |
Correct |
184 ms |
27948 KB |
Output is correct |
12 |
Correct |
410 ms |
67500 KB |
Output is correct |
13 |
Correct |
401 ms |
77868 KB |
Output is correct |
14 |
Correct |
418 ms |
77556 KB |
Output is correct |
15 |
Correct |
343 ms |
61568 KB |
Output is correct |
16 |
Correct |
126 ms |
27728 KB |
Output is correct |
17 |
Correct |
253 ms |
41120 KB |
Output is correct |
18 |
Correct |
561 ms |
81744 KB |
Output is correct |
19 |
Correct |
360 ms |
67572 KB |
Output is correct |
20 |
Correct |
375 ms |
69920 KB |
Output is correct |
21 |
Correct |
231 ms |
25500 KB |
Output is correct |
22 |
Correct |
249 ms |
24204 KB |
Output is correct |
23 |
Correct |
88 ms |
16968 KB |
Output is correct |
24 |
Correct |
183 ms |
27956 KB |
Output is correct |
25 |
Correct |
421 ms |
67432 KB |
Output is correct |
26 |
Correct |
408 ms |
77828 KB |
Output is correct |
27 |
Correct |
409 ms |
77496 KB |
Output is correct |
28 |
Correct |
362 ms |
61484 KB |
Output is correct |
29 |
Correct |
137 ms |
27628 KB |
Output is correct |
30 |
Correct |
242 ms |
41244 KB |
Output is correct |
31 |
Correct |
524 ms |
81620 KB |
Output is correct |
32 |
Correct |
351 ms |
67496 KB |
Output is correct |
33 |
Correct |
374 ms |
69872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
320 KB |
Output is correct |
2 |
Correct |
6 ms |
596 KB |
Output is correct |
3 |
Correct |
3 ms |
320 KB |
Output is correct |
4 |
Correct |
3 ms |
340 KB |
Output is correct |
5 |
Correct |
6 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
3 ms |
444 KB |
Output is correct |
12 |
Correct |
4 ms |
468 KB |
Output is correct |
13 |
Correct |
6 ms |
852 KB |
Output is correct |
14 |
Correct |
8 ms |
980 KB |
Output is correct |
15 |
Correct |
1 ms |
308 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
907 ms |
25480 KB |
Output is correct |
19 |
Correct |
249 ms |
4640 KB |
Output is correct |
20 |
Correct |
177 ms |
3796 KB |
Output is correct |
21 |
Correct |
214 ms |
4080 KB |
Output is correct |
22 |
Correct |
235 ms |
4224 KB |
Output is correct |
23 |
Correct |
231 ms |
4556 KB |
Output is correct |
24 |
Correct |
216 ms |
4044 KB |
Output is correct |
25 |
Correct |
258 ms |
4208 KB |
Output is correct |
26 |
Correct |
237 ms |
4404 KB |
Output is correct |
27 |
Correct |
460 ms |
20456 KB |
Output is correct |
28 |
Correct |
340 ms |
12432 KB |
Output is correct |
29 |
Correct |
383 ms |
18892 KB |
Output is correct |
30 |
Correct |
817 ms |
47520 KB |
Output is correct |
31 |
Correct |
4 ms |
340 KB |
Output is correct |
32 |
Correct |
642 ms |
21888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
320 KB |
Output is correct |
2 |
Correct |
6 ms |
596 KB |
Output is correct |
3 |
Correct |
3 ms |
320 KB |
Output is correct |
4 |
Correct |
3 ms |
340 KB |
Output is correct |
5 |
Correct |
6 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
3 ms |
444 KB |
Output is correct |
12 |
Correct |
4 ms |
468 KB |
Output is correct |
13 |
Correct |
6 ms |
852 KB |
Output is correct |
14 |
Correct |
8 ms |
980 KB |
Output is correct |
15 |
Correct |
1 ms |
308 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
907 ms |
25480 KB |
Output is correct |
19 |
Correct |
249 ms |
4640 KB |
Output is correct |
20 |
Correct |
177 ms |
3796 KB |
Output is correct |
21 |
Correct |
214 ms |
4080 KB |
Output is correct |
22 |
Correct |
235 ms |
4224 KB |
Output is correct |
23 |
Correct |
231 ms |
4556 KB |
Output is correct |
24 |
Correct |
216 ms |
4044 KB |
Output is correct |
25 |
Correct |
258 ms |
4208 KB |
Output is correct |
26 |
Correct |
237 ms |
4404 KB |
Output is correct |
27 |
Correct |
460 ms |
20456 KB |
Output is correct |
28 |
Correct |
340 ms |
12432 KB |
Output is correct |
29 |
Correct |
383 ms |
18892 KB |
Output is correct |
30 |
Correct |
817 ms |
47520 KB |
Output is correct |
31 |
Correct |
4 ms |
340 KB |
Output is correct |
32 |
Correct |
642 ms |
21888 KB |
Output is correct |
33 |
Correct |
439 ms |
67416 KB |
Output is correct |
34 |
Correct |
393 ms |
77948 KB |
Output is correct |
35 |
Correct |
416 ms |
77512 KB |
Output is correct |
36 |
Correct |
338 ms |
61536 KB |
Output is correct |
37 |
Correct |
139 ms |
29704 KB |
Output is correct |
38 |
Correct |
230 ms |
37624 KB |
Output is correct |
39 |
Correct |
224 ms |
25464 KB |
Output is correct |
40 |
Correct |
243 ms |
24116 KB |
Output is correct |
41 |
Correct |
90 ms |
16992 KB |
Output is correct |
42 |
Correct |
184 ms |
27948 KB |
Output is correct |
43 |
Correct |
410 ms |
67500 KB |
Output is correct |
44 |
Correct |
401 ms |
77868 KB |
Output is correct |
45 |
Correct |
418 ms |
77556 KB |
Output is correct |
46 |
Correct |
343 ms |
61568 KB |
Output is correct |
47 |
Correct |
126 ms |
27728 KB |
Output is correct |
48 |
Correct |
253 ms |
41120 KB |
Output is correct |
49 |
Correct |
561 ms |
81744 KB |
Output is correct |
50 |
Correct |
360 ms |
67572 KB |
Output is correct |
51 |
Correct |
375 ms |
69920 KB |
Output is correct |
52 |
Correct |
231 ms |
25500 KB |
Output is correct |
53 |
Correct |
249 ms |
24204 KB |
Output is correct |
54 |
Correct |
88 ms |
16968 KB |
Output is correct |
55 |
Correct |
183 ms |
27956 KB |
Output is correct |
56 |
Correct |
421 ms |
67432 KB |
Output is correct |
57 |
Correct |
408 ms |
77828 KB |
Output is correct |
58 |
Correct |
409 ms |
77496 KB |
Output is correct |
59 |
Correct |
362 ms |
61484 KB |
Output is correct |
60 |
Correct |
137 ms |
27628 KB |
Output is correct |
61 |
Correct |
242 ms |
41244 KB |
Output is correct |
62 |
Correct |
524 ms |
81620 KB |
Output is correct |
63 |
Correct |
351 ms |
67496 KB |
Output is correct |
64 |
Correct |
374 ms |
69872 KB |
Output is correct |
65 |
Correct |
213 ms |
20064 KB |
Output is correct |
66 |
Correct |
299 ms |
30460 KB |
Output is correct |
67 |
Correct |
300 ms |
30176 KB |
Output is correct |
68 |
Correct |
274 ms |
23436 KB |
Output is correct |
69 |
Correct |
280 ms |
22548 KB |
Output is correct |
70 |
Correct |
58 ms |
3924 KB |
Output is correct |
71 |
Correct |
320 ms |
30348 KB |
Output is correct |
72 |
Correct |
302 ms |
30036 KB |
Output is correct |
73 |
Correct |
295 ms |
23428 KB |
Output is correct |
74 |
Correct |
259 ms |
29508 KB |
Output is correct |
75 |
Correct |
247 ms |
30400 KB |
Output is correct |
76 |
Correct |
236 ms |
30080 KB |
Output is correct |
77 |
Correct |
275 ms |
23380 KB |
Output is correct |
78 |
Correct |
226 ms |
21608 KB |
Output is correct |
79 |
Correct |
533 ms |
28944 KB |
Output is correct |
80 |
Correct |
585 ms |
27444 KB |
Output is correct |
81 |
Correct |
369 ms |
20364 KB |
Output is correct |
82 |
Correct |
498 ms |
31300 KB |
Output is correct |
83 |
Correct |
665 ms |
71088 KB |
Output is correct |
84 |
Correct |
808 ms |
81396 KB |
Output is correct |
85 |
Correct |
726 ms |
81292 KB |
Output is correct |
86 |
Correct |
667 ms |
64972 KB |
Output is correct |
87 |
Correct |
360 ms |
31228 KB |
Output is correct |
88 |
Correct |
430 ms |
44652 KB |
Output is correct |
89 |
Correct |
757 ms |
85052 KB |
Output is correct |
90 |
Correct |
699 ms |
70980 KB |
Output is correct |
91 |
Correct |
588 ms |
73500 KB |
Output is correct |