#include <bits/stdc++.h>
using namespace std;
const int mx = 2e5 + 5;
struct persistentSegTree{
int idx = 1, root[mx], seg[mx * 31], lc[mx * 31], rc[mx * 31]; set<int> pos[mx];
void add(int r, int c){
pos[r].insert(c);
}
void init(){
for (int i = 0; i < mx; i++){
root[i] = !i ? 0 : root[i - 1];
for (int j : pos[i]) upd(j, 1, root[i]);
}
}
void dup(int &i){
lc[idx] = lc[i];
rc[idx] = rc[i];
seg[idx] = seg[i];
i = idx; idx++;
}
void upd(int p, int val, int &i, int l = 0, int r = 2e5){
dup(i);
if (l == r){ seg[i] += val; return; }
int mid = (l + r) / 2;
if (p <= mid) upd(p, val, lc[i], l, mid);
else upd(p, val, rc[i], mid + 1, r);
seg[i] = seg[lc[i]] + seg[rc[i]];
}
int qry(int ql, int qr, int i, int l = 0, int r = 2e5){
if (qr < l or ql > r or !i) return 0;
if (l >= ql and r <= qr) return seg[i];
int mid = (l + r) / 2;
return qry(ql, qr, lc[i], l, mid) + qry(ql, qr, rc[i], mid + 1, r);
}
int rectQry(int ar, int ac, int br, int bc){
return qry(ac, bc, root[br]) - qry(ac, bc, root[ar - 1]);
}
};
int mnr = 1e9, mxr, mnc = 1e9, mxc; persistentSegTree rivers, nodes, topEdg, leftEdg;
void init(int R, int C, int sr, int sc, int m, char *S){
auto addRiver = [&](int r, int c){
rivers.add(r, c);
nodes.add(r, c);
nodes.add(r, c + 1);
nodes.add(r + 1, c);
nodes.add(r + 1, c + 1);
topEdg.add(r, c);
topEdg.add(r + 1, c);
leftEdg.add(r, c);
leftEdg.add(r, c + 1);
mnr = min(mnr, r);
mxr = max(mxr, r);
mnc = min(mnc, c);
mxc = max(mxc, c);
};
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);
}
rivers.init();
nodes.init();
topEdg.init();
leftEdg.init();
}
int colour(int ar, int ac, int br, int bc){
int n = br - ar + 1;
int m = bc - ac + 1;
int C = (ar < mnr and br > mxr and ac < mnc and bc > mxc) ? 2 : 1;
int V = 2 * (n + m) + nodes.rectQry(ar + 1, ac + 1, br, bc);
int E = topEdg.rectQry(ar + 1, ac, br, bc) + leftEdg.rectQry(ar, ac + 1, br, bc) + 2 * (n + m);
int F = E - V + C + 1;
return F - rivers.rectQry(ar, ac, br, bc) - 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
41352 KB |
Output is correct |
2 |
Correct |
26 ms |
42292 KB |
Output is correct |
3 |
Correct |
25 ms |
41596 KB |
Output is correct |
4 |
Correct |
24 ms |
41500 KB |
Output is correct |
5 |
Correct |
26 ms |
42584 KB |
Output is correct |
6 |
Correct |
20 ms |
41044 KB |
Output is correct |
7 |
Correct |
22 ms |
41036 KB |
Output is correct |
8 |
Correct |
22 ms |
41104 KB |
Output is correct |
9 |
Correct |
22 ms |
40988 KB |
Output is correct |
10 |
Correct |
23 ms |
41036 KB |
Output is correct |
11 |
Correct |
25 ms |
41588 KB |
Output is correct |
12 |
Correct |
25 ms |
42060 KB |
Output is correct |
13 |
Correct |
27 ms |
43184 KB |
Output is correct |
14 |
Correct |
32 ms |
43808 KB |
Output is correct |
15 |
Correct |
22 ms |
41100 KB |
Output is correct |
16 |
Correct |
23 ms |
40968 KB |
Output is correct |
17 |
Correct |
22 ms |
41012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
40968 KB |
Output is correct |
2 |
Correct |
22 ms |
41012 KB |
Output is correct |
3 |
Correct |
428 ms |
139952 KB |
Output is correct |
4 |
Correct |
638 ms |
204572 KB |
Output is correct |
5 |
Correct |
662 ms |
203304 KB |
Output is correct |
6 |
Correct |
528 ms |
166760 KB |
Output is correct |
7 |
Correct |
684 ms |
164700 KB |
Output is correct |
8 |
Correct |
96 ms |
44740 KB |
Output is correct |
9 |
Correct |
648 ms |
204560 KB |
Output is correct |
10 |
Correct |
673 ms |
203120 KB |
Output is correct |
11 |
Correct |
555 ms |
166604 KB |
Output is correct |
12 |
Correct |
404 ms |
193216 KB |
Output is correct |
13 |
Correct |
433 ms |
204376 KB |
Output is correct |
14 |
Correct |
461 ms |
203132 KB |
Output is correct |
15 |
Correct |
440 ms |
166976 KB |
Output is correct |
16 |
Correct |
468 ms |
157628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
41100 KB |
Output is correct |
2 |
Correct |
387 ms |
201124 KB |
Output is correct |
3 |
Correct |
191 ms |
198668 KB |
Output is correct |
4 |
Correct |
209 ms |
201168 KB |
Output is correct |
5 |
Correct |
197 ms |
159940 KB |
Output is correct |
6 |
Correct |
94 ms |
71244 KB |
Output is correct |
7 |
Correct |
159 ms |
100880 KB |
Output is correct |
8 |
Correct |
314 ms |
183792 KB |
Output is correct |
9 |
Correct |
293 ms |
167756 KB |
Output is correct |
10 |
Correct |
106 ms |
72768 KB |
Output is correct |
11 |
Correct |
178 ms |
119500 KB |
Output is correct |
12 |
Correct |
371 ms |
201104 KB |
Output is correct |
13 |
Correct |
190 ms |
198564 KB |
Output is correct |
14 |
Correct |
209 ms |
201064 KB |
Output is correct |
15 |
Correct |
206 ms |
159772 KB |
Output is correct |
16 |
Correct |
92 ms |
65144 KB |
Output is correct |
17 |
Correct |
145 ms |
100988 KB |
Output is correct |
18 |
Correct |
279 ms |
201156 KB |
Output is correct |
19 |
Correct |
281 ms |
202252 KB |
Output is correct |
20 |
Correct |
284 ms |
202084 KB |
Output is correct |
21 |
Correct |
314 ms |
183912 KB |
Output is correct |
22 |
Correct |
299 ms |
167832 KB |
Output is correct |
23 |
Correct |
101 ms |
72756 KB |
Output is correct |
24 |
Correct |
185 ms |
119536 KB |
Output is correct |
25 |
Correct |
375 ms |
201080 KB |
Output is correct |
26 |
Correct |
192 ms |
198680 KB |
Output is correct |
27 |
Correct |
210 ms |
201100 KB |
Output is correct |
28 |
Correct |
189 ms |
159824 KB |
Output is correct |
29 |
Correct |
89 ms |
65028 KB |
Output is correct |
30 |
Correct |
147 ms |
100940 KB |
Output is correct |
31 |
Correct |
271 ms |
201056 KB |
Output is correct |
32 |
Correct |
277 ms |
202080 KB |
Output is correct |
33 |
Correct |
276 ms |
202060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
41352 KB |
Output is correct |
2 |
Correct |
26 ms |
42292 KB |
Output is correct |
3 |
Correct |
25 ms |
41596 KB |
Output is correct |
4 |
Correct |
24 ms |
41500 KB |
Output is correct |
5 |
Correct |
26 ms |
42584 KB |
Output is correct |
6 |
Correct |
20 ms |
41044 KB |
Output is correct |
7 |
Correct |
22 ms |
41036 KB |
Output is correct |
8 |
Correct |
22 ms |
41104 KB |
Output is correct |
9 |
Correct |
22 ms |
40988 KB |
Output is correct |
10 |
Correct |
23 ms |
41036 KB |
Output is correct |
11 |
Correct |
25 ms |
41588 KB |
Output is correct |
12 |
Correct |
25 ms |
42060 KB |
Output is correct |
13 |
Correct |
27 ms |
43184 KB |
Output is correct |
14 |
Correct |
32 ms |
43808 KB |
Output is correct |
15 |
Correct |
22 ms |
41100 KB |
Output is correct |
16 |
Correct |
23 ms |
40968 KB |
Output is correct |
17 |
Correct |
22 ms |
41012 KB |
Output is correct |
18 |
Correct |
741 ms |
125536 KB |
Output is correct |
19 |
Correct |
222 ms |
48156 KB |
Output is correct |
20 |
Correct |
175 ms |
45068 KB |
Output is correct |
21 |
Correct |
187 ms |
45744 KB |
Output is correct |
22 |
Correct |
200 ms |
46520 KB |
Output is correct |
23 |
Correct |
224 ms |
47948 KB |
Output is correct |
24 |
Correct |
177 ms |
45516 KB |
Output is correct |
25 |
Correct |
196 ms |
46284 KB |
Output is correct |
26 |
Correct |
201 ms |
46812 KB |
Output is correct |
27 |
Correct |
291 ms |
109804 KB |
Output is correct |
28 |
Correct |
237 ms |
75892 KB |
Output is correct |
29 |
Correct |
293 ms |
104236 KB |
Output is correct |
30 |
Correct |
568 ms |
204496 KB |
Output is correct |
31 |
Correct |
27 ms |
41164 KB |
Output is correct |
32 |
Correct |
562 ms |
110636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
41352 KB |
Output is correct |
2 |
Correct |
26 ms |
42292 KB |
Output is correct |
3 |
Correct |
25 ms |
41596 KB |
Output is correct |
4 |
Correct |
24 ms |
41500 KB |
Output is correct |
5 |
Correct |
26 ms |
42584 KB |
Output is correct |
6 |
Correct |
20 ms |
41044 KB |
Output is correct |
7 |
Correct |
22 ms |
41036 KB |
Output is correct |
8 |
Correct |
22 ms |
41104 KB |
Output is correct |
9 |
Correct |
22 ms |
40988 KB |
Output is correct |
10 |
Correct |
23 ms |
41036 KB |
Output is correct |
11 |
Correct |
25 ms |
41588 KB |
Output is correct |
12 |
Correct |
25 ms |
42060 KB |
Output is correct |
13 |
Correct |
27 ms |
43184 KB |
Output is correct |
14 |
Correct |
32 ms |
43808 KB |
Output is correct |
15 |
Correct |
22 ms |
41100 KB |
Output is correct |
16 |
Correct |
23 ms |
40968 KB |
Output is correct |
17 |
Correct |
22 ms |
41012 KB |
Output is correct |
18 |
Correct |
741 ms |
125536 KB |
Output is correct |
19 |
Correct |
222 ms |
48156 KB |
Output is correct |
20 |
Correct |
175 ms |
45068 KB |
Output is correct |
21 |
Correct |
187 ms |
45744 KB |
Output is correct |
22 |
Correct |
200 ms |
46520 KB |
Output is correct |
23 |
Correct |
224 ms |
47948 KB |
Output is correct |
24 |
Correct |
177 ms |
45516 KB |
Output is correct |
25 |
Correct |
196 ms |
46284 KB |
Output is correct |
26 |
Correct |
201 ms |
46812 KB |
Output is correct |
27 |
Correct |
291 ms |
109804 KB |
Output is correct |
28 |
Correct |
237 ms |
75892 KB |
Output is correct |
29 |
Correct |
293 ms |
104236 KB |
Output is correct |
30 |
Correct |
568 ms |
204496 KB |
Output is correct |
31 |
Correct |
27 ms |
41164 KB |
Output is correct |
32 |
Correct |
562 ms |
110636 KB |
Output is correct |
33 |
Correct |
387 ms |
201124 KB |
Output is correct |
34 |
Correct |
191 ms |
198668 KB |
Output is correct |
35 |
Correct |
209 ms |
201168 KB |
Output is correct |
36 |
Correct |
197 ms |
159940 KB |
Output is correct |
37 |
Correct |
94 ms |
71244 KB |
Output is correct |
38 |
Correct |
159 ms |
100880 KB |
Output is correct |
39 |
Correct |
314 ms |
183792 KB |
Output is correct |
40 |
Correct |
293 ms |
167756 KB |
Output is correct |
41 |
Correct |
106 ms |
72768 KB |
Output is correct |
42 |
Correct |
178 ms |
119500 KB |
Output is correct |
43 |
Correct |
371 ms |
201104 KB |
Output is correct |
44 |
Correct |
190 ms |
198564 KB |
Output is correct |
45 |
Correct |
209 ms |
201064 KB |
Output is correct |
46 |
Correct |
206 ms |
159772 KB |
Output is correct |
47 |
Correct |
92 ms |
65144 KB |
Output is correct |
48 |
Correct |
145 ms |
100988 KB |
Output is correct |
49 |
Correct |
279 ms |
201156 KB |
Output is correct |
50 |
Correct |
281 ms |
202252 KB |
Output is correct |
51 |
Correct |
284 ms |
202084 KB |
Output is correct |
52 |
Correct |
314 ms |
183912 KB |
Output is correct |
53 |
Correct |
299 ms |
167832 KB |
Output is correct |
54 |
Correct |
101 ms |
72756 KB |
Output is correct |
55 |
Correct |
185 ms |
119536 KB |
Output is correct |
56 |
Correct |
375 ms |
201080 KB |
Output is correct |
57 |
Correct |
192 ms |
198680 KB |
Output is correct |
58 |
Correct |
210 ms |
201100 KB |
Output is correct |
59 |
Correct |
189 ms |
159824 KB |
Output is correct |
60 |
Correct |
89 ms |
65028 KB |
Output is correct |
61 |
Correct |
147 ms |
100940 KB |
Output is correct |
62 |
Correct |
271 ms |
201056 KB |
Output is correct |
63 |
Correct |
277 ms |
202080 KB |
Output is correct |
64 |
Correct |
276 ms |
202060 KB |
Output is correct |
65 |
Correct |
428 ms |
139952 KB |
Output is correct |
66 |
Correct |
638 ms |
204572 KB |
Output is correct |
67 |
Correct |
662 ms |
203304 KB |
Output is correct |
68 |
Correct |
528 ms |
166760 KB |
Output is correct |
69 |
Correct |
684 ms |
164700 KB |
Output is correct |
70 |
Correct |
96 ms |
44740 KB |
Output is correct |
71 |
Correct |
648 ms |
204560 KB |
Output is correct |
72 |
Correct |
673 ms |
203120 KB |
Output is correct |
73 |
Correct |
555 ms |
166604 KB |
Output is correct |
74 |
Correct |
404 ms |
193216 KB |
Output is correct |
75 |
Correct |
433 ms |
204376 KB |
Output is correct |
76 |
Correct |
461 ms |
203132 KB |
Output is correct |
77 |
Correct |
440 ms |
166976 KB |
Output is correct |
78 |
Correct |
468 ms |
157628 KB |
Output is correct |
79 |
Correct |
1045 ms |
187260 KB |
Output is correct |
80 |
Correct |
1028 ms |
171436 KB |
Output is correct |
81 |
Correct |
349 ms |
76136 KB |
Output is correct |
82 |
Correct |
361 ms |
122924 KB |
Output is correct |
83 |
Correct |
631 ms |
204628 KB |
Output is correct |
84 |
Correct |
307 ms |
202176 KB |
Output is correct |
85 |
Correct |
368 ms |
204548 KB |
Output is correct |
86 |
Correct |
321 ms |
163404 KB |
Output is correct |
87 |
Correct |
148 ms |
68524 KB |
Output is correct |
88 |
Correct |
213 ms |
104440 KB |
Output is correct |
89 |
Correct |
337 ms |
204664 KB |
Output is correct |
90 |
Correct |
504 ms |
205760 KB |
Output is correct |
91 |
Correct |
483 ms |
205516 KB |
Output is correct |