#include "rainbow.h"
#include "bits/stdc++.h"
using namespace std;
int N, M;
typedef pair <int, int> pii;
struct Container {
vector <int> t[200010 * 4];
vector <pii> u;
void insert(int x, int y, int c, int b, int e) {
if(b == e) {
t[c].emplace_back(y);
return ;
}
int m = (b + e) >> 1;
int l = c << 1;
int r = l + 1;
if(x <= m) insert(x, y, l, b, m);
else insert(x, y, r, m + 1, e);
}
void build(int c, int b, int e) {
if(b == e) {
sort(t[c].begin(), t[c].end());
return ;
}
int m = (b + e) >> 1;
int l = c << 1;
int r = l + 1;
build(l, b, m);
build(r, m + 1, e);
merge(t[l].begin(), t[l].end(), t[r].begin(), t[r].end(), back_inserter(t[c]));
}
int count(int x, int y, int p, int q, int c, int b, int e) {
if(x <= b && e <= y) {
return upper_bound(t[c].begin(), t[c].end(), q) - lower_bound(t[c].begin(), t[c].end(), p);
}
if(y < b || e < x) return 0;
int l = c << 1;
int r = l + 1;
int m = (b + e) >> 1;
return count(x, y, p, q, l, b, m) + count(x, y, p, q, r, m + 1, e);
}
int count(int x, int y, int p, int q) {
int ans = 0;
for(auto i : u) {
if(x <= i.first && i.first <= y) {
if(p <= i.second && i.second <= q) {
++ans;
}
}
}
return ans;
}
void insert(int x, int y) {
u.emplace_back(x, y);
return ;
// insert(x, y, 1, 1, N);
}
void build() {
// build(1, 1, N);
}
} E1, E2, V, F;
int lx, rx, ly, ry;
void init(int R, int C, int sr, int sc, int len, char *S) {
N = R;
M = C;
vector <pii> u;
u.emplace_back(sr, sc);
// int len = strlen();
for(int i = 0; i < len; i++) {
if(S[i] == 'N') --sr;
else if (S[i] == 'S') ++sr;
else if (S[i] == 'W') --sc;
else ++sc;
u.emplace_back(sr, sc);
}
lx = N, ly = M;
rx = 1, ry = 1;
for(auto i : u) {
lx = min(lx, i.first);
ly = min(ly, i.second);
rx = max(rx, i.first);
ry = max(ry, i.second);
}
// cout << lx << ' ' << rx << ' ' << ly << ' ' << ry << endl;
// for(auto i : u) {
// cout << i.first << ' ' << i.second << endl;
// }
set <pii> s;
for(auto i : u) {
s.emplace(i.first, i.second);
s.emplace(i.first - 1, i.second);
s.emplace(i.first, i.second - 1);
s.emplace(i.first - 1, i.second - 1);
}
for(auto i : s) {
if(0 < i.first && 0 < i.second) {
F.insert(i.first, i.second);
}
}
s.clear();
for(auto i : u) {
s.emplace(i.first - 1, i.second);
s.emplace(i.first, i.second);
}
for(auto i : s) {
if(0 < i.first && 0 < i.second) {
E1.insert(i.first, i.second);
}
}
s.clear();
for(auto i : u) {
s.emplace(i.first, i.second - 1);
s.emplace(i.first, i.second);
}
for(auto i : s) {
if(0 < i.first && 0 < i.second) {
E2.insert(i.first, i.second);
}
}
s.clear();
for(auto i : u) {
s.emplace(i.first, i.second);
}
for(auto i : s) {
V.insert(i.first, i.second);
}
s.clear();
F.build();
V.build();
E1.build();
E2.build();
}
int colour(int ar, int ac, int br, int bc) {
long long cnt = 0;
int row = br - ar + 1;
int col = bc - ac + 1;
long long e = 0;
e += 1LL * (row - 1) * col;
e += 1LL * row * (col - 1);
e -= E1.count(ar, br - 1, ac, bc);
e -= E2.count(ar, br, ac, bc - 1);
long long v = 0;
v += 1LL * row * col;
v -= V.count(ar, br, ac, bc);
long long f = 1;
f += 1LL * (row - 1) * (col - 1);
f -= F.count(ar, br - 1, ac, bc - 1);
if(ar < lx && rx < br) {
if(ac < ly && ry < bc) {
f += 1;
}
}
cnt = v - e + f - 1;
return cnt;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
75520 KB |
Output is correct |
2 |
Correct |
88 ms |
75892 KB |
Output is correct |
3 |
Correct |
72 ms |
75512 KB |
Output is correct |
4 |
Correct |
72 ms |
75512 KB |
Output is correct |
5 |
Correct |
78 ms |
75644 KB |
Output is correct |
6 |
Correct |
65 ms |
75396 KB |
Output is correct |
7 |
Correct |
72 ms |
75488 KB |
Output is correct |
8 |
Correct |
66 ms |
75512 KB |
Output is correct |
9 |
Correct |
65 ms |
75512 KB |
Output is correct |
10 |
Correct |
73 ms |
75512 KB |
Output is correct |
11 |
Correct |
81 ms |
75512 KB |
Output is correct |
12 |
Correct |
81 ms |
75560 KB |
Output is correct |
13 |
Correct |
89 ms |
75752 KB |
Output is correct |
14 |
Correct |
93 ms |
75768 KB |
Output is correct |
15 |
Correct |
69 ms |
75512 KB |
Output is correct |
16 |
Correct |
66 ms |
75512 KB |
Output is correct |
17 |
Correct |
63 ms |
75516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
75512 KB |
Output is correct |
2 |
Correct |
63 ms |
75516 KB |
Output is correct |
3 |
Execution timed out |
3037 ms |
83860 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
75512 KB |
Output is correct |
2 |
Correct |
355 ms |
91524 KB |
Output is correct |
3 |
Correct |
329 ms |
91120 KB |
Output is correct |
4 |
Correct |
293 ms |
89272 KB |
Output is correct |
5 |
Correct |
284 ms |
86128 KB |
Output is correct |
6 |
Correct |
171 ms |
79000 KB |
Output is correct |
7 |
Correct |
222 ms |
81516 KB |
Output is correct |
8 |
Correct |
275 ms |
89416 KB |
Output is correct |
9 |
Correct |
296 ms |
87936 KB |
Output is correct |
10 |
Correct |
157 ms |
78832 KB |
Output is correct |
11 |
Correct |
303 ms |
83624 KB |
Output is correct |
12 |
Correct |
387 ms |
91620 KB |
Output is correct |
13 |
Correct |
344 ms |
91348 KB |
Output is correct |
14 |
Correct |
297 ms |
89392 KB |
Output is correct |
15 |
Correct |
283 ms |
86204 KB |
Output is correct |
16 |
Correct |
174 ms |
78568 KB |
Output is correct |
17 |
Correct |
244 ms |
81772 KB |
Output is correct |
18 |
Correct |
423 ms |
91732 KB |
Output is correct |
19 |
Correct |
340 ms |
90088 KB |
Output is correct |
20 |
Correct |
349 ms |
90228 KB |
Output is correct |
21 |
Correct |
330 ms |
89452 KB |
Output is correct |
22 |
Correct |
316 ms |
88040 KB |
Output is correct |
23 |
Correct |
159 ms |
78800 KB |
Output is correct |
24 |
Correct |
338 ms |
83432 KB |
Output is correct |
25 |
Correct |
428 ms |
91664 KB |
Output is correct |
26 |
Correct |
365 ms |
91276 KB |
Output is correct |
27 |
Correct |
336 ms |
89428 KB |
Output is correct |
28 |
Correct |
261 ms |
86204 KB |
Output is correct |
29 |
Correct |
169 ms |
78700 KB |
Output is correct |
30 |
Correct |
259 ms |
81720 KB |
Output is correct |
31 |
Correct |
374 ms |
91684 KB |
Output is correct |
32 |
Correct |
364 ms |
90084 KB |
Output is correct |
33 |
Correct |
335 ms |
90088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
75520 KB |
Output is correct |
2 |
Correct |
88 ms |
75892 KB |
Output is correct |
3 |
Correct |
72 ms |
75512 KB |
Output is correct |
4 |
Correct |
72 ms |
75512 KB |
Output is correct |
5 |
Correct |
78 ms |
75644 KB |
Output is correct |
6 |
Correct |
65 ms |
75396 KB |
Output is correct |
7 |
Correct |
72 ms |
75488 KB |
Output is correct |
8 |
Correct |
66 ms |
75512 KB |
Output is correct |
9 |
Correct |
65 ms |
75512 KB |
Output is correct |
10 |
Correct |
73 ms |
75512 KB |
Output is correct |
11 |
Correct |
81 ms |
75512 KB |
Output is correct |
12 |
Correct |
81 ms |
75560 KB |
Output is correct |
13 |
Correct |
89 ms |
75752 KB |
Output is correct |
14 |
Correct |
93 ms |
75768 KB |
Output is correct |
15 |
Correct |
69 ms |
75512 KB |
Output is correct |
16 |
Correct |
66 ms |
75512 KB |
Output is correct |
17 |
Correct |
63 ms |
75516 KB |
Output is correct |
18 |
Execution timed out |
3015 ms |
84324 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
75520 KB |
Output is correct |
2 |
Correct |
88 ms |
75892 KB |
Output is correct |
3 |
Correct |
72 ms |
75512 KB |
Output is correct |
4 |
Correct |
72 ms |
75512 KB |
Output is correct |
5 |
Correct |
78 ms |
75644 KB |
Output is correct |
6 |
Correct |
65 ms |
75396 KB |
Output is correct |
7 |
Correct |
72 ms |
75488 KB |
Output is correct |
8 |
Correct |
66 ms |
75512 KB |
Output is correct |
9 |
Correct |
65 ms |
75512 KB |
Output is correct |
10 |
Correct |
73 ms |
75512 KB |
Output is correct |
11 |
Correct |
81 ms |
75512 KB |
Output is correct |
12 |
Correct |
81 ms |
75560 KB |
Output is correct |
13 |
Correct |
89 ms |
75752 KB |
Output is correct |
14 |
Correct |
93 ms |
75768 KB |
Output is correct |
15 |
Correct |
69 ms |
75512 KB |
Output is correct |
16 |
Correct |
66 ms |
75512 KB |
Output is correct |
17 |
Correct |
63 ms |
75516 KB |
Output is correct |
18 |
Execution timed out |
3015 ms |
84324 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |