#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;
using pi = pair<int, int>;
const int MAXT = 20000000;
const int MAXN = 200005;
struct node{
int l, r, sum;
}pool[MAXT];
int piv;
int newnode(){ return ++piv; }
void init(int s, int e, int p){
if(s == e) return;
int m = (s+e)/2;
pool[p].l = newnode();
pool[p].r = newnode();
init(s, m, pool[p].l);
init(m+1, e, pool[p].r);
}
void add(int pos, int s, int e, int prv, int cur){
pool[cur].sum = pool[prv].sum + 1;
if(s == e) return;
int m = (s+e)/2;
if(pos <= m){
pool[cur].l = newnode();
pool[cur].r = pool[prv].r;
add(pos, s, m, pool[prv].l, pool[cur].l);
}
else{
pool[cur].l = pool[prv].l;
pool[cur].r = newnode();
add(pos, m+1, e, pool[prv].r, pool[cur].r);
}
}
int query(int s, int e, int ps, int pe, int p){
if(e < ps || pe < s) return 0;
if(s <= ps && pe <= e) return pool[p].sum;
int pm = (ps + pe) / 2;
return query(s, e, ps, pm, pool[p].l) + query(s, e, pm+1, pe, pool[p].r);
}
int tree[4][MAXN];
vector<int> v[4][MAXN];
int minx = 1e9, miny = 1e9, maxx = -1e9, maxy = -1e9, yMax;
void init(int R, int C, int sr, int sc, int M, char *S) {
auto upload = [&](int x, int y){
v[0][x].push_back(y);
v[0][x].push_back(y + 1);
v[0][x + 1].push_back(y);
v[0][x + 1].push_back(y + 1);
v[1][x].push_back(y);
v[1][x].push_back(y + 1);
v[2][x].push_back(y);
v[2][x + 1].push_back(y);
v[3][x].push_back(y);
minx = min(minx, x); maxx = max(maxx, x + 1);
miny = min(miny, y); maxy = max(maxy, y + 1);
};
upload(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--;
upload(sr, sc);
}
yMax = C + 1;
for(int i=0; i<4; i++){
tree[i][0] = newnode();
init(1, yMax, tree[i][0]);
for(int j=1; j<=R+1; j++){
sort(v[i][j].begin(), v[i][j].end());
v[i][j].resize(unique(v[i][j].begin(), v[i][j].end()) - v[i][j].begin());
int prv = tree[i][j-1];
for(auto &k : v[i][j]){
int nxt = newnode();
add(k, 1, yMax, prv, nxt);
prv = nxt;
}
tree[i][j] = prv;
}
}
}
int colour(int ar, int ac, int br, int bc) {
auto query_helper = [&](int idx, int sx, int ex, int sy, int ey){
return query(sy, ey, 1, yMax, tree[idx][ex])
- query(sy, ey, 1, yMax, tree[idx][sx - 1]);
};
int V = query_helper(0, ar + 1, br, ac + 1, bc);
int E = query_helper(1, ar, br, ac + 1, bc) + query_helper(2, ar + 1, br, ac, bc);
int F = query_helper(3, ar, br, ac, bc);
if(ar < minx && maxx < br + 1 && ac < miny && maxy < bc + 1){
return 2 + E - V - F;
}
return 1 + E - V - F;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
19244 KB |
Output is correct |
2 |
Correct |
21 ms |
19584 KB |
Output is correct |
3 |
Correct |
19 ms |
19200 KB |
Output is correct |
4 |
Correct |
24 ms |
19328 KB |
Output is correct |
5 |
Correct |
21 ms |
19712 KB |
Output is correct |
6 |
Correct |
17 ms |
19072 KB |
Output is correct |
7 |
Correct |
17 ms |
19200 KB |
Output is correct |
8 |
Correct |
20 ms |
19192 KB |
Output is correct |
9 |
Correct |
18 ms |
19200 KB |
Output is correct |
10 |
Correct |
20 ms |
19200 KB |
Output is correct |
11 |
Correct |
24 ms |
19428 KB |
Output is correct |
12 |
Correct |
22 ms |
19584 KB |
Output is correct |
13 |
Correct |
21 ms |
19888 KB |
Output is correct |
14 |
Correct |
24 ms |
20224 KB |
Output is correct |
15 |
Correct |
17 ms |
19200 KB |
Output is correct |
16 |
Correct |
17 ms |
19200 KB |
Output is correct |
17 |
Correct |
18 ms |
19200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
19200 KB |
Output is correct |
2 |
Correct |
18 ms |
19200 KB |
Output is correct |
3 |
Correct |
997 ms |
121024 KB |
Output is correct |
4 |
Correct |
1238 ms |
175316 KB |
Output is correct |
5 |
Correct |
1205 ms |
174408 KB |
Output is correct |
6 |
Correct |
988 ms |
144340 KB |
Output is correct |
7 |
Correct |
1018 ms |
142932 KB |
Output is correct |
8 |
Correct |
778 ms |
44120 KB |
Output is correct |
9 |
Correct |
1140 ms |
174892 KB |
Output is correct |
10 |
Correct |
1112 ms |
174284 KB |
Output is correct |
11 |
Correct |
987 ms |
144216 KB |
Output is correct |
12 |
Correct |
358 ms |
166100 KB |
Output is correct |
13 |
Correct |
385 ms |
175224 KB |
Output is correct |
14 |
Correct |
385 ms |
174048 KB |
Output is correct |
15 |
Correct |
407 ms |
144276 KB |
Output is correct |
16 |
Correct |
1075 ms |
135488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
19200 KB |
Output is correct |
2 |
Correct |
224 ms |
177056 KB |
Output is correct |
3 |
Correct |
237 ms |
185352 KB |
Output is correct |
4 |
Correct |
225 ms |
179960 KB |
Output is correct |
5 |
Correct |
195 ms |
147556 KB |
Output is correct |
6 |
Correct |
107 ms |
71120 KB |
Output is correct |
7 |
Correct |
132 ms |
95240 KB |
Output is correct |
8 |
Correct |
189 ms |
130144 KB |
Output is correct |
9 |
Correct |
182 ms |
115432 KB |
Output is correct |
10 |
Correct |
64 ms |
39928 KB |
Output is correct |
11 |
Correct |
137 ms |
83136 KB |
Output is correct |
12 |
Correct |
220 ms |
177028 KB |
Output is correct |
13 |
Correct |
232 ms |
185268 KB |
Output is correct |
14 |
Correct |
239 ms |
179960 KB |
Output is correct |
15 |
Correct |
201 ms |
147556 KB |
Output is correct |
16 |
Correct |
91 ms |
65660 KB |
Output is correct |
17 |
Correct |
122 ms |
95600 KB |
Output is correct |
18 |
Correct |
210 ms |
177508 KB |
Output is correct |
19 |
Correct |
207 ms |
182088 KB |
Output is correct |
20 |
Correct |
208 ms |
182116 KB |
Output is correct |
21 |
Correct |
190 ms |
130144 KB |
Output is correct |
22 |
Correct |
175 ms |
115528 KB |
Output is correct |
23 |
Correct |
65 ms |
39900 KB |
Output is correct |
24 |
Correct |
123 ms |
83164 KB |
Output is correct |
25 |
Correct |
241 ms |
177112 KB |
Output is correct |
26 |
Correct |
232 ms |
185212 KB |
Output is correct |
27 |
Correct |
238 ms |
179960 KB |
Output is correct |
28 |
Correct |
192 ms |
147684 KB |
Output is correct |
29 |
Correct |
108 ms |
65748 KB |
Output is correct |
30 |
Correct |
131 ms |
95576 KB |
Output is correct |
31 |
Correct |
198 ms |
177372 KB |
Output is correct |
32 |
Correct |
237 ms |
182116 KB |
Output is correct |
33 |
Correct |
235 ms |
181992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
19244 KB |
Output is correct |
2 |
Correct |
21 ms |
19584 KB |
Output is correct |
3 |
Correct |
19 ms |
19200 KB |
Output is correct |
4 |
Correct |
24 ms |
19328 KB |
Output is correct |
5 |
Correct |
21 ms |
19712 KB |
Output is correct |
6 |
Correct |
17 ms |
19072 KB |
Output is correct |
7 |
Correct |
17 ms |
19200 KB |
Output is correct |
8 |
Correct |
20 ms |
19192 KB |
Output is correct |
9 |
Correct |
18 ms |
19200 KB |
Output is correct |
10 |
Correct |
20 ms |
19200 KB |
Output is correct |
11 |
Correct |
24 ms |
19428 KB |
Output is correct |
12 |
Correct |
22 ms |
19584 KB |
Output is correct |
13 |
Correct |
21 ms |
19888 KB |
Output is correct |
14 |
Correct |
24 ms |
20224 KB |
Output is correct |
15 |
Correct |
17 ms |
19200 KB |
Output is correct |
16 |
Correct |
17 ms |
19200 KB |
Output is correct |
17 |
Correct |
18 ms |
19200 KB |
Output is correct |
18 |
Correct |
850 ms |
64260 KB |
Output is correct |
19 |
Correct |
220 ms |
21880 KB |
Output is correct |
20 |
Correct |
149 ms |
20216 KB |
Output is correct |
21 |
Correct |
178 ms |
20696 KB |
Output is correct |
22 |
Correct |
181 ms |
20860 KB |
Output is correct |
23 |
Correct |
218 ms |
21948 KB |
Output is correct |
24 |
Correct |
170 ms |
20472 KB |
Output is correct |
25 |
Correct |
232 ms |
20984 KB |
Output is correct |
26 |
Correct |
199 ms |
21244 KB |
Output is correct |
27 |
Correct |
348 ms |
56732 KB |
Output is correct |
28 |
Correct |
284 ms |
40568 KB |
Output is correct |
29 |
Correct |
335 ms |
54484 KB |
Output is correct |
30 |
Correct |
522 ms |
102136 KB |
Output is correct |
31 |
Correct |
24 ms |
19192 KB |
Output is correct |
32 |
Correct |
645 ms |
56668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
19244 KB |
Output is correct |
2 |
Correct |
21 ms |
19584 KB |
Output is correct |
3 |
Correct |
19 ms |
19200 KB |
Output is correct |
4 |
Correct |
24 ms |
19328 KB |
Output is correct |
5 |
Correct |
21 ms |
19712 KB |
Output is correct |
6 |
Correct |
17 ms |
19072 KB |
Output is correct |
7 |
Correct |
17 ms |
19200 KB |
Output is correct |
8 |
Correct |
20 ms |
19192 KB |
Output is correct |
9 |
Correct |
18 ms |
19200 KB |
Output is correct |
10 |
Correct |
20 ms |
19200 KB |
Output is correct |
11 |
Correct |
24 ms |
19428 KB |
Output is correct |
12 |
Correct |
22 ms |
19584 KB |
Output is correct |
13 |
Correct |
21 ms |
19888 KB |
Output is correct |
14 |
Correct |
24 ms |
20224 KB |
Output is correct |
15 |
Correct |
17 ms |
19200 KB |
Output is correct |
16 |
Correct |
17 ms |
19200 KB |
Output is correct |
17 |
Correct |
18 ms |
19200 KB |
Output is correct |
18 |
Correct |
850 ms |
64260 KB |
Output is correct |
19 |
Correct |
220 ms |
21880 KB |
Output is correct |
20 |
Correct |
149 ms |
20216 KB |
Output is correct |
21 |
Correct |
178 ms |
20696 KB |
Output is correct |
22 |
Correct |
181 ms |
20860 KB |
Output is correct |
23 |
Correct |
218 ms |
21948 KB |
Output is correct |
24 |
Correct |
170 ms |
20472 KB |
Output is correct |
25 |
Correct |
232 ms |
20984 KB |
Output is correct |
26 |
Correct |
199 ms |
21244 KB |
Output is correct |
27 |
Correct |
348 ms |
56732 KB |
Output is correct |
28 |
Correct |
284 ms |
40568 KB |
Output is correct |
29 |
Correct |
335 ms |
54484 KB |
Output is correct |
30 |
Correct |
522 ms |
102136 KB |
Output is correct |
31 |
Correct |
24 ms |
19192 KB |
Output is correct |
32 |
Correct |
645 ms |
56668 KB |
Output is correct |
33 |
Correct |
224 ms |
177056 KB |
Output is correct |
34 |
Correct |
237 ms |
185352 KB |
Output is correct |
35 |
Correct |
225 ms |
179960 KB |
Output is correct |
36 |
Correct |
195 ms |
147556 KB |
Output is correct |
37 |
Correct |
107 ms |
71120 KB |
Output is correct |
38 |
Correct |
132 ms |
95240 KB |
Output is correct |
39 |
Correct |
189 ms |
130144 KB |
Output is correct |
40 |
Correct |
182 ms |
115432 KB |
Output is correct |
41 |
Correct |
64 ms |
39928 KB |
Output is correct |
42 |
Correct |
137 ms |
83136 KB |
Output is correct |
43 |
Correct |
220 ms |
177028 KB |
Output is correct |
44 |
Correct |
232 ms |
185268 KB |
Output is correct |
45 |
Correct |
239 ms |
179960 KB |
Output is correct |
46 |
Correct |
201 ms |
147556 KB |
Output is correct |
47 |
Correct |
91 ms |
65660 KB |
Output is correct |
48 |
Correct |
122 ms |
95600 KB |
Output is correct |
49 |
Correct |
210 ms |
177508 KB |
Output is correct |
50 |
Correct |
207 ms |
182088 KB |
Output is correct |
51 |
Correct |
208 ms |
182116 KB |
Output is correct |
52 |
Correct |
190 ms |
130144 KB |
Output is correct |
53 |
Correct |
175 ms |
115528 KB |
Output is correct |
54 |
Correct |
65 ms |
39900 KB |
Output is correct |
55 |
Correct |
123 ms |
83164 KB |
Output is correct |
56 |
Correct |
241 ms |
177112 KB |
Output is correct |
57 |
Correct |
232 ms |
185212 KB |
Output is correct |
58 |
Correct |
238 ms |
179960 KB |
Output is correct |
59 |
Correct |
192 ms |
147684 KB |
Output is correct |
60 |
Correct |
108 ms |
65748 KB |
Output is correct |
61 |
Correct |
131 ms |
95576 KB |
Output is correct |
62 |
Correct |
198 ms |
177372 KB |
Output is correct |
63 |
Correct |
237 ms |
182116 KB |
Output is correct |
64 |
Correct |
235 ms |
181992 KB |
Output is correct |
65 |
Correct |
1324 ms |
131188 KB |
Output is correct |
66 |
Correct |
1167 ms |
116256 KB |
Output is correct |
67 |
Correct |
427 ms |
40764 KB |
Output is correct |
68 |
Correct |
770 ms |
83916 KB |
Output is correct |
69 |
Correct |
1042 ms |
178040 KB |
Output is correct |
70 |
Correct |
1014 ms |
186100 KB |
Output is correct |
71 |
Correct |
984 ms |
180728 KB |
Output is correct |
72 |
Correct |
941 ms |
148452 KB |
Output is correct |
73 |
Correct |
797 ms |
66552 KB |
Output is correct |
74 |
Correct |
824 ms |
96516 KB |
Output is correct |
75 |
Correct |
910 ms |
178296 KB |
Output is correct |
76 |
Correct |
1060 ms |
183140 KB |
Output is correct |
77 |
Correct |
851 ms |
182868 KB |
Output is correct |
78 |
Correct |
997 ms |
121024 KB |
Output is correct |
79 |
Correct |
1238 ms |
175316 KB |
Output is correct |
80 |
Correct |
1205 ms |
174408 KB |
Output is correct |
81 |
Correct |
988 ms |
144340 KB |
Output is correct |
82 |
Correct |
1018 ms |
142932 KB |
Output is correct |
83 |
Correct |
778 ms |
44120 KB |
Output is correct |
84 |
Correct |
1140 ms |
174892 KB |
Output is correct |
85 |
Correct |
1112 ms |
174284 KB |
Output is correct |
86 |
Correct |
987 ms |
144216 KB |
Output is correct |
87 |
Correct |
358 ms |
166100 KB |
Output is correct |
88 |
Correct |
385 ms |
175224 KB |
Output is correct |
89 |
Correct |
385 ms |
174048 KB |
Output is correct |
90 |
Correct |
407 ms |
144276 KB |
Output is correct |
91 |
Correct |
1075 ms |
135488 KB |
Output is correct |