#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// Ofast, O0, O1, O2, O3, unroll-loops, fast-math, trapv
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define Mp make_pair
#define sep ' '
#define endl '\n'
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define kill(res) cout << res << '\n', exit(0);
#define set_dec(x) cout << fixed << setprecision(x);
#define fast_io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r", stdin) ; freopen("output.txt", "w", stdout);
#define lid (id<<1)
#define rid (lid|1)
#define mid ((l+r)>>1)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll N = 2e5 + 50;
const ll Mod = 1e9 + 7;
struct segment{
vector<int> idx[N], seg[N*4];
void build(int l = 0, int r = N, int id = 1){
if(l+1 == r){
seg[id] = idx[l];
sort(all(seg[id]));
seg[id].resize(unique(all(seg[id])) - seg[id].begin());
return;
}
build(l, mid, lid);
build(mid, r, rid);
seg[id].resize(seg[lid].size() + seg[rid].size());
merge(all(seg[lid]), all(seg[rid]), seg[id].begin());
}
int get(int ql, int qr, int dwn, int up, int l = 0, int r = N, int id = 1){
if(ql <= l && r <= qr){
int x1 = lower_bound(all(seg[id]), up) - seg[id].begin();
int x2 = lower_bound(all(seg[id]), dwn) - seg[id].begin();
return x2 - x1;
}
if(qr <= l || r <= ql) return 0;
return get(ql, qr, dwn, up, l, mid, lid) + get(ql, qr, dwn, up, mid, r, rid);
}
} pnt, vert, horiz, riv;
int R, C, sr, sc, M, x0 = N, y00 = N, x1, y11;
string s;
void add(int x, int y){
riv.idx[x].pb(y);
vert.idx[x-1].pb(y);
vert.idx[x].pb(y);
horiz.idx[x].pb(y-1);
horiz.idx[x].pb(y);
pnt.idx[x-1].pb(y-1);
pnt.idx[x-1].pb(y);
pnt.idx[x].pb(y-1);
pnt.idx[x].pb(y);
x0 = min(x0, x);
x1 = max(x1, x);
y00 = min(y00, y);
y11 = max(y11, y);
}
void init(int _R, int _C, int _sr, int _sc, int _M, char *S){
R = _R; C = _C; sr = _sr; sc = _sc; M = _M; s = S;
int x = sc, y = sr; add(x, y);
for(int i = 0; i < M; i++){
if(s[i] == 'N') y--;
else if(s[i] == 'S') y++;
else if(s[i] == 'E') x++;
else x--;
add(x, y);
}
pnt.build(); vert.build(); horiz.build(); riv.build();
}
int colour(int ar, int ac, int br, int bc){
ll m = vert.get(ac, bc, br + 1, ar) + horiz.get(ac, bc + 1, br, ar) + 2 * (br - ar + 1 + bc - ac + 1);
ll n = pnt.get(ac, bc, br, ar) + 2 * (br - ar + 1 + bc - ac + 1);
ll r = riv.get(ac, bc + 1, br + 1, ar);
ll x = (ac < x0 && x1 < bc && ar < y00 && y11 < br);
ll res = m - n + 1 - r + x;
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
94300 KB |
Output is correct |
2 |
Correct |
33 ms |
94800 KB |
Output is correct |
3 |
Correct |
32 ms |
94296 KB |
Output is correct |
4 |
Correct |
33 ms |
94556 KB |
Output is correct |
5 |
Correct |
35 ms |
94812 KB |
Output is correct |
6 |
Correct |
33 ms |
94808 KB |
Output is correct |
7 |
Correct |
30 ms |
94300 KB |
Output is correct |
8 |
Correct |
35 ms |
94300 KB |
Output is correct |
9 |
Correct |
31 ms |
94300 KB |
Output is correct |
10 |
Correct |
31 ms |
94300 KB |
Output is correct |
11 |
Correct |
34 ms |
94552 KB |
Output is correct |
12 |
Correct |
33 ms |
94812 KB |
Output is correct |
13 |
Correct |
34 ms |
94924 KB |
Output is correct |
14 |
Correct |
35 ms |
95232 KB |
Output is correct |
15 |
Correct |
35 ms |
94300 KB |
Output is correct |
16 |
Correct |
31 ms |
94300 KB |
Output is correct |
17 |
Correct |
34 ms |
94300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
94300 KB |
Output is correct |
2 |
Correct |
34 ms |
94300 KB |
Output is correct |
3 |
Correct |
542 ms |
141412 KB |
Output is correct |
4 |
Correct |
798 ms |
170348 KB |
Output is correct |
5 |
Correct |
735 ms |
167992 KB |
Output is correct |
6 |
Correct |
543 ms |
147508 KB |
Output is correct |
7 |
Correct |
651 ms |
146300 KB |
Output is correct |
8 |
Correct |
274 ms |
105392 KB |
Output is correct |
9 |
Correct |
815 ms |
170340 KB |
Output is correct |
10 |
Correct |
804 ms |
167660 KB |
Output is correct |
11 |
Correct |
580 ms |
147296 KB |
Output is correct |
12 |
Correct |
293 ms |
165572 KB |
Output is correct |
13 |
Correct |
374 ms |
170196 KB |
Output is correct |
14 |
Correct |
381 ms |
167592 KB |
Output is correct |
15 |
Correct |
337 ms |
147344 KB |
Output is correct |
16 |
Correct |
537 ms |
149448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
94300 KB |
Output is correct |
2 |
Correct |
159 ms |
167248 KB |
Output is correct |
3 |
Correct |
67 ms |
142408 KB |
Output is correct |
4 |
Correct |
104 ms |
152764 KB |
Output is correct |
5 |
Correct |
77 ms |
137500 KB |
Output is correct |
6 |
Correct |
64 ms |
110800 KB |
Output is correct |
7 |
Correct |
74 ms |
118708 KB |
Output is correct |
8 |
Correct |
109 ms |
146768 KB |
Output is correct |
9 |
Correct |
106 ms |
141140 KB |
Output is correct |
10 |
Correct |
52 ms |
107264 KB |
Output is correct |
11 |
Correct |
97 ms |
126404 KB |
Output is correct |
12 |
Correct |
151 ms |
167252 KB |
Output is correct |
13 |
Correct |
68 ms |
142368 KB |
Output is correct |
14 |
Correct |
110 ms |
152628 KB |
Output is correct |
15 |
Correct |
79 ms |
137620 KB |
Output is correct |
16 |
Correct |
62 ms |
109516 KB |
Output is correct |
17 |
Correct |
72 ms |
118488 KB |
Output is correct |
18 |
Correct |
77 ms |
144212 KB |
Output is correct |
19 |
Correct |
109 ms |
155440 KB |
Output is correct |
20 |
Correct |
108 ms |
155216 KB |
Output is correct |
21 |
Correct |
112 ms |
146772 KB |
Output is correct |
22 |
Correct |
104 ms |
141132 KB |
Output is correct |
23 |
Correct |
51 ms |
107092 KB |
Output is correct |
24 |
Correct |
82 ms |
126404 KB |
Output is correct |
25 |
Correct |
153 ms |
167508 KB |
Output is correct |
26 |
Correct |
68 ms |
142496 KB |
Output is correct |
27 |
Correct |
108 ms |
152784 KB |
Output is correct |
28 |
Correct |
78 ms |
137660 KB |
Output is correct |
29 |
Correct |
72 ms |
109396 KB |
Output is correct |
30 |
Correct |
74 ms |
118552 KB |
Output is correct |
31 |
Correct |
76 ms |
144360 KB |
Output is correct |
32 |
Correct |
107 ms |
155256 KB |
Output is correct |
33 |
Correct |
106 ms |
155200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
94300 KB |
Output is correct |
2 |
Correct |
33 ms |
94800 KB |
Output is correct |
3 |
Correct |
32 ms |
94296 KB |
Output is correct |
4 |
Correct |
33 ms |
94556 KB |
Output is correct |
5 |
Correct |
35 ms |
94812 KB |
Output is correct |
6 |
Correct |
33 ms |
94808 KB |
Output is correct |
7 |
Correct |
30 ms |
94300 KB |
Output is correct |
8 |
Correct |
35 ms |
94300 KB |
Output is correct |
9 |
Correct |
31 ms |
94300 KB |
Output is correct |
10 |
Correct |
31 ms |
94300 KB |
Output is correct |
11 |
Correct |
34 ms |
94552 KB |
Output is correct |
12 |
Correct |
33 ms |
94812 KB |
Output is correct |
13 |
Correct |
34 ms |
94924 KB |
Output is correct |
14 |
Correct |
35 ms |
95232 KB |
Output is correct |
15 |
Correct |
35 ms |
94300 KB |
Output is correct |
16 |
Correct |
31 ms |
94300 KB |
Output is correct |
17 |
Correct |
34 ms |
94300 KB |
Output is correct |
18 |
Correct |
577 ms |
127028 KB |
Output is correct |
19 |
Correct |
223 ms |
99156 KB |
Output is correct |
20 |
Correct |
162 ms |
98036 KB |
Output is correct |
21 |
Correct |
177 ms |
98044 KB |
Output is correct |
22 |
Correct |
191 ms |
98504 KB |
Output is correct |
23 |
Correct |
230 ms |
98992 KB |
Output is correct |
24 |
Correct |
190 ms |
98340 KB |
Output is correct |
25 |
Correct |
202 ms |
98384 KB |
Output is correct |
26 |
Correct |
195 ms |
98568 KB |
Output is correct |
27 |
Correct |
322 ms |
123472 KB |
Output is correct |
28 |
Correct |
281 ms |
114752 KB |
Output is correct |
29 |
Correct |
342 ms |
122256 KB |
Output is correct |
30 |
Correct |
520 ms |
147812 KB |
Output is correct |
31 |
Correct |
34 ms |
94296 KB |
Output is correct |
32 |
Correct |
572 ms |
123648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
94300 KB |
Output is correct |
2 |
Correct |
33 ms |
94800 KB |
Output is correct |
3 |
Correct |
32 ms |
94296 KB |
Output is correct |
4 |
Correct |
33 ms |
94556 KB |
Output is correct |
5 |
Correct |
35 ms |
94812 KB |
Output is correct |
6 |
Correct |
33 ms |
94808 KB |
Output is correct |
7 |
Correct |
30 ms |
94300 KB |
Output is correct |
8 |
Correct |
35 ms |
94300 KB |
Output is correct |
9 |
Correct |
31 ms |
94300 KB |
Output is correct |
10 |
Correct |
31 ms |
94300 KB |
Output is correct |
11 |
Correct |
34 ms |
94552 KB |
Output is correct |
12 |
Correct |
33 ms |
94812 KB |
Output is correct |
13 |
Correct |
34 ms |
94924 KB |
Output is correct |
14 |
Correct |
35 ms |
95232 KB |
Output is correct |
15 |
Correct |
35 ms |
94300 KB |
Output is correct |
16 |
Correct |
31 ms |
94300 KB |
Output is correct |
17 |
Correct |
34 ms |
94300 KB |
Output is correct |
18 |
Correct |
577 ms |
127028 KB |
Output is correct |
19 |
Correct |
223 ms |
99156 KB |
Output is correct |
20 |
Correct |
162 ms |
98036 KB |
Output is correct |
21 |
Correct |
177 ms |
98044 KB |
Output is correct |
22 |
Correct |
191 ms |
98504 KB |
Output is correct |
23 |
Correct |
230 ms |
98992 KB |
Output is correct |
24 |
Correct |
190 ms |
98340 KB |
Output is correct |
25 |
Correct |
202 ms |
98384 KB |
Output is correct |
26 |
Correct |
195 ms |
98568 KB |
Output is correct |
27 |
Correct |
322 ms |
123472 KB |
Output is correct |
28 |
Correct |
281 ms |
114752 KB |
Output is correct |
29 |
Correct |
342 ms |
122256 KB |
Output is correct |
30 |
Correct |
520 ms |
147812 KB |
Output is correct |
31 |
Correct |
34 ms |
94296 KB |
Output is correct |
32 |
Correct |
572 ms |
123648 KB |
Output is correct |
33 |
Correct |
159 ms |
167248 KB |
Output is correct |
34 |
Correct |
67 ms |
142408 KB |
Output is correct |
35 |
Correct |
104 ms |
152764 KB |
Output is correct |
36 |
Correct |
77 ms |
137500 KB |
Output is correct |
37 |
Correct |
64 ms |
110800 KB |
Output is correct |
38 |
Correct |
74 ms |
118708 KB |
Output is correct |
39 |
Correct |
109 ms |
146768 KB |
Output is correct |
40 |
Correct |
106 ms |
141140 KB |
Output is correct |
41 |
Correct |
52 ms |
107264 KB |
Output is correct |
42 |
Correct |
97 ms |
126404 KB |
Output is correct |
43 |
Correct |
151 ms |
167252 KB |
Output is correct |
44 |
Correct |
68 ms |
142368 KB |
Output is correct |
45 |
Correct |
110 ms |
152628 KB |
Output is correct |
46 |
Correct |
79 ms |
137620 KB |
Output is correct |
47 |
Correct |
62 ms |
109516 KB |
Output is correct |
48 |
Correct |
72 ms |
118488 KB |
Output is correct |
49 |
Correct |
77 ms |
144212 KB |
Output is correct |
50 |
Correct |
109 ms |
155440 KB |
Output is correct |
51 |
Correct |
108 ms |
155216 KB |
Output is correct |
52 |
Correct |
112 ms |
146772 KB |
Output is correct |
53 |
Correct |
104 ms |
141132 KB |
Output is correct |
54 |
Correct |
51 ms |
107092 KB |
Output is correct |
55 |
Correct |
82 ms |
126404 KB |
Output is correct |
56 |
Correct |
153 ms |
167508 KB |
Output is correct |
57 |
Correct |
68 ms |
142496 KB |
Output is correct |
58 |
Correct |
108 ms |
152784 KB |
Output is correct |
59 |
Correct |
78 ms |
137660 KB |
Output is correct |
60 |
Correct |
72 ms |
109396 KB |
Output is correct |
61 |
Correct |
74 ms |
118552 KB |
Output is correct |
62 |
Correct |
76 ms |
144360 KB |
Output is correct |
63 |
Correct |
107 ms |
155256 KB |
Output is correct |
64 |
Correct |
106 ms |
155200 KB |
Output is correct |
65 |
Correct |
542 ms |
141412 KB |
Output is correct |
66 |
Correct |
798 ms |
170348 KB |
Output is correct |
67 |
Correct |
735 ms |
167992 KB |
Output is correct |
68 |
Correct |
543 ms |
147508 KB |
Output is correct |
69 |
Correct |
651 ms |
146300 KB |
Output is correct |
70 |
Correct |
274 ms |
105392 KB |
Output is correct |
71 |
Correct |
815 ms |
170340 KB |
Output is correct |
72 |
Correct |
804 ms |
167660 KB |
Output is correct |
73 |
Correct |
580 ms |
147296 KB |
Output is correct |
74 |
Correct |
293 ms |
165572 KB |
Output is correct |
75 |
Correct |
374 ms |
170196 KB |
Output is correct |
76 |
Correct |
381 ms |
167592 KB |
Output is correct |
77 |
Correct |
337 ms |
147344 KB |
Output is correct |
78 |
Correct |
537 ms |
149448 KB |
Output is correct |
79 |
Correct |
1058 ms |
150352 KB |
Output is correct |
80 |
Correct |
1119 ms |
144708 KB |
Output is correct |
81 |
Correct |
430 ms |
110528 KB |
Output is correct |
82 |
Correct |
577 ms |
129924 KB |
Output is correct |
83 |
Correct |
629 ms |
170836 KB |
Output is correct |
84 |
Correct |
335 ms |
146028 KB |
Output is correct |
85 |
Correct |
436 ms |
156608 KB |
Output is correct |
86 |
Correct |
369 ms |
140928 KB |
Output is correct |
87 |
Correct |
324 ms |
112956 KB |
Output is correct |
88 |
Correct |
299 ms |
121836 KB |
Output is correct |
89 |
Correct |
305 ms |
148304 KB |
Output is correct |
90 |
Correct |
464 ms |
158860 KB |
Output is correct |
91 |
Correct |
480 ms |
158748 KB |
Output is correct |