#include "rainbow.h"
#include <algorithm>
#include <vector>
#include <tuple>
#define x first
#define y second
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define sort_and_unique(v) { sort(all(v)); v.erase(unique(all(v)), v.end()); }
using namespace std;
using pp=pair<int,int>;
using ll=long long;
const int maxm = int(1e5) + 10;
vector<pp> riv, eh, ev, e4;
void River(int sx, int sy, int m, char *s) {
riv.resize(m+1);
for (int i=0; i<m; ++i) {
riv[i] = {sx, sy};
if (s[i] == 'S') ++sx; else if (s[i] == 'N') --sx;
else if (s[i] == 'E') ++sy; else --sy;
}
riv[m++] = {sx, sy};
sort_and_unique(riv); m = riv.size();
eh = riv; ev = riv; eh.resize(2*m); ev.resize(2*m);
for (int i=0, x, y; i<m; ++i) { tie(x, y) = riv[i];
eh[m+i] = {x, y-1}; ev[m+i] = {x-1, y};
}
sort_and_unique(eh); sort_and_unique(ev);
e4 = riv; e4.resize(4*m);
for (int i=0, j=m, x, y; i<m; ++i) { tie(x, y) = riv[i];
e4[j++] = {x-1, y};
e4[j++] = {x, y-1};
e4[j++] = {x-1, y-1};
}
sort_and_unique(e4);
}
struct MST {
const static int M = 262144;
vector<int> t[M<<1];
void put(int x, int y) { t[M+x].pb(y); }
void init() {
for (int i=0; i<M; ++i) sort(all(t[M+i]));
for (int i=M-1; 1<=i; --i) {
static int tmp[4*maxm];
t[i] = vector<int>(tmp, merge(all(t[i*2]), all(t[i*2+1]), tmp));
}
}
int rq(int l, int r, int d, int u) { if (d>u) return 0;
int x = 0;
auto vq = [&](const vector<int> &v) -> int {
return upper_bound(all(v), u) - lower_bound(all(v), d);
};
for (l+=M, r+=M; l<=r; l/=2, r/=2) {
if (l%2 == 1) x += vq(t[l++]);
if (r%2 == 0) x += vq(t[r--]);
}
return x;
}
} triv, teh, tev, te4;
void Write() {
#define wr(v, t) for (auto &tmp:v) t.put(tmp.x, tmp.y); t.init();
wr(riv, triv);
wr(eh, teh);
wr(ev, tev);
wr(e4, te4);
#undef wr
}
pp rmn, rmx;
void init(int R, int C, int sr, int sc, int M, char *S) {
River(sr, sc, M, S);
Write();
rmn = {1e9, 1e9};
rmx = {-1e9, -1e9};
for (auto &tmp:riv) {
rmn.x = min(rmn.x, tmp.x);
rmn.y = min(rmn.y, tmp.y);
rmx.x = max(rmx.x, tmp.x);
rmx.y = max(rmx.y, tmp.y);
}
}
int colour(int ar, int ac, int br, int bc) {
ll w = br-ar+1, h = bc-ac+1;
ll inv = w * h;
ll ine = (w-1)*h + w*(h-1);
ll inf = (w-1)*(h-1);
inv -= triv.rq(ar, br, ac, bc);
ine -= teh.rq(ar, br, ac, bc-1);
ine -= tev.rq(ar, br-1, ac, bc);
inf -= te4.rq(ar, br-1, ac, bc-1);
if (ar < rmn.x && rmx.x < br &&
ac < rmn.y && rmn.y < bc) ++inf;
return inv - ine + inf;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
49600 KB |
Output is correct |
2 |
Correct |
38 ms |
49956 KB |
Output is correct |
3 |
Incorrect |
38 ms |
49612 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
49576 KB |
Output is correct |
2 |
Correct |
37 ms |
49512 KB |
Output is correct |
3 |
Correct |
213 ms |
81852 KB |
Output is correct |
4 |
Correct |
262 ms |
103256 KB |
Output is correct |
5 |
Correct |
265 ms |
102844 KB |
Output is correct |
6 |
Correct |
245 ms |
91156 KB |
Output is correct |
7 |
Correct |
245 ms |
90240 KB |
Output is correct |
8 |
Correct |
105 ms |
51204 KB |
Output is correct |
9 |
Correct |
281 ms |
103252 KB |
Output is correct |
10 |
Correct |
296 ms |
102828 KB |
Output is correct |
11 |
Correct |
243 ms |
91164 KB |
Output is correct |
12 |
Correct |
208 ms |
99308 KB |
Output is correct |
13 |
Correct |
215 ms |
103332 KB |
Output is correct |
14 |
Correct |
206 ms |
102936 KB |
Output is correct |
15 |
Correct |
232 ms |
91292 KB |
Output is correct |
16 |
Correct |
208 ms |
87840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
49484 KB |
Output is correct |
2 |
Correct |
134 ms |
102624 KB |
Output is correct |
3 |
Correct |
205 ms |
119304 KB |
Output is correct |
4 |
Correct |
188 ms |
108708 KB |
Output is correct |
5 |
Correct |
170 ms |
97632 KB |
Output is correct |
6 |
Correct |
82 ms |
60612 KB |
Output is correct |
7 |
Correct |
100 ms |
70796 KB |
Output is correct |
8 |
Correct |
137 ms |
97044 KB |
Output is correct |
9 |
Correct |
128 ms |
91700 KB |
Output is correct |
10 |
Correct |
68 ms |
60584 KB |
Output is correct |
11 |
Correct |
97 ms |
76072 KB |
Output is correct |
12 |
Correct |
132 ms |
102564 KB |
Output is correct |
13 |
Correct |
233 ms |
119240 KB |
Output is correct |
14 |
Correct |
191 ms |
108708 KB |
Output is correct |
15 |
Correct |
157 ms |
97724 KB |
Output is correct |
16 |
Correct |
66 ms |
58580 KB |
Output is correct |
17 |
Correct |
103 ms |
70932 KB |
Output is correct |
18 |
Correct |
158 ms |
102820 KB |
Output is correct |
19 |
Correct |
163 ms |
110632 KB |
Output is correct |
20 |
Correct |
167 ms |
110636 KB |
Output is correct |
21 |
Correct |
134 ms |
97084 KB |
Output is correct |
22 |
Correct |
127 ms |
91748 KB |
Output is correct |
23 |
Correct |
73 ms |
60540 KB |
Output is correct |
24 |
Correct |
99 ms |
75988 KB |
Output is correct |
25 |
Correct |
140 ms |
102568 KB |
Output is correct |
26 |
Correct |
208 ms |
119304 KB |
Output is correct |
27 |
Correct |
191 ms |
108708 KB |
Output is correct |
28 |
Correct |
158 ms |
97692 KB |
Output is correct |
29 |
Correct |
69 ms |
58608 KB |
Output is correct |
30 |
Correct |
110 ms |
70932 KB |
Output is correct |
31 |
Correct |
155 ms |
102852 KB |
Output is correct |
32 |
Correct |
160 ms |
110628 KB |
Output is correct |
33 |
Correct |
169 ms |
110636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
49600 KB |
Output is correct |
2 |
Correct |
38 ms |
49956 KB |
Output is correct |
3 |
Incorrect |
38 ms |
49612 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
49600 KB |
Output is correct |
2 |
Correct |
38 ms |
49956 KB |
Output is correct |
3 |
Incorrect |
38 ms |
49612 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |