/* 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 {
vi seg[maxn * 2];
void add(ll r, ll c) {
seg[r + n].eb(c);
}
void build() {
fori (i, n) {
sort(all(seg[i + n]));
seg[i + n].resize(unique(all(seg[i + n])) - seg[i + n].begin());
}
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
75512 KB |
Output is correct |
2 |
Correct |
51 ms |
75640 KB |
Output is correct |
3 |
Correct |
50 ms |
75508 KB |
Output is correct |
4 |
Correct |
50 ms |
75512 KB |
Output is correct |
5 |
Correct |
53 ms |
75768 KB |
Output is correct |
6 |
Correct |
48 ms |
75512 KB |
Output is correct |
7 |
Correct |
51 ms |
75520 KB |
Output is correct |
8 |
Correct |
48 ms |
75432 KB |
Output is correct |
9 |
Correct |
50 ms |
75512 KB |
Output is correct |
10 |
Correct |
49 ms |
75512 KB |
Output is correct |
11 |
Correct |
50 ms |
75512 KB |
Output is correct |
12 |
Correct |
53 ms |
75640 KB |
Output is correct |
13 |
Correct |
53 ms |
75768 KB |
Output is correct |
14 |
Correct |
54 ms |
75896 KB |
Output is correct |
15 |
Correct |
48 ms |
75512 KB |
Output is correct |
16 |
Correct |
49 ms |
75512 KB |
Output is correct |
17 |
Correct |
51 ms |
75512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
75512 KB |
Output is correct |
2 |
Correct |
51 ms |
75512 KB |
Output is correct |
3 |
Correct |
170 ms |
79976 KB |
Output is correct |
4 |
Correct |
197 ms |
82660 KB |
Output is correct |
5 |
Correct |
202 ms |
82268 KB |
Output is correct |
6 |
Correct |
176 ms |
82016 KB |
Output is correct |
7 |
Correct |
212 ms |
81748 KB |
Output is correct |
8 |
Correct |
139 ms |
80740 KB |
Output is correct |
9 |
Correct |
204 ms |
82260 KB |
Output is correct |
10 |
Correct |
215 ms |
82016 KB |
Output is correct |
11 |
Correct |
193 ms |
81756 KB |
Output is correct |
12 |
Correct |
138 ms |
81768 KB |
Output is correct |
13 |
Correct |
147 ms |
82468 KB |
Output is correct |
14 |
Correct |
143 ms |
82372 KB |
Output is correct |
15 |
Correct |
146 ms |
81884 KB |
Output is correct |
16 |
Correct |
169 ms |
80944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
75512 KB |
Output is correct |
2 |
Correct |
113 ms |
121888 KB |
Output is correct |
3 |
Correct |
184 ms |
137200 KB |
Output is correct |
4 |
Correct |
149 ms |
125304 KB |
Output is correct |
5 |
Correct |
154 ms |
117708 KB |
Output is correct |
6 |
Correct |
104 ms |
88568 KB |
Output is correct |
7 |
Correct |
110 ms |
96248 KB |
Output is correct |
8 |
Correct |
97 ms |
83940 KB |
Output is correct |
9 |
Correct |
100 ms |
85480 KB |
Output is correct |
10 |
Correct |
84 ms |
85368 KB |
Output is correct |
11 |
Correct |
113 ms |
97120 KB |
Output is correct |
12 |
Correct |
111 ms |
121796 KB |
Output is correct |
13 |
Correct |
182 ms |
137336 KB |
Output is correct |
14 |
Correct |
146 ms |
125304 KB |
Output is correct |
15 |
Correct |
152 ms |
117600 KB |
Output is correct |
16 |
Correct |
104 ms |
86648 KB |
Output is correct |
17 |
Correct |
112 ms |
95736 KB |
Output is correct |
18 |
Correct |
123 ms |
120184 KB |
Output is correct |
19 |
Correct |
146 ms |
127152 KB |
Output is correct |
20 |
Correct |
141 ms |
127164 KB |
Output is correct |
21 |
Correct |
96 ms |
83940 KB |
Output is correct |
22 |
Correct |
102 ms |
85484 KB |
Output is correct |
23 |
Correct |
82 ms |
85396 KB |
Output is correct |
24 |
Correct |
104 ms |
97132 KB |
Output is correct |
25 |
Correct |
112 ms |
121804 KB |
Output is correct |
26 |
Correct |
183 ms |
137336 KB |
Output is correct |
27 |
Correct |
153 ms |
125304 KB |
Output is correct |
28 |
Correct |
152 ms |
117600 KB |
Output is correct |
29 |
Correct |
100 ms |
86716 KB |
Output is correct |
30 |
Correct |
111 ms |
95864 KB |
Output is correct |
31 |
Correct |
123 ms |
120184 KB |
Output is correct |
32 |
Correct |
141 ms |
127200 KB |
Output is correct |
33 |
Correct |
143 ms |
127072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
75512 KB |
Output is correct |
2 |
Correct |
51 ms |
75640 KB |
Output is correct |
3 |
Correct |
50 ms |
75508 KB |
Output is correct |
4 |
Correct |
50 ms |
75512 KB |
Output is correct |
5 |
Correct |
53 ms |
75768 KB |
Output is correct |
6 |
Correct |
48 ms |
75512 KB |
Output is correct |
7 |
Correct |
51 ms |
75520 KB |
Output is correct |
8 |
Correct |
48 ms |
75432 KB |
Output is correct |
9 |
Correct |
50 ms |
75512 KB |
Output is correct |
10 |
Correct |
49 ms |
75512 KB |
Output is correct |
11 |
Correct |
50 ms |
75512 KB |
Output is correct |
12 |
Correct |
53 ms |
75640 KB |
Output is correct |
13 |
Correct |
53 ms |
75768 KB |
Output is correct |
14 |
Correct |
54 ms |
75896 KB |
Output is correct |
15 |
Correct |
48 ms |
75512 KB |
Output is correct |
16 |
Correct |
49 ms |
75512 KB |
Output is correct |
17 |
Correct |
51 ms |
75512 KB |
Output is correct |
18 |
Correct |
1097 ms |
92812 KB |
Output is correct |
19 |
Correct |
211 ms |
76792 KB |
Output is correct |
20 |
Correct |
194 ms |
76280 KB |
Output is correct |
21 |
Correct |
203 ms |
76408 KB |
Output is correct |
22 |
Correct |
232 ms |
76536 KB |
Output is correct |
23 |
Correct |
189 ms |
76664 KB |
Output is correct |
24 |
Correct |
257 ms |
76408 KB |
Output is correct |
25 |
Correct |
239 ms |
76676 KB |
Output is correct |
26 |
Correct |
234 ms |
76664 KB |
Output is correct |
27 |
Correct |
476 ms |
90744 KB |
Output is correct |
28 |
Correct |
402 ms |
85880 KB |
Output is correct |
29 |
Correct |
425 ms |
90232 KB |
Output is correct |
30 |
Correct |
770 ms |
104312 KB |
Output is correct |
31 |
Correct |
53 ms |
75512 KB |
Output is correct |
32 |
Correct |
818 ms |
90428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
75512 KB |
Output is correct |
2 |
Correct |
51 ms |
75640 KB |
Output is correct |
3 |
Correct |
50 ms |
75508 KB |
Output is correct |
4 |
Correct |
50 ms |
75512 KB |
Output is correct |
5 |
Correct |
53 ms |
75768 KB |
Output is correct |
6 |
Correct |
48 ms |
75512 KB |
Output is correct |
7 |
Correct |
51 ms |
75520 KB |
Output is correct |
8 |
Correct |
48 ms |
75432 KB |
Output is correct |
9 |
Correct |
50 ms |
75512 KB |
Output is correct |
10 |
Correct |
49 ms |
75512 KB |
Output is correct |
11 |
Correct |
50 ms |
75512 KB |
Output is correct |
12 |
Correct |
53 ms |
75640 KB |
Output is correct |
13 |
Correct |
53 ms |
75768 KB |
Output is correct |
14 |
Correct |
54 ms |
75896 KB |
Output is correct |
15 |
Correct |
48 ms |
75512 KB |
Output is correct |
16 |
Correct |
49 ms |
75512 KB |
Output is correct |
17 |
Correct |
51 ms |
75512 KB |
Output is correct |
18 |
Correct |
1097 ms |
92812 KB |
Output is correct |
19 |
Correct |
211 ms |
76792 KB |
Output is correct |
20 |
Correct |
194 ms |
76280 KB |
Output is correct |
21 |
Correct |
203 ms |
76408 KB |
Output is correct |
22 |
Correct |
232 ms |
76536 KB |
Output is correct |
23 |
Correct |
189 ms |
76664 KB |
Output is correct |
24 |
Correct |
257 ms |
76408 KB |
Output is correct |
25 |
Correct |
239 ms |
76676 KB |
Output is correct |
26 |
Correct |
234 ms |
76664 KB |
Output is correct |
27 |
Correct |
476 ms |
90744 KB |
Output is correct |
28 |
Correct |
402 ms |
85880 KB |
Output is correct |
29 |
Correct |
425 ms |
90232 KB |
Output is correct |
30 |
Correct |
770 ms |
104312 KB |
Output is correct |
31 |
Correct |
53 ms |
75512 KB |
Output is correct |
32 |
Correct |
818 ms |
90428 KB |
Output is correct |
33 |
Correct |
113 ms |
121888 KB |
Output is correct |
34 |
Correct |
184 ms |
137200 KB |
Output is correct |
35 |
Correct |
149 ms |
125304 KB |
Output is correct |
36 |
Correct |
154 ms |
117708 KB |
Output is correct |
37 |
Correct |
104 ms |
88568 KB |
Output is correct |
38 |
Correct |
110 ms |
96248 KB |
Output is correct |
39 |
Correct |
97 ms |
83940 KB |
Output is correct |
40 |
Correct |
100 ms |
85480 KB |
Output is correct |
41 |
Correct |
84 ms |
85368 KB |
Output is correct |
42 |
Correct |
113 ms |
97120 KB |
Output is correct |
43 |
Correct |
111 ms |
121796 KB |
Output is correct |
44 |
Correct |
182 ms |
137336 KB |
Output is correct |
45 |
Correct |
146 ms |
125304 KB |
Output is correct |
46 |
Correct |
152 ms |
117600 KB |
Output is correct |
47 |
Correct |
104 ms |
86648 KB |
Output is correct |
48 |
Correct |
112 ms |
95736 KB |
Output is correct |
49 |
Correct |
123 ms |
120184 KB |
Output is correct |
50 |
Correct |
146 ms |
127152 KB |
Output is correct |
51 |
Correct |
141 ms |
127164 KB |
Output is correct |
52 |
Correct |
96 ms |
83940 KB |
Output is correct |
53 |
Correct |
102 ms |
85484 KB |
Output is correct |
54 |
Correct |
82 ms |
85396 KB |
Output is correct |
55 |
Correct |
104 ms |
97132 KB |
Output is correct |
56 |
Correct |
112 ms |
121804 KB |
Output is correct |
57 |
Correct |
183 ms |
137336 KB |
Output is correct |
58 |
Correct |
153 ms |
125304 KB |
Output is correct |
59 |
Correct |
152 ms |
117600 KB |
Output is correct |
60 |
Correct |
100 ms |
86716 KB |
Output is correct |
61 |
Correct |
111 ms |
95864 KB |
Output is correct |
62 |
Correct |
123 ms |
120184 KB |
Output is correct |
63 |
Correct |
141 ms |
127200 KB |
Output is correct |
64 |
Correct |
143 ms |
127072 KB |
Output is correct |
65 |
Correct |
359 ms |
84708 KB |
Output is correct |
66 |
Correct |
407 ms |
86216 KB |
Output is correct |
67 |
Correct |
360 ms |
86136 KB |
Output is correct |
68 |
Correct |
473 ms |
97892 KB |
Output is correct |
69 |
Correct |
435 ms |
122596 KB |
Output is correct |
70 |
Correct |
885 ms |
138232 KB |
Output is correct |
71 |
Correct |
502 ms |
126200 KB |
Output is correct |
72 |
Correct |
572 ms |
118444 KB |
Output is correct |
73 |
Correct |
341 ms |
87328 KB |
Output is correct |
74 |
Correct |
341 ms |
96504 KB |
Output is correct |
75 |
Correct |
352 ms |
120988 KB |
Output is correct |
76 |
Correct |
669 ms |
127960 KB |
Output is correct |
77 |
Correct |
728 ms |
127968 KB |
Output is correct |
78 |
Correct |
170 ms |
79976 KB |
Output is correct |
79 |
Correct |
197 ms |
82660 KB |
Output is correct |
80 |
Correct |
202 ms |
82268 KB |
Output is correct |
81 |
Correct |
176 ms |
82016 KB |
Output is correct |
82 |
Correct |
212 ms |
81748 KB |
Output is correct |
83 |
Correct |
139 ms |
80740 KB |
Output is correct |
84 |
Correct |
204 ms |
82260 KB |
Output is correct |
85 |
Correct |
215 ms |
82016 KB |
Output is correct |
86 |
Correct |
193 ms |
81756 KB |
Output is correct |
87 |
Correct |
138 ms |
81768 KB |
Output is correct |
88 |
Correct |
147 ms |
82468 KB |
Output is correct |
89 |
Correct |
143 ms |
82372 KB |
Output is correct |
90 |
Correct |
146 ms |
81884 KB |
Output is correct |
91 |
Correct |
169 ms |
80944 KB |
Output is correct |