/* be name khoda */
// #define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <vector>
#include <fstream>
#include <set>
#include <map>
using namespace std;
#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif
typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;
#define forifrom(i, s, n) for (ll i = s; i < n; ++i)
#define forirto(i, n, e) for (ll i = (n) - 1; i >= e; --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))
#define debug(x) cout << #x << " -> " << (x) << endl
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl
const ll MOD = 1000000007;
const ll INF = 2000000000;
const long long BIG = 1446803456761533460LL;
#define XL (x << 1)
#define XR (XL | 1)
#define MD ((l + r) >> 1)
#define Add(a, b) a = ((a) + (b)) % MOD
#define Mul(a, b) a = (1LL * (a) * (b)) % MOD
// -----------------------------------------------------------------------
const ll maxn = 400000 + 10;
ll n, m, rmn = maxn, rmx = 0, cmn = maxn, cmx = 0;
pii d[256];
struct Segment {
ll m = 0;
pii pts[maxn];
vi seg[maxn * 2];
void add(ll r, ll c) {
pts[m++] = {r, c};
}
void build() {
sort(pts, pts + m);
m = unique(pts, pts + m) - pts;
fori (i, m) seg[pts[i].F + n].eb(pts[i].S);
forirto (i, n, 1) {
ll lsz = seg[i << 1].size(), rsz = seg[i << 1 ^ 1].size();
seg[i].resize(lsz + rsz);
merge(all(seg[i << 1]), all(seg[i << 1 ^ 1]), seg[i].begin());
}
}
inline ll count(vi &ar, ll l, ll r) {
return lower_bound(all(ar), r) - lower_bound(all(ar), l);
}
ll get(ll l1, ll r1, ll l2, ll r2) {
ll s = 0;
for (l1 += n, r1 += n; l1 < r1; l1 >>= 1, r1 >>= 1) {
if (l1 & 1) s += count(seg[l1], l2, r2), ++l1;
if (r1 & 1) --r1, s += count(seg[r1], l2, r2);
}
return s;
}
} verts, edgesV, edgesH, faces;
void move(ll r, ll c) {
smin(rmn, r), smax(rmx, r);
smin(cmn, c), smax(cmx, c);
faces.add(r, c);
fori (i, 4) verts.add(r + (i & 1), c + (i >> 1));
fori (i, 2) edgesV.add(r, c + i), edgesH.add(r + i, c);
}
void init(ll Ri, ll Ci, ll sr, ll sc, ll M, char *P) {
d['N'] = {-1, 0};
d['S'] = {1, 0};
d['W'] = {0, -1};
d['E'] = {0, 1};
n = Ri, m = Ci;
--sr, --sc;
move(sr, sc);
fori (i, M) {
sr += d[(ll) P[i]].F, sc += d[(ll) P[i]].S;
move(sr, sc);
}
verts.build();
edgesV.build();
edgesH.build();
faces.build();
}
ll colour(ll ar, ll ac, ll br, ll bc) {
--ar, --ac;
ll v = verts.get(ar + 1, br, ac + 1, bc);
ll e = edgesV.get(ar, br, ac + 1, bc) + edgesH.get(ar + 1, br, ac, bc);
ll river = faces.get(ar, br, ac, bc);
bool inside = (ar < rmn && rmx < br - 1 && ac < cmn && cmx < bc - 1);
ll c = 1 + inside;
ll f = c - v + e + 1 - 1; // c = v - e + (f - 1) (-1 was for big face)
ll ans = f - river;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
88056 KB |
Output is correct |
2 |
Correct |
63 ms |
88184 KB |
Output is correct |
3 |
Correct |
62 ms |
88056 KB |
Output is correct |
4 |
Correct |
61 ms |
88068 KB |
Output is correct |
5 |
Correct |
63 ms |
88188 KB |
Output is correct |
6 |
Correct |
59 ms |
87928 KB |
Output is correct |
7 |
Correct |
58 ms |
87932 KB |
Output is correct |
8 |
Correct |
59 ms |
87932 KB |
Output is correct |
9 |
Correct |
60 ms |
88032 KB |
Output is correct |
10 |
Correct |
58 ms |
87928 KB |
Output is correct |
11 |
Correct |
62 ms |
88056 KB |
Output is correct |
12 |
Correct |
62 ms |
88184 KB |
Output is correct |
13 |
Correct |
62 ms |
88312 KB |
Output is correct |
14 |
Correct |
65 ms |
88312 KB |
Output is correct |
15 |
Correct |
59 ms |
87928 KB |
Output is correct |
16 |
Correct |
58 ms |
87928 KB |
Output is correct |
17 |
Correct |
58 ms |
87928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
87928 KB |
Output is correct |
2 |
Correct |
58 ms |
87928 KB |
Output is correct |
3 |
Correct |
214 ms |
94580 KB |
Output is correct |
4 |
Correct |
243 ms |
96336 KB |
Output is correct |
5 |
Correct |
248 ms |
96372 KB |
Output is correct |
6 |
Correct |
240 ms |
95136 KB |
Output is correct |
7 |
Correct |
254 ms |
95092 KB |
Output is correct |
8 |
Correct |
159 ms |
91640 KB |
Output is correct |
9 |
Correct |
255 ms |
96496 KB |
Output is correct |
10 |
Correct |
255 ms |
96368 KB |
Output is correct |
11 |
Correct |
245 ms |
95092 KB |
Output is correct |
12 |
Correct |
183 ms |
95856 KB |
Output is correct |
13 |
Correct |
184 ms |
96240 KB |
Output is correct |
14 |
Correct |
194 ms |
96172 KB |
Output is correct |
15 |
Correct |
218 ms |
95092 KB |
Output is correct |
16 |
Correct |
216 ms |
95124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
87928 KB |
Output is correct |
2 |
Correct |
145 ms |
133100 KB |
Output is correct |
3 |
Correct |
176 ms |
149880 KB |
Output is correct |
4 |
Correct |
156 ms |
137208 KB |
Output is correct |
5 |
Correct |
155 ms |
129528 KB |
Output is correct |
6 |
Correct |
137 ms |
96760 KB |
Output is correct |
7 |
Correct |
160 ms |
105384 KB |
Output is correct |
8 |
Correct |
127 ms |
94980 KB |
Output is correct |
9 |
Correct |
141 ms |
95864 KB |
Output is correct |
10 |
Correct |
107 ms |
96416 KB |
Output is correct |
11 |
Correct |
148 ms |
106872 KB |
Output is correct |
12 |
Correct |
145 ms |
133104 KB |
Output is correct |
13 |
Correct |
182 ms |
149880 KB |
Output is correct |
14 |
Correct |
158 ms |
137336 KB |
Output is correct |
15 |
Correct |
151 ms |
129532 KB |
Output is correct |
16 |
Correct |
144 ms |
94968 KB |
Output is correct |
17 |
Correct |
153 ms |
104568 KB |
Output is correct |
18 |
Correct |
168 ms |
131320 KB |
Output is correct |
19 |
Correct |
155 ms |
139148 KB |
Output is correct |
20 |
Correct |
158 ms |
139116 KB |
Output is correct |
21 |
Correct |
122 ms |
94980 KB |
Output is correct |
22 |
Correct |
137 ms |
95864 KB |
Output is correct |
23 |
Correct |
108 ms |
96376 KB |
Output is correct |
24 |
Correct |
148 ms |
106872 KB |
Output is correct |
25 |
Correct |
142 ms |
133104 KB |
Output is correct |
26 |
Correct |
175 ms |
149880 KB |
Output is correct |
27 |
Correct |
155 ms |
137208 KB |
Output is correct |
28 |
Correct |
152 ms |
129528 KB |
Output is correct |
29 |
Correct |
144 ms |
94972 KB |
Output is correct |
30 |
Correct |
159 ms |
104616 KB |
Output is correct |
31 |
Correct |
172 ms |
131320 KB |
Output is correct |
32 |
Correct |
158 ms |
139248 KB |
Output is correct |
33 |
Correct |
162 ms |
139124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
88056 KB |
Output is correct |
2 |
Correct |
63 ms |
88184 KB |
Output is correct |
3 |
Correct |
62 ms |
88056 KB |
Output is correct |
4 |
Correct |
61 ms |
88068 KB |
Output is correct |
5 |
Correct |
63 ms |
88188 KB |
Output is correct |
6 |
Correct |
59 ms |
87928 KB |
Output is correct |
7 |
Correct |
58 ms |
87932 KB |
Output is correct |
8 |
Correct |
59 ms |
87932 KB |
Output is correct |
9 |
Correct |
60 ms |
88032 KB |
Output is correct |
10 |
Correct |
58 ms |
87928 KB |
Output is correct |
11 |
Correct |
62 ms |
88056 KB |
Output is correct |
12 |
Correct |
62 ms |
88184 KB |
Output is correct |
13 |
Correct |
62 ms |
88312 KB |
Output is correct |
14 |
Correct |
65 ms |
88312 KB |
Output is correct |
15 |
Correct |
59 ms |
87928 KB |
Output is correct |
16 |
Correct |
58 ms |
87928 KB |
Output is correct |
17 |
Correct |
58 ms |
87928 KB |
Output is correct |
18 |
Correct |
1132 ms |
105108 KB |
Output is correct |
19 |
Correct |
224 ms |
92024 KB |
Output is correct |
20 |
Correct |
207 ms |
91512 KB |
Output is correct |
21 |
Correct |
212 ms |
91640 KB |
Output is correct |
22 |
Correct |
225 ms |
91768 KB |
Output is correct |
23 |
Correct |
205 ms |
91896 KB |
Output is correct |
24 |
Correct |
290 ms |
91512 KB |
Output is correct |
25 |
Correct |
262 ms |
91784 KB |
Output is correct |
26 |
Correct |
252 ms |
91992 KB |
Output is correct |
27 |
Correct |
545 ms |
102776 KB |
Output is correct |
28 |
Correct |
449 ms |
96888 KB |
Output is correct |
29 |
Correct |
474 ms |
101880 KB |
Output is correct |
30 |
Correct |
827 ms |
118220 KB |
Output is correct |
31 |
Correct |
61 ms |
88056 KB |
Output is correct |
32 |
Correct |
879 ms |
102860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
88056 KB |
Output is correct |
2 |
Correct |
63 ms |
88184 KB |
Output is correct |
3 |
Correct |
62 ms |
88056 KB |
Output is correct |
4 |
Correct |
61 ms |
88068 KB |
Output is correct |
5 |
Correct |
63 ms |
88188 KB |
Output is correct |
6 |
Correct |
59 ms |
87928 KB |
Output is correct |
7 |
Correct |
58 ms |
87932 KB |
Output is correct |
8 |
Correct |
59 ms |
87932 KB |
Output is correct |
9 |
Correct |
60 ms |
88032 KB |
Output is correct |
10 |
Correct |
58 ms |
87928 KB |
Output is correct |
11 |
Correct |
62 ms |
88056 KB |
Output is correct |
12 |
Correct |
62 ms |
88184 KB |
Output is correct |
13 |
Correct |
62 ms |
88312 KB |
Output is correct |
14 |
Correct |
65 ms |
88312 KB |
Output is correct |
15 |
Correct |
59 ms |
87928 KB |
Output is correct |
16 |
Correct |
58 ms |
87928 KB |
Output is correct |
17 |
Correct |
58 ms |
87928 KB |
Output is correct |
18 |
Correct |
1132 ms |
105108 KB |
Output is correct |
19 |
Correct |
224 ms |
92024 KB |
Output is correct |
20 |
Correct |
207 ms |
91512 KB |
Output is correct |
21 |
Correct |
212 ms |
91640 KB |
Output is correct |
22 |
Correct |
225 ms |
91768 KB |
Output is correct |
23 |
Correct |
205 ms |
91896 KB |
Output is correct |
24 |
Correct |
290 ms |
91512 KB |
Output is correct |
25 |
Correct |
262 ms |
91784 KB |
Output is correct |
26 |
Correct |
252 ms |
91992 KB |
Output is correct |
27 |
Correct |
545 ms |
102776 KB |
Output is correct |
28 |
Correct |
449 ms |
96888 KB |
Output is correct |
29 |
Correct |
474 ms |
101880 KB |
Output is correct |
30 |
Correct |
827 ms |
118220 KB |
Output is correct |
31 |
Correct |
61 ms |
88056 KB |
Output is correct |
32 |
Correct |
879 ms |
102860 KB |
Output is correct |
33 |
Correct |
145 ms |
133100 KB |
Output is correct |
34 |
Correct |
176 ms |
149880 KB |
Output is correct |
35 |
Correct |
156 ms |
137208 KB |
Output is correct |
36 |
Correct |
155 ms |
129528 KB |
Output is correct |
37 |
Correct |
137 ms |
96760 KB |
Output is correct |
38 |
Correct |
160 ms |
105384 KB |
Output is correct |
39 |
Correct |
127 ms |
94980 KB |
Output is correct |
40 |
Correct |
141 ms |
95864 KB |
Output is correct |
41 |
Correct |
107 ms |
96416 KB |
Output is correct |
42 |
Correct |
148 ms |
106872 KB |
Output is correct |
43 |
Correct |
145 ms |
133104 KB |
Output is correct |
44 |
Correct |
182 ms |
149880 KB |
Output is correct |
45 |
Correct |
158 ms |
137336 KB |
Output is correct |
46 |
Correct |
151 ms |
129532 KB |
Output is correct |
47 |
Correct |
144 ms |
94968 KB |
Output is correct |
48 |
Correct |
153 ms |
104568 KB |
Output is correct |
49 |
Correct |
168 ms |
131320 KB |
Output is correct |
50 |
Correct |
155 ms |
139148 KB |
Output is correct |
51 |
Correct |
158 ms |
139116 KB |
Output is correct |
52 |
Correct |
122 ms |
94980 KB |
Output is correct |
53 |
Correct |
137 ms |
95864 KB |
Output is correct |
54 |
Correct |
108 ms |
96376 KB |
Output is correct |
55 |
Correct |
148 ms |
106872 KB |
Output is correct |
56 |
Correct |
142 ms |
133104 KB |
Output is correct |
57 |
Correct |
175 ms |
149880 KB |
Output is correct |
58 |
Correct |
155 ms |
137208 KB |
Output is correct |
59 |
Correct |
152 ms |
129528 KB |
Output is correct |
60 |
Correct |
144 ms |
94972 KB |
Output is correct |
61 |
Correct |
159 ms |
104616 KB |
Output is correct |
62 |
Correct |
172 ms |
131320 KB |
Output is correct |
63 |
Correct |
158 ms |
139248 KB |
Output is correct |
64 |
Correct |
162 ms |
139124 KB |
Output is correct |
65 |
Correct |
367 ms |
98436 KB |
Output is correct |
66 |
Correct |
434 ms |
99448 KB |
Output is correct |
67 |
Correct |
392 ms |
99872 KB |
Output is correct |
68 |
Correct |
536 ms |
110328 KB |
Output is correct |
69 |
Correct |
449 ms |
136556 KB |
Output is correct |
70 |
Correct |
893 ms |
153592 KB |
Output is correct |
71 |
Correct |
529 ms |
140684 KB |
Output is correct |
72 |
Correct |
575 ms |
133244 KB |
Output is correct |
73 |
Correct |
394 ms |
98552 KB |
Output is correct |
74 |
Correct |
389 ms |
108280 KB |
Output is correct |
75 |
Correct |
396 ms |
134904 KB |
Output is correct |
76 |
Correct |
684 ms |
142836 KB |
Output is correct |
77 |
Correct |
755 ms |
142708 KB |
Output is correct |
78 |
Correct |
214 ms |
94580 KB |
Output is correct |
79 |
Correct |
243 ms |
96336 KB |
Output is correct |
80 |
Correct |
248 ms |
96372 KB |
Output is correct |
81 |
Correct |
240 ms |
95136 KB |
Output is correct |
82 |
Correct |
254 ms |
95092 KB |
Output is correct |
83 |
Correct |
159 ms |
91640 KB |
Output is correct |
84 |
Correct |
255 ms |
96496 KB |
Output is correct |
85 |
Correct |
255 ms |
96368 KB |
Output is correct |
86 |
Correct |
245 ms |
95092 KB |
Output is correct |
87 |
Correct |
183 ms |
95856 KB |
Output is correct |
88 |
Correct |
184 ms |
96240 KB |
Output is correct |
89 |
Correct |
194 ms |
96172 KB |
Output is correct |
90 |
Correct |
218 ms |
95092 KB |
Output is correct |
91 |
Correct |
216 ms |
95124 KB |
Output is correct |