#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;
#define N 200005
#define L 18
#define N_ (1 << L)
#define M (42424242)
int sum[M], ll[M], rr[M];
int node(int k = 0) {
static int _ = 1;
sum[_] = sum[k];
ll[_] = ll[k], rr[_] = rr[k];
return _++;
}
int build_(int l, int r) {
int v = node(), m;
if (l < r) {
m = (l + r) / 2;
ll[v] = build_(l, m);
rr[v] = build_(m + 1, r);
}
return v;
}
int update(int v, int l, int r, int i) {
int v_ = node(v), m;
sum[v_]++;
if (l < r) {
m = (l + r) / 2;
if (i <= m)
ll[v_] = update(ll[v], l, m, i);
else
rr[v_] = update(rr[v], m + 1, r, i);
}
return v_;
}
int query_(int v, int l, int r, int ql, int qr) {
int m;
if (qr < l || ql > r)
return 0;
if (ql <= l && qr >= r)
return sum[v];
m = (l + r) / 2;
return query_(ll[v], l, m, ql, qr) + query_(rr[v], m + 1, r, ql, qr);
}
struct tree {
vector<int> pp[N + 1];
int xx[N + 1];
void add(int i, int j) {
pp[i].push_back(j);
}
void build() {
for (int i = 1; i <= N; i++) {
xx[i] = xx[i - 1];
sort(pp[i].begin(), pp[i].end());
pp[i].erase(unique(pp[i].begin(), pp[i].end()), pp[i].end());
for (int j : pp[i - 1])
xx[i] = update(xx[i], 1, N, j);
}
}
int query(int i, int j, int i_, int j_) {
if (i_ > j_)
return 0;
return query_(xx[j + 1], 1, N, i_, j_) - query_(xx[i], 1, N, i_, j_);
}
} st0, st1, st2, st3;
void add(int i, int j) {
st0.add(i, j);
st0.add(i + 1, j);
st0.add(i, j + 1);
st0.add(i + 1, j + 1);
st1.add(i, j);
st1.add(i + 1, j);
st2.add(i, j);
st2.add(i, j + 1);
st3.add(i, j);
}
int mx_i, mn_i, mx_j, mn_j;
void init(int n, int m, int si, int sj, int k, char *s) {
add(si, sj);
mx_i = mn_i = si;
mx_j = mn_j = sj;
for (int i = 0; i < k; i++) {
if (s[i] == 'N')
si--;
if (s[i] == 'E')
sj++;
if (s[i] == 'S')
si++;
if (s[i] == 'W')
sj--;
add(si, sj);
mx_i = max(mx_i, si);
mn_i = min(mn_i, si);
mx_j = max(mx_j, sj);
mn_j = min(mn_j, sj);
}
st0.build();
st1.build();
st2.build();
st3.build();
}
int colour(int i, int j, int i_, int j_) {
int E = st1.query(i + 1, i_, j, j_) + st2.query(i, i_, j + 1, j_);
int V = st0.query(i + 1, i_, j + 1, j_);
int R = st3.query(i, i_, j, j_);
int C = (i >= mn_i || i_ <= mx_i || j >= mn_j || j_ <= mx_j ? 1 : 2);
return E - V + C - R;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
22464 KB |
Output is correct |
2 |
Correct |
18 ms |
23320 KB |
Output is correct |
3 |
Correct |
16 ms |
22536 KB |
Output is correct |
4 |
Correct |
17 ms |
22580 KB |
Output is correct |
5 |
Correct |
18 ms |
23604 KB |
Output is correct |
6 |
Correct |
14 ms |
22228 KB |
Output is correct |
7 |
Correct |
14 ms |
22188 KB |
Output is correct |
8 |
Correct |
19 ms |
22228 KB |
Output is correct |
9 |
Correct |
15 ms |
22176 KB |
Output is correct |
10 |
Correct |
15 ms |
22192 KB |
Output is correct |
11 |
Correct |
17 ms |
22756 KB |
Output is correct |
12 |
Correct |
17 ms |
23092 KB |
Output is correct |
13 |
Correct |
18 ms |
23992 KB |
Output is correct |
14 |
Correct |
19 ms |
24504 KB |
Output is correct |
15 |
Correct |
13 ms |
22248 KB |
Output is correct |
16 |
Correct |
13 ms |
22188 KB |
Output is correct |
17 |
Correct |
13 ms |
22228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
22188 KB |
Output is correct |
2 |
Correct |
13 ms |
22228 KB |
Output is correct |
3 |
Correct |
530 ms |
107104 KB |
Output is correct |
4 |
Correct |
693 ms |
161764 KB |
Output is correct |
5 |
Correct |
768 ms |
160648 KB |
Output is correct |
6 |
Correct |
583 ms |
130716 KB |
Output is correct |
7 |
Correct |
680 ms |
129128 KB |
Output is correct |
8 |
Correct |
299 ms |
30236 KB |
Output is correct |
9 |
Correct |
668 ms |
161512 KB |
Output is correct |
10 |
Correct |
752 ms |
160764 KB |
Output is correct |
11 |
Correct |
621 ms |
130544 KB |
Output is correct |
12 |
Correct |
366 ms |
152576 KB |
Output is correct |
13 |
Correct |
389 ms |
161488 KB |
Output is correct |
14 |
Correct |
364 ms |
160344 KB |
Output is correct |
15 |
Correct |
345 ms |
131076 KB |
Output is correct |
16 |
Correct |
524 ms |
122084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
22248 KB |
Output is correct |
2 |
Correct |
196 ms |
158372 KB |
Output is correct |
3 |
Correct |
169 ms |
164100 KB |
Output is correct |
4 |
Correct |
202 ms |
161088 KB |
Output is correct |
5 |
Correct |
183 ms |
127612 KB |
Output is correct |
6 |
Correct |
70 ms |
52312 KB |
Output is correct |
7 |
Correct |
96 ms |
76556 KB |
Output is correct |
8 |
Correct |
219 ms |
144540 KB |
Output is correct |
9 |
Correct |
169 ms |
131136 KB |
Output is correct |
10 |
Correct |
68 ms |
50636 KB |
Output is correct |
11 |
Correct |
115 ms |
91532 KB |
Output is correct |
12 |
Correct |
192 ms |
158360 KB |
Output is correct |
13 |
Correct |
169 ms |
164040 KB |
Output is correct |
14 |
Correct |
170 ms |
161024 KB |
Output is correct |
15 |
Correct |
158 ms |
127520 KB |
Output is correct |
16 |
Correct |
67 ms |
46928 KB |
Output is correct |
17 |
Correct |
92 ms |
76876 KB |
Output is correct |
18 |
Correct |
179 ms |
158776 KB |
Output is correct |
19 |
Correct |
198 ms |
163252 KB |
Output is correct |
20 |
Correct |
174 ms |
163240 KB |
Output is correct |
21 |
Correct |
190 ms |
144428 KB |
Output is correct |
22 |
Correct |
195 ms |
131216 KB |
Output is correct |
23 |
Correct |
63 ms |
50592 KB |
Output is correct |
24 |
Correct |
118 ms |
91544 KB |
Output is correct |
25 |
Correct |
187 ms |
158328 KB |
Output is correct |
26 |
Correct |
167 ms |
164068 KB |
Output is correct |
27 |
Correct |
192 ms |
161084 KB |
Output is correct |
28 |
Correct |
162 ms |
127572 KB |
Output is correct |
29 |
Correct |
67 ms |
46920 KB |
Output is correct |
30 |
Correct |
91 ms |
76928 KB |
Output is correct |
31 |
Correct |
170 ms |
159048 KB |
Output is correct |
32 |
Correct |
190 ms |
163164 KB |
Output is correct |
33 |
Correct |
183 ms |
163180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
22464 KB |
Output is correct |
2 |
Correct |
18 ms |
23320 KB |
Output is correct |
3 |
Correct |
16 ms |
22536 KB |
Output is correct |
4 |
Correct |
17 ms |
22580 KB |
Output is correct |
5 |
Correct |
18 ms |
23604 KB |
Output is correct |
6 |
Correct |
14 ms |
22228 KB |
Output is correct |
7 |
Correct |
14 ms |
22188 KB |
Output is correct |
8 |
Correct |
19 ms |
22228 KB |
Output is correct |
9 |
Correct |
15 ms |
22176 KB |
Output is correct |
10 |
Correct |
15 ms |
22192 KB |
Output is correct |
11 |
Correct |
17 ms |
22756 KB |
Output is correct |
12 |
Correct |
17 ms |
23092 KB |
Output is correct |
13 |
Correct |
18 ms |
23992 KB |
Output is correct |
14 |
Correct |
19 ms |
24504 KB |
Output is correct |
15 |
Correct |
13 ms |
22248 KB |
Output is correct |
16 |
Correct |
13 ms |
22188 KB |
Output is correct |
17 |
Correct |
13 ms |
22228 KB |
Output is correct |
18 |
Correct |
832 ms |
97340 KB |
Output is correct |
19 |
Correct |
240 ms |
28736 KB |
Output is correct |
20 |
Correct |
212 ms |
26184 KB |
Output is correct |
21 |
Correct |
203 ms |
26712 KB |
Output is correct |
22 |
Correct |
246 ms |
27340 KB |
Output is correct |
23 |
Correct |
260 ms |
28676 KB |
Output is correct |
24 |
Correct |
211 ms |
26668 KB |
Output is correct |
25 |
Correct |
239 ms |
27304 KB |
Output is correct |
26 |
Correct |
215 ms |
27752 KB |
Output is correct |
27 |
Correct |
426 ms |
84576 KB |
Output is correct |
28 |
Correct |
348 ms |
56772 KB |
Output is correct |
29 |
Correct |
410 ms |
80020 KB |
Output is correct |
30 |
Correct |
632 ms |
162296 KB |
Output is correct |
31 |
Correct |
18 ms |
22356 KB |
Output is correct |
32 |
Correct |
670 ms |
84532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
22464 KB |
Output is correct |
2 |
Correct |
18 ms |
23320 KB |
Output is correct |
3 |
Correct |
16 ms |
22536 KB |
Output is correct |
4 |
Correct |
17 ms |
22580 KB |
Output is correct |
5 |
Correct |
18 ms |
23604 KB |
Output is correct |
6 |
Correct |
14 ms |
22228 KB |
Output is correct |
7 |
Correct |
14 ms |
22188 KB |
Output is correct |
8 |
Correct |
19 ms |
22228 KB |
Output is correct |
9 |
Correct |
15 ms |
22176 KB |
Output is correct |
10 |
Correct |
15 ms |
22192 KB |
Output is correct |
11 |
Correct |
17 ms |
22756 KB |
Output is correct |
12 |
Correct |
17 ms |
23092 KB |
Output is correct |
13 |
Correct |
18 ms |
23992 KB |
Output is correct |
14 |
Correct |
19 ms |
24504 KB |
Output is correct |
15 |
Correct |
13 ms |
22248 KB |
Output is correct |
16 |
Correct |
13 ms |
22188 KB |
Output is correct |
17 |
Correct |
13 ms |
22228 KB |
Output is correct |
18 |
Correct |
832 ms |
97340 KB |
Output is correct |
19 |
Correct |
240 ms |
28736 KB |
Output is correct |
20 |
Correct |
212 ms |
26184 KB |
Output is correct |
21 |
Correct |
203 ms |
26712 KB |
Output is correct |
22 |
Correct |
246 ms |
27340 KB |
Output is correct |
23 |
Correct |
260 ms |
28676 KB |
Output is correct |
24 |
Correct |
211 ms |
26668 KB |
Output is correct |
25 |
Correct |
239 ms |
27304 KB |
Output is correct |
26 |
Correct |
215 ms |
27752 KB |
Output is correct |
27 |
Correct |
426 ms |
84576 KB |
Output is correct |
28 |
Correct |
348 ms |
56772 KB |
Output is correct |
29 |
Correct |
410 ms |
80020 KB |
Output is correct |
30 |
Correct |
632 ms |
162296 KB |
Output is correct |
31 |
Correct |
18 ms |
22356 KB |
Output is correct |
32 |
Correct |
670 ms |
84532 KB |
Output is correct |
33 |
Correct |
196 ms |
158372 KB |
Output is correct |
34 |
Correct |
169 ms |
164100 KB |
Output is correct |
35 |
Correct |
202 ms |
161088 KB |
Output is correct |
36 |
Correct |
183 ms |
127612 KB |
Output is correct |
37 |
Correct |
70 ms |
52312 KB |
Output is correct |
38 |
Correct |
96 ms |
76556 KB |
Output is correct |
39 |
Correct |
219 ms |
144540 KB |
Output is correct |
40 |
Correct |
169 ms |
131136 KB |
Output is correct |
41 |
Correct |
68 ms |
50636 KB |
Output is correct |
42 |
Correct |
115 ms |
91532 KB |
Output is correct |
43 |
Correct |
192 ms |
158360 KB |
Output is correct |
44 |
Correct |
169 ms |
164040 KB |
Output is correct |
45 |
Correct |
170 ms |
161024 KB |
Output is correct |
46 |
Correct |
158 ms |
127520 KB |
Output is correct |
47 |
Correct |
67 ms |
46928 KB |
Output is correct |
48 |
Correct |
92 ms |
76876 KB |
Output is correct |
49 |
Correct |
179 ms |
158776 KB |
Output is correct |
50 |
Correct |
198 ms |
163252 KB |
Output is correct |
51 |
Correct |
174 ms |
163240 KB |
Output is correct |
52 |
Correct |
190 ms |
144428 KB |
Output is correct |
53 |
Correct |
195 ms |
131216 KB |
Output is correct |
54 |
Correct |
63 ms |
50592 KB |
Output is correct |
55 |
Correct |
118 ms |
91544 KB |
Output is correct |
56 |
Correct |
187 ms |
158328 KB |
Output is correct |
57 |
Correct |
167 ms |
164068 KB |
Output is correct |
58 |
Correct |
192 ms |
161084 KB |
Output is correct |
59 |
Correct |
162 ms |
127572 KB |
Output is correct |
60 |
Correct |
67 ms |
46920 KB |
Output is correct |
61 |
Correct |
91 ms |
76928 KB |
Output is correct |
62 |
Correct |
170 ms |
159048 KB |
Output is correct |
63 |
Correct |
190 ms |
163164 KB |
Output is correct |
64 |
Correct |
183 ms |
163180 KB |
Output is correct |
65 |
Correct |
530 ms |
107104 KB |
Output is correct |
66 |
Correct |
693 ms |
161764 KB |
Output is correct |
67 |
Correct |
768 ms |
160648 KB |
Output is correct |
68 |
Correct |
583 ms |
130716 KB |
Output is correct |
69 |
Correct |
680 ms |
129128 KB |
Output is correct |
70 |
Correct |
299 ms |
30236 KB |
Output is correct |
71 |
Correct |
668 ms |
161512 KB |
Output is correct |
72 |
Correct |
752 ms |
160764 KB |
Output is correct |
73 |
Correct |
621 ms |
130544 KB |
Output is correct |
74 |
Correct |
366 ms |
152576 KB |
Output is correct |
75 |
Correct |
389 ms |
161488 KB |
Output is correct |
76 |
Correct |
364 ms |
160344 KB |
Output is correct |
77 |
Correct |
345 ms |
131076 KB |
Output is correct |
78 |
Correct |
524 ms |
122084 KB |
Output is correct |
79 |
Correct |
1123 ms |
147952 KB |
Output is correct |
80 |
Correct |
1161 ms |
134768 KB |
Output is correct |
81 |
Correct |
542 ms |
54092 KB |
Output is correct |
82 |
Correct |
538 ms |
94988 KB |
Output is correct |
83 |
Correct |
686 ms |
161828 KB |
Output is correct |
84 |
Correct |
568 ms |
167560 KB |
Output is correct |
85 |
Correct |
579 ms |
164624 KB |
Output is correct |
86 |
Correct |
569 ms |
131144 KB |
Output is correct |
87 |
Correct |
384 ms |
50328 KB |
Output is correct |
88 |
Correct |
387 ms |
80544 KB |
Output is correct |
89 |
Correct |
485 ms |
162332 KB |
Output is correct |
90 |
Correct |
670 ms |
166856 KB |
Output is correct |
91 |
Correct |
583 ms |
166664 KB |
Output is correct |