#include "rainbow.h"
#include <algorithm>
#include <vector>
using ll = long long;
int row, col, mn_x, mx_x, mn_y, mx_y;
struct segT
{
int rt[200005], lson[10000005], rson[10000005], sum[10000005], t_cnt = 0;
void modify(int &u, int v, int l, int r, int pos)
{
u = ++t_cnt;
lson[u] = lson[v];
rson[u] = rson[v];
sum[u] = sum[v] + 1;
if (l == r)
return;
int m = l + r >> 1;
if (pos <= m)
modify(lson[u], lson[v], l, m, pos);
else
modify(rson[u], rson[v], m + 1, r, pos);
}
int query(int u, int l, int r, int L, int R)
{
if (!u)
return 0;
if (L <= l && r <= R)
return sum[u];
int m = l + r >> 1, res = 0;
if (L <= m)
res += query(lson[u], l, m, L, R);
if (m < R)
res += query(rson[u], m + 1, r, L, R);
return res;
}
int query(int l, int r, int L, int R)
{
if (l > r || L > R)
return 0;
return query(rt[r + 1], 0, col, L, R) - query(rt[l], 0, col, L, R);
}
} seg[4];
std::vector<int> vec[4][200005];
inline void add(int x, int y)
{
vec[0][++x].push_back(++y);
for (int i = 0; i < 2; i++)
{
vec[1][x - i].push_back(y);
vec[2][x].push_back(y - i);
for (int j = 0; j < 2; j++)
vec[3][x - i].push_back(y - j);
}
}
void init(int R, int C, int x, int y, int len, char *str)
{
row = R;
col = C;
mn_x = mx_x = --x;
mn_y = mx_y = --y;
add(x, y);
for (int i = 0; i < len; i++)
{
if (str[i] == 'N')
x--;
else if (str[i] == 'S')
x++;
else if (str[i] == 'W')
y--;
else
y++;
mn_x = std::min(mn_x, x);
mx_x = std::max(mx_x, x);
mn_y = std::min(mn_y, y);
mx_y = std::max(mx_y, y);
add(x, y);
}
for (int i = 0; i < 4; i++)
{
for (int j = 0; j <= row; j++)
{
seg[i].rt[j + 1] = seg[i].rt[j];
std::sort(vec[i][j].begin(), vec[i][j].end());
vec[i][j].erase(std::unique(vec[i][j].begin(), vec[i][j].end()), vec[i][j].end());
for (int k : vec[i][j])
seg[i].modify(seg[i].rt[j + 1], seg[i].rt[j + 1], 0, col, k);
}
}
}
int colour(int xl, int yl, int xr, int yr)
{
ll ans = (ll)(--xr - --xl + 1) * (--yr - --yl + 1);
ans -= seg[0].query(xl + 1, xr + 1, yl + 1, yr + 1); // 1 * 1
ans -= (ll)(xr - xl) * (yr - yl + 1) - seg[1].query(xl + 1, xr, yl + 1, yr + 1); // 2 * 1
ans -= (ll)(xr - xl + 1) * (yr - yl) - seg[2].query(xl + 1, xr + 1, yl + 1, yr); // 1 * 2
ans += (ll)(xr - xl) * (yr - yl) - seg[3].query(xl + 1, xr, yl + 1, yr); // 2 * 2
return ans + (xl < mn_x && xr > mx_x && yl < mn_y && yr > mx_y); // circle
}
Compilation message
rainbow.cpp: In member function 'void segT::modify(int&, int, int, int, int)':
rainbow.cpp:17:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int m = l + r >> 1;
~~^~~
rainbow.cpp: In member function 'int segT::query(int, int, int, int, int)':
rainbow.cpp:29:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int m = l + r >> 1, res = 0;
~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
19320 KB |
Output is correct |
2 |
Correct |
22 ms |
19704 KB |
Output is correct |
3 |
Correct |
21 ms |
19320 KB |
Output is correct |
4 |
Correct |
21 ms |
19448 KB |
Output is correct |
5 |
Correct |
21 ms |
19832 KB |
Output is correct |
6 |
Correct |
18 ms |
19192 KB |
Output is correct |
7 |
Correct |
18 ms |
19148 KB |
Output is correct |
8 |
Correct |
18 ms |
19192 KB |
Output is correct |
9 |
Correct |
18 ms |
19192 KB |
Output is correct |
10 |
Correct |
18 ms |
19196 KB |
Output is correct |
11 |
Correct |
19 ms |
19448 KB |
Output is correct |
12 |
Correct |
21 ms |
19576 KB |
Output is correct |
13 |
Correct |
21 ms |
19960 KB |
Output is correct |
14 |
Correct |
22 ms |
20216 KB |
Output is correct |
15 |
Correct |
18 ms |
19192 KB |
Output is correct |
16 |
Correct |
18 ms |
19320 KB |
Output is correct |
17 |
Correct |
18 ms |
19260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
19320 KB |
Output is correct |
2 |
Correct |
18 ms |
19260 KB |
Output is correct |
3 |
Correct |
412 ms |
104544 KB |
Output is correct |
4 |
Correct |
491 ms |
158684 KB |
Output is correct |
5 |
Correct |
490 ms |
157784 KB |
Output is correct |
6 |
Correct |
360 ms |
128120 KB |
Output is correct |
7 |
Correct |
500 ms |
126328 KB |
Output is correct |
8 |
Correct |
101 ms |
27612 KB |
Output is correct |
9 |
Correct |
528 ms |
158608 KB |
Output is correct |
10 |
Correct |
542 ms |
157608 KB |
Output is correct |
11 |
Correct |
429 ms |
127420 KB |
Output is correct |
12 |
Correct |
250 ms |
149424 KB |
Output is correct |
13 |
Correct |
279 ms |
158620 KB |
Output is correct |
14 |
Correct |
305 ms |
157732 KB |
Output is correct |
15 |
Correct |
269 ms |
128032 KB |
Output is correct |
16 |
Correct |
417 ms |
119124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
19192 KB |
Output is correct |
2 |
Correct |
206 ms |
158036 KB |
Output is correct |
3 |
Correct |
252 ms |
164140 KB |
Output is correct |
4 |
Correct |
219 ms |
161196 KB |
Output is correct |
5 |
Correct |
205 ms |
127544 KB |
Output is correct |
6 |
Correct |
88 ms |
52348 KB |
Output is correct |
7 |
Correct |
122 ms |
76468 KB |
Output is correct |
8 |
Correct |
211 ms |
127096 KB |
Output is correct |
9 |
Correct |
192 ms |
112880 KB |
Output is correct |
10 |
Correct |
64 ms |
39796 KB |
Output is correct |
11 |
Correct |
134 ms |
80408 KB |
Output is correct |
12 |
Correct |
228 ms |
158044 KB |
Output is correct |
13 |
Correct |
257 ms |
164180 KB |
Output is correct |
14 |
Correct |
224 ms |
161200 KB |
Output is correct |
15 |
Correct |
204 ms |
127604 KB |
Output is correct |
16 |
Correct |
83 ms |
47068 KB |
Output is correct |
17 |
Correct |
122 ms |
76896 KB |
Output is correct |
18 |
Correct |
216 ms |
158720 KB |
Output is correct |
19 |
Correct |
207 ms |
163300 KB |
Output is correct |
20 |
Correct |
220 ms |
163252 KB |
Output is correct |
21 |
Correct |
212 ms |
127092 KB |
Output is correct |
22 |
Correct |
192 ms |
112872 KB |
Output is correct |
23 |
Correct |
63 ms |
39800 KB |
Output is correct |
24 |
Correct |
134 ms |
80412 KB |
Output is correct |
25 |
Correct |
230 ms |
158116 KB |
Output is correct |
26 |
Correct |
257 ms |
164216 KB |
Output is correct |
27 |
Correct |
247 ms |
161144 KB |
Output is correct |
28 |
Correct |
204 ms |
127584 KB |
Output is correct |
29 |
Correct |
82 ms |
47052 KB |
Output is correct |
30 |
Correct |
123 ms |
76928 KB |
Output is correct |
31 |
Correct |
219 ms |
158712 KB |
Output is correct |
32 |
Correct |
239 ms |
163328 KB |
Output is correct |
33 |
Correct |
237 ms |
163128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
19320 KB |
Output is correct |
2 |
Correct |
22 ms |
19704 KB |
Output is correct |
3 |
Correct |
21 ms |
19320 KB |
Output is correct |
4 |
Correct |
21 ms |
19448 KB |
Output is correct |
5 |
Correct |
21 ms |
19832 KB |
Output is correct |
6 |
Correct |
18 ms |
19192 KB |
Output is correct |
7 |
Correct |
18 ms |
19148 KB |
Output is correct |
8 |
Correct |
18 ms |
19192 KB |
Output is correct |
9 |
Correct |
18 ms |
19192 KB |
Output is correct |
10 |
Correct |
18 ms |
19196 KB |
Output is correct |
11 |
Correct |
19 ms |
19448 KB |
Output is correct |
12 |
Correct |
21 ms |
19576 KB |
Output is correct |
13 |
Correct |
21 ms |
19960 KB |
Output is correct |
14 |
Correct |
22 ms |
20216 KB |
Output is correct |
15 |
Correct |
18 ms |
19192 KB |
Output is correct |
16 |
Correct |
18 ms |
19320 KB |
Output is correct |
17 |
Correct |
18 ms |
19260 KB |
Output is correct |
18 |
Correct |
786 ms |
66896 KB |
Output is correct |
19 |
Correct |
262 ms |
24484 KB |
Output is correct |
20 |
Correct |
161 ms |
22848 KB |
Output is correct |
21 |
Correct |
191 ms |
23288 KB |
Output is correct |
22 |
Correct |
212 ms |
23544 KB |
Output is correct |
23 |
Correct |
250 ms |
24404 KB |
Output is correct |
24 |
Correct |
166 ms |
23300 KB |
Output is correct |
25 |
Correct |
189 ms |
23484 KB |
Output is correct |
26 |
Correct |
206 ms |
23800 KB |
Output is correct |
27 |
Correct |
217 ms |
59408 KB |
Output is correct |
28 |
Correct |
196 ms |
43128 KB |
Output is correct |
29 |
Correct |
236 ms |
57080 KB |
Output is correct |
30 |
Correct |
422 ms |
104708 KB |
Output is correct |
31 |
Correct |
21 ms |
19292 KB |
Output is correct |
32 |
Correct |
473 ms |
59156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
19320 KB |
Output is correct |
2 |
Correct |
22 ms |
19704 KB |
Output is correct |
3 |
Correct |
21 ms |
19320 KB |
Output is correct |
4 |
Correct |
21 ms |
19448 KB |
Output is correct |
5 |
Correct |
21 ms |
19832 KB |
Output is correct |
6 |
Correct |
18 ms |
19192 KB |
Output is correct |
7 |
Correct |
18 ms |
19148 KB |
Output is correct |
8 |
Correct |
18 ms |
19192 KB |
Output is correct |
9 |
Correct |
18 ms |
19192 KB |
Output is correct |
10 |
Correct |
18 ms |
19196 KB |
Output is correct |
11 |
Correct |
19 ms |
19448 KB |
Output is correct |
12 |
Correct |
21 ms |
19576 KB |
Output is correct |
13 |
Correct |
21 ms |
19960 KB |
Output is correct |
14 |
Correct |
22 ms |
20216 KB |
Output is correct |
15 |
Correct |
18 ms |
19192 KB |
Output is correct |
16 |
Correct |
18 ms |
19320 KB |
Output is correct |
17 |
Correct |
18 ms |
19260 KB |
Output is correct |
18 |
Correct |
786 ms |
66896 KB |
Output is correct |
19 |
Correct |
262 ms |
24484 KB |
Output is correct |
20 |
Correct |
161 ms |
22848 KB |
Output is correct |
21 |
Correct |
191 ms |
23288 KB |
Output is correct |
22 |
Correct |
212 ms |
23544 KB |
Output is correct |
23 |
Correct |
250 ms |
24404 KB |
Output is correct |
24 |
Correct |
166 ms |
23300 KB |
Output is correct |
25 |
Correct |
189 ms |
23484 KB |
Output is correct |
26 |
Correct |
206 ms |
23800 KB |
Output is correct |
27 |
Correct |
217 ms |
59408 KB |
Output is correct |
28 |
Correct |
196 ms |
43128 KB |
Output is correct |
29 |
Correct |
236 ms |
57080 KB |
Output is correct |
30 |
Correct |
422 ms |
104708 KB |
Output is correct |
31 |
Correct |
21 ms |
19292 KB |
Output is correct |
32 |
Correct |
473 ms |
59156 KB |
Output is correct |
33 |
Correct |
206 ms |
158036 KB |
Output is correct |
34 |
Correct |
252 ms |
164140 KB |
Output is correct |
35 |
Correct |
219 ms |
161196 KB |
Output is correct |
36 |
Correct |
205 ms |
127544 KB |
Output is correct |
37 |
Correct |
88 ms |
52348 KB |
Output is correct |
38 |
Correct |
122 ms |
76468 KB |
Output is correct |
39 |
Correct |
211 ms |
127096 KB |
Output is correct |
40 |
Correct |
192 ms |
112880 KB |
Output is correct |
41 |
Correct |
64 ms |
39796 KB |
Output is correct |
42 |
Correct |
134 ms |
80408 KB |
Output is correct |
43 |
Correct |
228 ms |
158044 KB |
Output is correct |
44 |
Correct |
257 ms |
164180 KB |
Output is correct |
45 |
Correct |
224 ms |
161200 KB |
Output is correct |
46 |
Correct |
204 ms |
127604 KB |
Output is correct |
47 |
Correct |
83 ms |
47068 KB |
Output is correct |
48 |
Correct |
122 ms |
76896 KB |
Output is correct |
49 |
Correct |
216 ms |
158720 KB |
Output is correct |
50 |
Correct |
207 ms |
163300 KB |
Output is correct |
51 |
Correct |
220 ms |
163252 KB |
Output is correct |
52 |
Correct |
212 ms |
127092 KB |
Output is correct |
53 |
Correct |
192 ms |
112872 KB |
Output is correct |
54 |
Correct |
63 ms |
39800 KB |
Output is correct |
55 |
Correct |
134 ms |
80412 KB |
Output is correct |
56 |
Correct |
230 ms |
158116 KB |
Output is correct |
57 |
Correct |
257 ms |
164216 KB |
Output is correct |
58 |
Correct |
247 ms |
161144 KB |
Output is correct |
59 |
Correct |
204 ms |
127584 KB |
Output is correct |
60 |
Correct |
82 ms |
47052 KB |
Output is correct |
61 |
Correct |
123 ms |
76928 KB |
Output is correct |
62 |
Correct |
219 ms |
158712 KB |
Output is correct |
63 |
Correct |
239 ms |
163328 KB |
Output is correct |
64 |
Correct |
237 ms |
163128 KB |
Output is correct |
65 |
Correct |
976 ms |
130520 KB |
Output is correct |
66 |
Correct |
1061 ms |
116340 KB |
Output is correct |
67 |
Correct |
379 ms |
43388 KB |
Output is correct |
68 |
Correct |
390 ms |
83932 KB |
Output is correct |
69 |
Correct |
550 ms |
161620 KB |
Output is correct |
70 |
Correct |
413 ms |
167672 KB |
Output is correct |
71 |
Correct |
483 ms |
164892 KB |
Output is correct |
72 |
Correct |
401 ms |
131132 KB |
Output is correct |
73 |
Correct |
171 ms |
50524 KB |
Output is correct |
74 |
Correct |
220 ms |
80440 KB |
Output is correct |
75 |
Correct |
318 ms |
162220 KB |
Output is correct |
76 |
Correct |
560 ms |
166916 KB |
Output is correct |
77 |
Correct |
553 ms |
166740 KB |
Output is correct |
78 |
Correct |
412 ms |
104544 KB |
Output is correct |
79 |
Correct |
491 ms |
158684 KB |
Output is correct |
80 |
Correct |
490 ms |
157784 KB |
Output is correct |
81 |
Correct |
360 ms |
128120 KB |
Output is correct |
82 |
Correct |
500 ms |
126328 KB |
Output is correct |
83 |
Correct |
101 ms |
27612 KB |
Output is correct |
84 |
Correct |
528 ms |
158608 KB |
Output is correct |
85 |
Correct |
542 ms |
157608 KB |
Output is correct |
86 |
Correct |
429 ms |
127420 KB |
Output is correct |
87 |
Correct |
250 ms |
149424 KB |
Output is correct |
88 |
Correct |
279 ms |
158620 KB |
Output is correct |
89 |
Correct |
305 ms |
157732 KB |
Output is correct |
90 |
Correct |
269 ms |
128032 KB |
Output is correct |
91 |
Correct |
417 ms |
119124 KB |
Output is correct |