#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
const int mxN=2e5, INF=69696969;
int n, m, lr=INF, rr=-1, lc=INF, rc=-1;
set<int> vis[mxN];
vector<int> row_edge[mxN], col_edge[mxN], faces[mxN];
bool ok(int i, int j) {
return 0<=i&&i<n&&0<=j&&j<m&&vis[i].find(j)==vis[i].end();
}
void consider(int i, int j) {
if (vis[i].find(j)==vis[i].end()) {
lr=min(lr, i), rr=max(rr, i);
lc=min(lc, j), rc=max(rc, j);
if (ok(i, j-1)) row_edge[i].push_back(j-1);
if (ok(i, j+1)) row_edge[i].push_back(j);
if (ok(i-1, j)) col_edge[i-1].push_back(j);
if (ok(i+1, j)) col_edge[i].push_back(j);
for (int a : {i-1, i})
for (int b : {j-1, j})
if (ok(a, b)&&ok(a+1, b)&&ok(a, b+1)&&ok(a+1, b+1))
faces[a].push_back(b);
vis[i].insert(j);
}
}
struct Node {
int s=0;
Node *left=nullptr, *right=nullptr;
Node(int l, int r) {
if (l!=r) {
int mid=(l+r)/2;
left=new Node(l, mid);
right=new Node(mid+1, r);
}
}
Node(int x) : s(x) {}
Node(Node* left, Node* right) : left(left), right(right) { s=left->s+right->s; }
Node* upd(int i, int l, int r) {
if (l>i||r<i) return this;
if (l==r) return new Node(s+1);
int mid=(l+r)/2;
return new Node(left->upd(i, l, mid), right->upd(i, mid+1, r));
}
int qry(int ql, int qr, int l, int r) {
if (l>qr||r<ql) return 0;
if (ql<=l&&r<=qr) return s;
int mid=(l+r)/2;
return left->qry(ql, qr, l, mid)+right->qry(ql, qr, mid+1, r);
}
};
vector<Node*> pv, pre, pce, pf; // prefix vertex, prefix row edge, prefix column edge, prefix face
void init(int R, int C, int sr, int sc, int M, char *S) {
n=R, m=C, --sr, --sc;
consider(sr, sc);
for (int i=0; i<M; ++i) {
if (S[i]=='N'||S[i]=='S') sr+=S[i]=='S'?1:-1;
else sc+=S[i]=='E'?1:-1;
assert(0<=sr&&sr<n&&0<=sc&&sc<m);
consider(sr, sc);
}
Node* cur=new Node(0, m-1);
pv.push_back(cur);
pre.push_back(cur);
pce.push_back(cur);
pf.push_back(cur);
for (int i=0; i<n; ++i) {
cur=pv.back();
for (int j : vis[i]) cur=cur->upd(j, 0, m-1);
pv.push_back(cur);
cur=pre.back();
for (int j : row_edge[i]) cur=cur->upd(j, 0, m-1);
pre.push_back(cur);
cur=pce.back();
for (int j : col_edge[i]) cur=cur->upd(j, 0, m-1);
pce.push_back(cur);
cur=pf.back();
for (int j : faces[i]) cur=cur->upd(j, 0, m-1);
pf.push_back(cur);
}
}
int cnt(vector<Node*>& p, int a, int b, int c, int d) {
return p[c+1]->qry(b, d, 0, m-1)-p[a]->qry(b, d, 0, m-1);
}
int colour(int ar, int ac, int br, int bc) {
--ar, --ac, --br, --bc;
ll v=(ll)(br-ar+1)*(bc-ac+1)-cnt(pv, ar, ac, br, bc);
ll e=(ll)(br-ar+1)*(bc-ac)+(ll)(br-ar)*(bc-ac+1)-cnt(pre, ar, ac, br, bc-1)-cnt(pce, ar, ac, br-1, bc);
ll f=(ll)(br-ar)*(bc-ac)-cnt(pf, ar, ac, br-1, bc-1)+(ar<lr&&rr<br&&ac<lc&&rc<bc);
return v-e+f;
}
/*int main() {
ios::sync_with_stdio(0);
cin.tie(0);
init(6, 4, 3, 3, 9, "NWESSWEWS");
cout << colour(2, 3, 2, 3) << " " << colour(3, 2, 4, 4) << " " << colour(5, 3, 6, 4) << " " << colour(1, 2, 5, 3) << endl;
return 0;
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23892 KB |
Output is correct |
2 |
Correct |
19 ms |
24832 KB |
Output is correct |
3 |
Correct |
16 ms |
24024 KB |
Output is correct |
4 |
Correct |
16 ms |
24116 KB |
Output is correct |
5 |
Correct |
15 ms |
24956 KB |
Output is correct |
6 |
Correct |
12 ms |
23764 KB |
Output is correct |
7 |
Correct |
14 ms |
23764 KB |
Output is correct |
8 |
Correct |
17 ms |
23792 KB |
Output is correct |
9 |
Correct |
14 ms |
23716 KB |
Output is correct |
10 |
Correct |
12 ms |
23788 KB |
Output is correct |
11 |
Correct |
18 ms |
24148 KB |
Output is correct |
12 |
Correct |
15 ms |
24568 KB |
Output is correct |
13 |
Correct |
21 ms |
25428 KB |
Output is correct |
14 |
Correct |
17 ms |
25848 KB |
Output is correct |
15 |
Correct |
13 ms |
23764 KB |
Output is correct |
16 |
Correct |
13 ms |
23764 KB |
Output is correct |
17 |
Correct |
12 ms |
23792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23792 KB |
Output is correct |
3 |
Correct |
606 ms |
182892 KB |
Output is correct |
4 |
Correct |
774 ms |
278632 KB |
Output is correct |
5 |
Correct |
803 ms |
272460 KB |
Output is correct |
6 |
Correct |
631 ms |
207944 KB |
Output is correct |
7 |
Correct |
653 ms |
205224 KB |
Output is correct |
8 |
Correct |
281 ms |
39904 KB |
Output is correct |
9 |
Correct |
782 ms |
278708 KB |
Output is correct |
10 |
Correct |
811 ms |
272368 KB |
Output is correct |
11 |
Correct |
636 ms |
207808 KB |
Output is correct |
12 |
Correct |
428 ms |
262872 KB |
Output is correct |
13 |
Correct |
441 ms |
278540 KB |
Output is correct |
14 |
Correct |
443 ms |
272404 KB |
Output is correct |
15 |
Correct |
362 ms |
208048 KB |
Output is correct |
16 |
Correct |
628 ms |
209448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
Output is correct |
2 |
Correct |
533 ms |
400552 KB |
Output is correct |
3 |
Correct |
481 ms |
401276 KB |
Output is correct |
4 |
Correct |
437 ms |
403224 KB |
Output is correct |
5 |
Correct |
367 ms |
311464 KB |
Output is correct |
6 |
Correct |
118 ms |
110124 KB |
Output is correct |
7 |
Correct |
219 ms |
177352 KB |
Output is correct |
8 |
Correct |
339 ms |
224148 KB |
Output is correct |
9 |
Correct |
314 ms |
207592 KB |
Output is correct |
10 |
Correct |
111 ms |
71692 KB |
Output is correct |
11 |
Correct |
193 ms |
160760 KB |
Output is correct |
12 |
Correct |
510 ms |
400648 KB |
Output is correct |
13 |
Correct |
451 ms |
401264 KB |
Output is correct |
14 |
Correct |
475 ms |
403264 KB |
Output is correct |
15 |
Correct |
373 ms |
311484 KB |
Output is correct |
16 |
Correct |
136 ms |
96560 KB |
Output is correct |
17 |
Correct |
217 ms |
177540 KB |
Output is correct |
18 |
Correct |
461 ms |
400224 KB |
Output is correct |
19 |
Correct |
482 ms |
347572 KB |
Output is correct |
20 |
Correct |
407 ms |
347404 KB |
Output is correct |
21 |
Correct |
351 ms |
224140 KB |
Output is correct |
22 |
Correct |
293 ms |
207592 KB |
Output is correct |
23 |
Correct |
90 ms |
71676 KB |
Output is correct |
24 |
Correct |
193 ms |
160776 KB |
Output is correct |
25 |
Correct |
544 ms |
400456 KB |
Output is correct |
26 |
Correct |
434 ms |
401232 KB |
Output is correct |
27 |
Correct |
456 ms |
403216 KB |
Output is correct |
28 |
Correct |
348 ms |
311612 KB |
Output is correct |
29 |
Correct |
112 ms |
96556 KB |
Output is correct |
30 |
Correct |
213 ms |
177576 KB |
Output is correct |
31 |
Correct |
481 ms |
400164 KB |
Output is correct |
32 |
Correct |
459 ms |
347652 KB |
Output is correct |
33 |
Correct |
422 ms |
347404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23892 KB |
Output is correct |
2 |
Correct |
19 ms |
24832 KB |
Output is correct |
3 |
Correct |
16 ms |
24024 KB |
Output is correct |
4 |
Correct |
16 ms |
24116 KB |
Output is correct |
5 |
Correct |
15 ms |
24956 KB |
Output is correct |
6 |
Correct |
12 ms |
23764 KB |
Output is correct |
7 |
Correct |
14 ms |
23764 KB |
Output is correct |
8 |
Correct |
17 ms |
23792 KB |
Output is correct |
9 |
Correct |
14 ms |
23716 KB |
Output is correct |
10 |
Correct |
12 ms |
23788 KB |
Output is correct |
11 |
Correct |
18 ms |
24148 KB |
Output is correct |
12 |
Correct |
15 ms |
24568 KB |
Output is correct |
13 |
Correct |
21 ms |
25428 KB |
Output is correct |
14 |
Correct |
17 ms |
25848 KB |
Output is correct |
15 |
Correct |
13 ms |
23764 KB |
Output is correct |
16 |
Correct |
13 ms |
23764 KB |
Output is correct |
17 |
Correct |
12 ms |
23792 KB |
Output is correct |
18 |
Correct |
650 ms |
133480 KB |
Output is correct |
19 |
Correct |
200 ms |
32016 KB |
Output is correct |
20 |
Correct |
125 ms |
27760 KB |
Output is correct |
21 |
Correct |
143 ms |
28728 KB |
Output is correct |
22 |
Correct |
157 ms |
29580 KB |
Output is correct |
23 |
Correct |
183 ms |
31876 KB |
Output is correct |
24 |
Correct |
141 ms |
28276 KB |
Output is correct |
25 |
Correct |
143 ms |
29132 KB |
Output is correct |
26 |
Correct |
187 ms |
29988 KB |
Output is correct |
27 |
Correct |
364 ms |
114744 KB |
Output is correct |
28 |
Correct |
274 ms |
69504 KB |
Output is correct |
29 |
Correct |
376 ms |
107580 KB |
Output is correct |
30 |
Correct |
579 ms |
240332 KB |
Output is correct |
31 |
Correct |
14 ms |
23892 KB |
Output is correct |
32 |
Correct |
439 ms |
116044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23892 KB |
Output is correct |
2 |
Correct |
19 ms |
24832 KB |
Output is correct |
3 |
Correct |
16 ms |
24024 KB |
Output is correct |
4 |
Correct |
16 ms |
24116 KB |
Output is correct |
5 |
Correct |
15 ms |
24956 KB |
Output is correct |
6 |
Correct |
12 ms |
23764 KB |
Output is correct |
7 |
Correct |
14 ms |
23764 KB |
Output is correct |
8 |
Correct |
17 ms |
23792 KB |
Output is correct |
9 |
Correct |
14 ms |
23716 KB |
Output is correct |
10 |
Correct |
12 ms |
23788 KB |
Output is correct |
11 |
Correct |
18 ms |
24148 KB |
Output is correct |
12 |
Correct |
15 ms |
24568 KB |
Output is correct |
13 |
Correct |
21 ms |
25428 KB |
Output is correct |
14 |
Correct |
17 ms |
25848 KB |
Output is correct |
15 |
Correct |
13 ms |
23764 KB |
Output is correct |
16 |
Correct |
13 ms |
23764 KB |
Output is correct |
17 |
Correct |
12 ms |
23792 KB |
Output is correct |
18 |
Correct |
650 ms |
133480 KB |
Output is correct |
19 |
Correct |
200 ms |
32016 KB |
Output is correct |
20 |
Correct |
125 ms |
27760 KB |
Output is correct |
21 |
Correct |
143 ms |
28728 KB |
Output is correct |
22 |
Correct |
157 ms |
29580 KB |
Output is correct |
23 |
Correct |
183 ms |
31876 KB |
Output is correct |
24 |
Correct |
141 ms |
28276 KB |
Output is correct |
25 |
Correct |
143 ms |
29132 KB |
Output is correct |
26 |
Correct |
187 ms |
29988 KB |
Output is correct |
27 |
Correct |
364 ms |
114744 KB |
Output is correct |
28 |
Correct |
274 ms |
69504 KB |
Output is correct |
29 |
Correct |
376 ms |
107580 KB |
Output is correct |
30 |
Correct |
579 ms |
240332 KB |
Output is correct |
31 |
Correct |
14 ms |
23892 KB |
Output is correct |
32 |
Correct |
439 ms |
116044 KB |
Output is correct |
33 |
Correct |
533 ms |
400552 KB |
Output is correct |
34 |
Correct |
481 ms |
401276 KB |
Output is correct |
35 |
Correct |
437 ms |
403224 KB |
Output is correct |
36 |
Correct |
367 ms |
311464 KB |
Output is correct |
37 |
Correct |
118 ms |
110124 KB |
Output is correct |
38 |
Correct |
219 ms |
177352 KB |
Output is correct |
39 |
Correct |
339 ms |
224148 KB |
Output is correct |
40 |
Correct |
314 ms |
207592 KB |
Output is correct |
41 |
Correct |
111 ms |
71692 KB |
Output is correct |
42 |
Correct |
193 ms |
160760 KB |
Output is correct |
43 |
Correct |
510 ms |
400648 KB |
Output is correct |
44 |
Correct |
451 ms |
401264 KB |
Output is correct |
45 |
Correct |
475 ms |
403264 KB |
Output is correct |
46 |
Correct |
373 ms |
311484 KB |
Output is correct |
47 |
Correct |
136 ms |
96560 KB |
Output is correct |
48 |
Correct |
217 ms |
177540 KB |
Output is correct |
49 |
Correct |
461 ms |
400224 KB |
Output is correct |
50 |
Correct |
482 ms |
347572 KB |
Output is correct |
51 |
Correct |
407 ms |
347404 KB |
Output is correct |
52 |
Correct |
351 ms |
224140 KB |
Output is correct |
53 |
Correct |
293 ms |
207592 KB |
Output is correct |
54 |
Correct |
90 ms |
71676 KB |
Output is correct |
55 |
Correct |
193 ms |
160776 KB |
Output is correct |
56 |
Correct |
544 ms |
400456 KB |
Output is correct |
57 |
Correct |
434 ms |
401232 KB |
Output is correct |
58 |
Correct |
456 ms |
403216 KB |
Output is correct |
59 |
Correct |
348 ms |
311612 KB |
Output is correct |
60 |
Correct |
112 ms |
96556 KB |
Output is correct |
61 |
Correct |
213 ms |
177576 KB |
Output is correct |
62 |
Correct |
481 ms |
400164 KB |
Output is correct |
63 |
Correct |
459 ms |
347652 KB |
Output is correct |
64 |
Correct |
422 ms |
347404 KB |
Output is correct |
65 |
Correct |
606 ms |
182892 KB |
Output is correct |
66 |
Correct |
774 ms |
278632 KB |
Output is correct |
67 |
Correct |
803 ms |
272460 KB |
Output is correct |
68 |
Correct |
631 ms |
207944 KB |
Output is correct |
69 |
Correct |
653 ms |
205224 KB |
Output is correct |
70 |
Correct |
281 ms |
39904 KB |
Output is correct |
71 |
Correct |
782 ms |
278708 KB |
Output is correct |
72 |
Correct |
811 ms |
272368 KB |
Output is correct |
73 |
Correct |
636 ms |
207808 KB |
Output is correct |
74 |
Correct |
428 ms |
262872 KB |
Output is correct |
75 |
Correct |
441 ms |
278540 KB |
Output is correct |
76 |
Correct |
443 ms |
272404 KB |
Output is correct |
77 |
Correct |
362 ms |
208048 KB |
Output is correct |
78 |
Correct |
628 ms |
209448 KB |
Output is correct |
79 |
Correct |
1037 ms |
227676 KB |
Output is correct |
80 |
Correct |
933 ms |
211076 KB |
Output is correct |
81 |
Correct |
358 ms |
75160 KB |
Output is correct |
82 |
Correct |
521 ms |
164284 KB |
Output is correct |
83 |
Correct |
988 ms |
404072 KB |
Output is correct |
84 |
Correct |
784 ms |
404784 KB |
Output is correct |
85 |
Correct |
813 ms |
406680 KB |
Output is correct |
86 |
Correct |
689 ms |
314932 KB |
Output is correct |
87 |
Correct |
416 ms |
100012 KB |
Output is correct |
88 |
Correct |
571 ms |
181064 KB |
Output is correct |
89 |
Correct |
836 ms |
403736 KB |
Output is correct |
90 |
Correct |
922 ms |
351112 KB |
Output is correct |
91 |
Correct |
828 ms |
350984 KB |
Output is correct |