#include "rainbow.h"
#include <vector>
#include <algorithm>
using namespace std;
#define ll long long
const int MX = 2e5 + 5;
struct segmentTree{
vector<int> st[MX * 2 + 5];
void upd(int ps, int val){
st[ps + MX].push_back(val);
}
void proc(){
for(int i = MX; i < 2 * MX; i ++){
sort(st[i].begin(), st[i].end());
st[i].erase(unique(st[i].begin(), st[i].end()), st[i].end());
}
for(int i = MX - 1; i > 0; i --){
st[i] = vector<int>(st[i * 2].size() + st[i * 2 + 1].size());
merge(st[i * 2].begin(), st[i * 2].end(), st[i * 2 + 1].begin(), st[i * 2 + 1].end(), st[i].begin());
}
}
int que(int lf, int rg, int x, int y){
int ans = 0;
for(lf += MX, rg += MX + 1; lf < rg; lf /= 2, rg /= 2){
if(lf % 2)
ans += upper_bound(st[lf].begin(), st[lf].end(), y) - lower_bound(st[lf].begin(), st[lf].end(), x), lf ++;
if(rg % 2)
rg --, ans += upper_bound(st[rg].begin(), st[rg].end(), y) - lower_bound(st[rg].begin(), st[rg].end(), x);
}
return ans;
}
} vertex, hori, verti, face;
int totalRivers = 0;
void addRiver(int x, int y){
vertex.upd(x, y);
hori.upd(x, y - 1); hori.upd(x, y);
verti.upd(y, x - 1); verti.upd(y, x);
face.upd(x - 1, y - 1); face.upd(x, y - 1); face.upd(x - 1, y); face.upd(x, y);
}
void init(int R, int C, int sr, int sc, int M, char *s) {
addRiver(sr, sc);
for(int i = 0; i < M; i ++){
if(s[i] == 'N') sr --;
if(s[i] == 'S') sr ++;
if(s[i] == 'E') sc ++;
if(s[i] == 'W') sc --;
addRiver(sr, sc);
}
vertex.proc(); hori.proc(); verti.proc(); face.proc();
totalRivers = vertex.que(0, MX - 1, 0, MX - 1);
}
int colour(int ar, int ac, int br, int bc) {
ll H = br - ar + 1, W = bc - ac + 1;
ll V = H * W - vertex.que(ar, br, ac, bc);
ll E = (H - 1) * W + (W - 1) * H - hori.que(ar, br, ac, bc - 1) - verti.que(ac, bc, ar, br - 1);
ll F = (H - 1) * (W - 1) - face.que(ar, br - 1, ac, bc - 1);
if(vertex.que(ar + 1, br - 1, ac + 1, bc - 1) == totalRivers) F ++;
return V - E + F;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
37880 KB |
Output is correct |
2 |
Correct |
26 ms |
38256 KB |
Output is correct |
3 |
Correct |
25 ms |
37964 KB |
Output is correct |
4 |
Correct |
27 ms |
38000 KB |
Output is correct |
5 |
Correct |
28 ms |
38380 KB |
Output is correct |
6 |
Correct |
25 ms |
37840 KB |
Output is correct |
7 |
Correct |
24 ms |
37860 KB |
Output is correct |
8 |
Correct |
24 ms |
37872 KB |
Output is correct |
9 |
Correct |
24 ms |
37844 KB |
Output is correct |
10 |
Correct |
25 ms |
37844 KB |
Output is correct |
11 |
Correct |
28 ms |
37996 KB |
Output is correct |
12 |
Correct |
30 ms |
38216 KB |
Output is correct |
13 |
Correct |
38 ms |
38444 KB |
Output is correct |
14 |
Correct |
29 ms |
38652 KB |
Output is correct |
15 |
Correct |
29 ms |
37852 KB |
Output is correct |
16 |
Correct |
24 ms |
37864 KB |
Output is correct |
17 |
Correct |
32 ms |
37840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
37864 KB |
Output is correct |
2 |
Correct |
32 ms |
37840 KB |
Output is correct |
3 |
Correct |
264 ms |
69632 KB |
Output is correct |
4 |
Correct |
380 ms |
89040 KB |
Output is correct |
5 |
Correct |
331 ms |
88280 KB |
Output is correct |
6 |
Correct |
232 ms |
77180 KB |
Output is correct |
7 |
Correct |
315 ms |
76824 KB |
Output is correct |
8 |
Correct |
128 ms |
45716 KB |
Output is correct |
9 |
Correct |
369 ms |
89084 KB |
Output is correct |
10 |
Correct |
366 ms |
88284 KB |
Output is correct |
11 |
Correct |
282 ms |
77196 KB |
Output is correct |
12 |
Correct |
152 ms |
85752 KB |
Output is correct |
13 |
Correct |
173 ms |
89092 KB |
Output is correct |
14 |
Correct |
163 ms |
88232 KB |
Output is correct |
15 |
Correct |
158 ms |
77276 KB |
Output is correct |
16 |
Correct |
292 ms |
75000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
37852 KB |
Output is correct |
2 |
Correct |
74 ms |
87716 KB |
Output is correct |
3 |
Correct |
107 ms |
95280 KB |
Output is correct |
4 |
Correct |
107 ms |
87936 KB |
Output is correct |
5 |
Correct |
99 ms |
78772 KB |
Output is correct |
6 |
Correct |
60 ms |
50928 KB |
Output is correct |
7 |
Correct |
66 ms |
58676 KB |
Output is correct |
8 |
Correct |
78 ms |
78952 KB |
Output is correct |
9 |
Correct |
85 ms |
74824 KB |
Output is correct |
10 |
Correct |
57 ms |
48456 KB |
Output is correct |
11 |
Correct |
86 ms |
63340 KB |
Output is correct |
12 |
Correct |
74 ms |
87720 KB |
Output is correct |
13 |
Correct |
104 ms |
95292 KB |
Output is correct |
14 |
Correct |
96 ms |
87724 KB |
Output is correct |
15 |
Correct |
110 ms |
78808 KB |
Output is correct |
16 |
Correct |
69 ms |
49076 KB |
Output is correct |
17 |
Correct |
67 ms |
57996 KB |
Output is correct |
18 |
Correct |
77 ms |
82940 KB |
Output is correct |
19 |
Correct |
93 ms |
89320 KB |
Output is correct |
20 |
Correct |
103 ms |
89324 KB |
Output is correct |
21 |
Correct |
84 ms |
79016 KB |
Output is correct |
22 |
Correct |
78 ms |
74892 KB |
Output is correct |
23 |
Correct |
48 ms |
48428 KB |
Output is correct |
24 |
Correct |
70 ms |
63380 KB |
Output is correct |
25 |
Correct |
81 ms |
87708 KB |
Output is correct |
26 |
Correct |
124 ms |
95356 KB |
Output is correct |
27 |
Correct |
89 ms |
87796 KB |
Output is correct |
28 |
Correct |
86 ms |
78816 KB |
Output is correct |
29 |
Correct |
68 ms |
48988 KB |
Output is correct |
30 |
Correct |
74 ms |
58064 KB |
Output is correct |
31 |
Correct |
77 ms |
82960 KB |
Output is correct |
32 |
Correct |
101 ms |
89296 KB |
Output is correct |
33 |
Correct |
93 ms |
89288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
37880 KB |
Output is correct |
2 |
Correct |
26 ms |
38256 KB |
Output is correct |
3 |
Correct |
25 ms |
37964 KB |
Output is correct |
4 |
Correct |
27 ms |
38000 KB |
Output is correct |
5 |
Correct |
28 ms |
38380 KB |
Output is correct |
6 |
Correct |
25 ms |
37840 KB |
Output is correct |
7 |
Correct |
24 ms |
37860 KB |
Output is correct |
8 |
Correct |
24 ms |
37872 KB |
Output is correct |
9 |
Correct |
24 ms |
37844 KB |
Output is correct |
10 |
Correct |
25 ms |
37844 KB |
Output is correct |
11 |
Correct |
28 ms |
37996 KB |
Output is correct |
12 |
Correct |
30 ms |
38216 KB |
Output is correct |
13 |
Correct |
38 ms |
38444 KB |
Output is correct |
14 |
Correct |
29 ms |
38652 KB |
Output is correct |
15 |
Correct |
29 ms |
37852 KB |
Output is correct |
16 |
Correct |
24 ms |
37864 KB |
Output is correct |
17 |
Correct |
32 ms |
37840 KB |
Output is correct |
18 |
Correct |
891 ms |
66536 KB |
Output is correct |
19 |
Correct |
219 ms |
42324 KB |
Output is correct |
20 |
Correct |
170 ms |
41544 KB |
Output is correct |
21 |
Correct |
194 ms |
41660 KB |
Output is correct |
22 |
Correct |
227 ms |
41876 KB |
Output is correct |
23 |
Correct |
215 ms |
42192 KB |
Output is correct |
24 |
Correct |
243 ms |
41648 KB |
Output is correct |
25 |
Correct |
235 ms |
41884 KB |
Output is correct |
26 |
Correct |
228 ms |
42076 KB |
Output is correct |
27 |
Correct |
399 ms |
62676 KB |
Output is correct |
28 |
Correct |
355 ms |
54340 KB |
Output is correct |
29 |
Correct |
397 ms |
61404 KB |
Output is correct |
30 |
Correct |
641 ms |
86404 KB |
Output is correct |
31 |
Correct |
35 ms |
37972 KB |
Output is correct |
32 |
Correct |
710 ms |
62672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
37880 KB |
Output is correct |
2 |
Correct |
26 ms |
38256 KB |
Output is correct |
3 |
Correct |
25 ms |
37964 KB |
Output is correct |
4 |
Correct |
27 ms |
38000 KB |
Output is correct |
5 |
Correct |
28 ms |
38380 KB |
Output is correct |
6 |
Correct |
25 ms |
37840 KB |
Output is correct |
7 |
Correct |
24 ms |
37860 KB |
Output is correct |
8 |
Correct |
24 ms |
37872 KB |
Output is correct |
9 |
Correct |
24 ms |
37844 KB |
Output is correct |
10 |
Correct |
25 ms |
37844 KB |
Output is correct |
11 |
Correct |
28 ms |
37996 KB |
Output is correct |
12 |
Correct |
30 ms |
38216 KB |
Output is correct |
13 |
Correct |
38 ms |
38444 KB |
Output is correct |
14 |
Correct |
29 ms |
38652 KB |
Output is correct |
15 |
Correct |
29 ms |
37852 KB |
Output is correct |
16 |
Correct |
24 ms |
37864 KB |
Output is correct |
17 |
Correct |
32 ms |
37840 KB |
Output is correct |
18 |
Correct |
891 ms |
66536 KB |
Output is correct |
19 |
Correct |
219 ms |
42324 KB |
Output is correct |
20 |
Correct |
170 ms |
41544 KB |
Output is correct |
21 |
Correct |
194 ms |
41660 KB |
Output is correct |
22 |
Correct |
227 ms |
41876 KB |
Output is correct |
23 |
Correct |
215 ms |
42192 KB |
Output is correct |
24 |
Correct |
243 ms |
41648 KB |
Output is correct |
25 |
Correct |
235 ms |
41884 KB |
Output is correct |
26 |
Correct |
228 ms |
42076 KB |
Output is correct |
27 |
Correct |
399 ms |
62676 KB |
Output is correct |
28 |
Correct |
355 ms |
54340 KB |
Output is correct |
29 |
Correct |
397 ms |
61404 KB |
Output is correct |
30 |
Correct |
641 ms |
86404 KB |
Output is correct |
31 |
Correct |
35 ms |
37972 KB |
Output is correct |
32 |
Correct |
710 ms |
62672 KB |
Output is correct |
33 |
Correct |
74 ms |
87716 KB |
Output is correct |
34 |
Correct |
107 ms |
95280 KB |
Output is correct |
35 |
Correct |
107 ms |
87936 KB |
Output is correct |
36 |
Correct |
99 ms |
78772 KB |
Output is correct |
37 |
Correct |
60 ms |
50928 KB |
Output is correct |
38 |
Correct |
66 ms |
58676 KB |
Output is correct |
39 |
Correct |
78 ms |
78952 KB |
Output is correct |
40 |
Correct |
85 ms |
74824 KB |
Output is correct |
41 |
Correct |
57 ms |
48456 KB |
Output is correct |
42 |
Correct |
86 ms |
63340 KB |
Output is correct |
43 |
Correct |
74 ms |
87720 KB |
Output is correct |
44 |
Correct |
104 ms |
95292 KB |
Output is correct |
45 |
Correct |
96 ms |
87724 KB |
Output is correct |
46 |
Correct |
110 ms |
78808 KB |
Output is correct |
47 |
Correct |
69 ms |
49076 KB |
Output is correct |
48 |
Correct |
67 ms |
57996 KB |
Output is correct |
49 |
Correct |
77 ms |
82940 KB |
Output is correct |
50 |
Correct |
93 ms |
89320 KB |
Output is correct |
51 |
Correct |
103 ms |
89324 KB |
Output is correct |
52 |
Correct |
84 ms |
79016 KB |
Output is correct |
53 |
Correct |
78 ms |
74892 KB |
Output is correct |
54 |
Correct |
48 ms |
48428 KB |
Output is correct |
55 |
Correct |
70 ms |
63380 KB |
Output is correct |
56 |
Correct |
81 ms |
87708 KB |
Output is correct |
57 |
Correct |
124 ms |
95356 KB |
Output is correct |
58 |
Correct |
89 ms |
87796 KB |
Output is correct |
59 |
Correct |
86 ms |
78816 KB |
Output is correct |
60 |
Correct |
68 ms |
48988 KB |
Output is correct |
61 |
Correct |
74 ms |
58064 KB |
Output is correct |
62 |
Correct |
77 ms |
82960 KB |
Output is correct |
63 |
Correct |
101 ms |
89296 KB |
Output is correct |
64 |
Correct |
93 ms |
89288 KB |
Output is correct |
65 |
Correct |
264 ms |
69632 KB |
Output is correct |
66 |
Correct |
380 ms |
89040 KB |
Output is correct |
67 |
Correct |
331 ms |
88280 KB |
Output is correct |
68 |
Correct |
232 ms |
77180 KB |
Output is correct |
69 |
Correct |
315 ms |
76824 KB |
Output is correct |
70 |
Correct |
128 ms |
45716 KB |
Output is correct |
71 |
Correct |
369 ms |
89084 KB |
Output is correct |
72 |
Correct |
366 ms |
88284 KB |
Output is correct |
73 |
Correct |
282 ms |
77196 KB |
Output is correct |
74 |
Correct |
152 ms |
85752 KB |
Output is correct |
75 |
Correct |
173 ms |
89092 KB |
Output is correct |
76 |
Correct |
163 ms |
88232 KB |
Output is correct |
77 |
Correct |
158 ms |
77276 KB |
Output is correct |
78 |
Correct |
292 ms |
75000 KB |
Output is correct |
79 |
Correct |
564 ms |
82368 KB |
Output is correct |
80 |
Correct |
524 ms |
78304 KB |
Output is correct |
81 |
Correct |
371 ms |
51916 KB |
Output is correct |
82 |
Correct |
510 ms |
66728 KB |
Output is correct |
83 |
Correct |
446 ms |
91164 KB |
Output is correct |
84 |
Correct |
607 ms |
98768 KB |
Output is correct |
85 |
Correct |
496 ms |
91480 KB |
Output is correct |
86 |
Correct |
524 ms |
82380 KB |
Output is correct |
87 |
Correct |
294 ms |
52668 KB |
Output is correct |
88 |
Correct |
326 ms |
61612 KB |
Output is correct |
89 |
Correct |
305 ms |
86508 KB |
Output is correct |
90 |
Correct |
600 ms |
92772 KB |
Output is correct |
91 |
Correct |
677 ms |
92872 KB |
Output is correct |