#include <bits/stdc++.h>
#include "rainbow.h"
using namespace std;
typedef pair <int, int> pii;
struct pst{
struct node{
int l, r, v;
node() : l(0), r(0), v(0) {}
};
node T[15151515];
int R[202020], r, t, c;
void init(int w) { c = w; }
void insert(int p, int s, int e, int i, int v)
{
T[p].v += v;
if(s == e) return;
else if(i <= (s + e >> 1)){
T[++t] = T[T[p].l]; T[p].l = t;
insert(T[p].l, s, s + e >> 1, i, v);
}
else{
T[++t] = T[T[p].r]; T[p].r = t;
insert(T[p].r, (s + e >> 1) + 1, e, i, v);
}
}
void insert(int p, int v)
{
T[++t] = T[r]; r = t;
insert(r, 1, c, p, v);
}
void root(int p) { R[p] = r; }
int query(int p, int s, int e, int l, int r)
{
if(!p || r < s || e < l) return 0;
else if(l <= s && e <= r){
return T[p].v;
}
else return query(T[p].l, s, s + e >> 1, l, r)
+ query(T[p].r, (s + e >> 1) + 1, e, l, r);
}
int query(int sr, int sc, int er, int ec)
{
return query(R[er], 1, c, sc, ec)
- query(R[sr - 1], 1, c, sc, ec);
}
};
pst T;
vector <int> R1[202020], R2[202020];
vector <int> C1[202020], C2[202020];
vector <pii> V, E1, E2, F;
int lx, ly, rx, ry;
void push(int x, int y)
{
V.emplace_back(x, y);
E1.emplace_back(x, y);
E1.emplace_back(x + 1, y);
E2.emplace_back(x, y);
E2.emplace_back(x, y + 1);
F.emplace_back(x, y);
F.emplace_back(x, y + 1);
F.emplace_back(x + 1, y);
F.emplace_back(x + 1, y + 1);
}
void compress(vector <pii> &V)
{
sort(V.begin(), V.end());
V.erase(unique(V.begin(), V.end()), V.end());
}
void init(int r, int c, int x, int y, int m, char *S)
{
int i, v, e1, e2, f;
T.init(c + 1);
push(x, y);
lx = rx = x; ly = ry = y;
for(i=0; i<m; i++){
if(S[i] == 'N') x --;
else if(S[i] == 'S') x ++;
else if(S[i] == 'W') y --;
else y ++;
push(x, y);
lx = min(lx, x); rx = max(rx, x);
ly = min(ly, y); ry = max(ry, y);
}
compress(V);
compress(E1);
compress(E2);
compress(F);
v = e1 = e2 = f = 0;
for(i=1; i<=r+1; i++){
for(; v<V.size() && V[v].first == i; v++){
T.insert(V[v].second, -1);
}
for(; e1<E1.size() && E1[e1].first == i; e1++){
T.insert(E1[e1].second, 1);
R1[i].push_back(E1[e1].second);
}
for(; e2<E2.size() && E2[e2].first == i; e2++){
T.insert(E2[e2].second, 1);
C1[E2[e2].second].push_back(i);
}
for(; f<F.size() && F[f].first == i; f++){
T.insert(F[f].second, -1);
R2[i].push_back(F[f].second);
C2[F[f].second].push_back(i);
}
T.root(i);
}
}
int colour(int sr, int sc, int er, int ec)
{
int ret = 1 + T.query(sr, sc, er, ec);
ret -= lower_bound(R1[sr].begin(), R1[sr].end(), ec + 1)
- lower_bound(R1[sr].begin(), R1[sr].end(), sc);
ret -= lower_bound(C1[sc].begin(), C1[sc].end(), er + 1)
- lower_bound(C1[sc].begin(), C1[sc].end(), sr);
ret += lower_bound(R2[sr].begin(), R2[sr].end(), ec + 1)
- lower_bound(R2[sr].begin(), R2[sr].end(), sc + 1);
ret += lower_bound(C2[sc].begin(), C2[sc].end(), er + 1)
- lower_bound(C2[sc].begin(), C2[sc].end(), sr);
ret += (sr < lx && rx < er && sc < ly && ry < ec);
return ret;
}
Compilation message
rainbow.cpp: In member function 'void pst::insert(int, int, int, int, int)':
rainbow.cpp:25:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
else if(i <= (s + e >> 1)){
~~^~~
rainbow.cpp:27:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
insert(T[p].l, s, s + e >> 1, i, v);
~~^~~
rainbow.cpp:31:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
insert(T[p].r, (s + e >> 1) + 1, e, i, v);
~~^~~
rainbow.cpp: In member function 'int pst::query(int, int, int, int, int)':
rainbow.cpp:49:34: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
else return query(T[p].l, s, s + e >> 1, l, r)
~~^~~
rainbow.cpp:50:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
+ query(T[p].r, (s + e >> 1) + 1, e, l, r);
~~^~~
rainbow.cpp: In function 'void init(int, int, int, int, int, char*)':
rainbow.cpp:118:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(; v<V.size() && V[v].first == i; v++){
~^~~~~~~~~
rainbow.cpp:122:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(; e1<E1.size() && E1[e1].first == i; e1++){
~~^~~~~~~~~~
rainbow.cpp:127:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(; e2<E2.size() && E2[e2].first == i; e2++){
~~^~~~~~~~~~
rainbow.cpp:132:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(; f<F.size() && F[f].first == i; f++){
~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
149 ms |
197244 KB |
Output is correct |
2 |
Correct |
153 ms |
197368 KB |
Output is correct |
3 |
Correct |
149 ms |
197216 KB |
Output is correct |
4 |
Correct |
150 ms |
197268 KB |
Output is correct |
5 |
Correct |
152 ms |
197752 KB |
Output is correct |
6 |
Correct |
150 ms |
197188 KB |
Output is correct |
7 |
Correct |
149 ms |
197248 KB |
Output is correct |
8 |
Correct |
148 ms |
197268 KB |
Output is correct |
9 |
Correct |
150 ms |
197240 KB |
Output is correct |
10 |
Correct |
147 ms |
197240 KB |
Output is correct |
11 |
Correct |
149 ms |
197368 KB |
Output is correct |
12 |
Correct |
150 ms |
197368 KB |
Output is correct |
13 |
Correct |
152 ms |
197496 KB |
Output is correct |
14 |
Correct |
153 ms |
197708 KB |
Output is correct |
15 |
Correct |
149 ms |
197240 KB |
Output is correct |
16 |
Correct |
157 ms |
197240 KB |
Output is correct |
17 |
Correct |
150 ms |
197240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
157 ms |
197240 KB |
Output is correct |
2 |
Correct |
150 ms |
197240 KB |
Output is correct |
3 |
Correct |
425 ms |
207140 KB |
Output is correct |
4 |
Correct |
569 ms |
213284 KB |
Output is correct |
5 |
Correct |
569 ms |
212596 KB |
Output is correct |
6 |
Correct |
492 ms |
209680 KB |
Output is correct |
7 |
Correct |
530 ms |
209800 KB |
Output is correct |
8 |
Correct |
268 ms |
205892 KB |
Output is correct |
9 |
Correct |
557 ms |
213312 KB |
Output is correct |
10 |
Correct |
552 ms |
212548 KB |
Output is correct |
11 |
Correct |
552 ms |
209852 KB |
Output is correct |
12 |
Correct |
393 ms |
212272 KB |
Output is correct |
13 |
Correct |
394 ms |
213208 KB |
Output is correct |
14 |
Correct |
399 ms |
212704 KB |
Output is correct |
15 |
Correct |
374 ms |
209860 KB |
Output is correct |
16 |
Correct |
458 ms |
208832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
149 ms |
197240 KB |
Output is correct |
2 |
Correct |
330 ms |
213448 KB |
Output is correct |
3 |
Correct |
254 ms |
213316 KB |
Output is correct |
4 |
Correct |
270 ms |
211524 KB |
Output is correct |
5 |
Correct |
245 ms |
210248 KB |
Output is correct |
6 |
Correct |
238 ms |
205892 KB |
Output is correct |
7 |
Correct |
267 ms |
206660 KB |
Output is correct |
8 |
Correct |
307 ms |
209092 KB |
Output is correct |
9 |
Correct |
300 ms |
208292 KB |
Output is correct |
10 |
Correct |
212 ms |
201812 KB |
Output is correct |
11 |
Correct |
257 ms |
207556 KB |
Output is correct |
12 |
Correct |
337 ms |
213444 KB |
Output is correct |
13 |
Correct |
246 ms |
213188 KB |
Output is correct |
14 |
Correct |
266 ms |
211400 KB |
Output is correct |
15 |
Correct |
244 ms |
210244 KB |
Output is correct |
16 |
Correct |
235 ms |
206020 KB |
Output is correct |
17 |
Correct |
247 ms |
206660 KB |
Output is correct |
18 |
Correct |
305 ms |
208920 KB |
Output is correct |
19 |
Correct |
291 ms |
213520 KB |
Output is correct |
20 |
Correct |
306 ms |
213384 KB |
Output is correct |
21 |
Correct |
324 ms |
209012 KB |
Output is correct |
22 |
Correct |
299 ms |
208324 KB |
Output is correct |
23 |
Correct |
208 ms |
201916 KB |
Output is correct |
24 |
Correct |
267 ms |
207300 KB |
Output is correct |
25 |
Correct |
340 ms |
213572 KB |
Output is correct |
26 |
Correct |
261 ms |
213072 KB |
Output is correct |
27 |
Correct |
283 ms |
211396 KB |
Output is correct |
28 |
Correct |
268 ms |
210224 KB |
Output is correct |
29 |
Correct |
246 ms |
205864 KB |
Output is correct |
30 |
Correct |
260 ms |
206660 KB |
Output is correct |
31 |
Correct |
302 ms |
208836 KB |
Output is correct |
32 |
Correct |
283 ms |
213444 KB |
Output is correct |
33 |
Correct |
292 ms |
213460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
149 ms |
197244 KB |
Output is correct |
2 |
Correct |
153 ms |
197368 KB |
Output is correct |
3 |
Correct |
149 ms |
197216 KB |
Output is correct |
4 |
Correct |
150 ms |
197268 KB |
Output is correct |
5 |
Correct |
152 ms |
197752 KB |
Output is correct |
6 |
Correct |
150 ms |
197188 KB |
Output is correct |
7 |
Correct |
149 ms |
197248 KB |
Output is correct |
8 |
Correct |
148 ms |
197268 KB |
Output is correct |
9 |
Correct |
150 ms |
197240 KB |
Output is correct |
10 |
Correct |
147 ms |
197240 KB |
Output is correct |
11 |
Correct |
149 ms |
197368 KB |
Output is correct |
12 |
Correct |
150 ms |
197368 KB |
Output is correct |
13 |
Correct |
152 ms |
197496 KB |
Output is correct |
14 |
Correct |
153 ms |
197708 KB |
Output is correct |
15 |
Correct |
149 ms |
197240 KB |
Output is correct |
16 |
Correct |
157 ms |
197240 KB |
Output is correct |
17 |
Correct |
150 ms |
197240 KB |
Output is correct |
18 |
Correct |
458 ms |
206844 KB |
Output is correct |
19 |
Correct |
260 ms |
198364 KB |
Output is correct |
20 |
Correct |
228 ms |
197884 KB |
Output is correct |
21 |
Correct |
234 ms |
198008 KB |
Output is correct |
22 |
Correct |
241 ms |
198232 KB |
Output is correct |
23 |
Correct |
249 ms |
198404 KB |
Output is correct |
24 |
Correct |
243 ms |
198264 KB |
Output is correct |
25 |
Correct |
242 ms |
198264 KB |
Output is correct |
26 |
Correct |
248 ms |
198392 KB |
Output is correct |
27 |
Correct |
341 ms |
206688 KB |
Output is correct |
28 |
Correct |
390 ms |
206004 KB |
Output is correct |
29 |
Correct |
331 ms |
206656 KB |
Output is correct |
30 |
Correct |
436 ms |
208780 KB |
Output is correct |
31 |
Correct |
153 ms |
197240 KB |
Output is correct |
32 |
Correct |
430 ms |
206792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
149 ms |
197244 KB |
Output is correct |
2 |
Correct |
153 ms |
197368 KB |
Output is correct |
3 |
Correct |
149 ms |
197216 KB |
Output is correct |
4 |
Correct |
150 ms |
197268 KB |
Output is correct |
5 |
Correct |
152 ms |
197752 KB |
Output is correct |
6 |
Correct |
150 ms |
197188 KB |
Output is correct |
7 |
Correct |
149 ms |
197248 KB |
Output is correct |
8 |
Correct |
148 ms |
197268 KB |
Output is correct |
9 |
Correct |
150 ms |
197240 KB |
Output is correct |
10 |
Correct |
147 ms |
197240 KB |
Output is correct |
11 |
Correct |
149 ms |
197368 KB |
Output is correct |
12 |
Correct |
150 ms |
197368 KB |
Output is correct |
13 |
Correct |
152 ms |
197496 KB |
Output is correct |
14 |
Correct |
153 ms |
197708 KB |
Output is correct |
15 |
Correct |
149 ms |
197240 KB |
Output is correct |
16 |
Correct |
157 ms |
197240 KB |
Output is correct |
17 |
Correct |
150 ms |
197240 KB |
Output is correct |
18 |
Correct |
458 ms |
206844 KB |
Output is correct |
19 |
Correct |
260 ms |
198364 KB |
Output is correct |
20 |
Correct |
228 ms |
197884 KB |
Output is correct |
21 |
Correct |
234 ms |
198008 KB |
Output is correct |
22 |
Correct |
241 ms |
198232 KB |
Output is correct |
23 |
Correct |
249 ms |
198404 KB |
Output is correct |
24 |
Correct |
243 ms |
198264 KB |
Output is correct |
25 |
Correct |
242 ms |
198264 KB |
Output is correct |
26 |
Correct |
248 ms |
198392 KB |
Output is correct |
27 |
Correct |
341 ms |
206688 KB |
Output is correct |
28 |
Correct |
390 ms |
206004 KB |
Output is correct |
29 |
Correct |
331 ms |
206656 KB |
Output is correct |
30 |
Correct |
436 ms |
208780 KB |
Output is correct |
31 |
Correct |
153 ms |
197240 KB |
Output is correct |
32 |
Correct |
430 ms |
206792 KB |
Output is correct |
33 |
Correct |
330 ms |
213448 KB |
Output is correct |
34 |
Correct |
254 ms |
213316 KB |
Output is correct |
35 |
Correct |
270 ms |
211524 KB |
Output is correct |
36 |
Correct |
245 ms |
210248 KB |
Output is correct |
37 |
Correct |
238 ms |
205892 KB |
Output is correct |
38 |
Correct |
267 ms |
206660 KB |
Output is correct |
39 |
Correct |
307 ms |
209092 KB |
Output is correct |
40 |
Correct |
300 ms |
208292 KB |
Output is correct |
41 |
Correct |
212 ms |
201812 KB |
Output is correct |
42 |
Correct |
257 ms |
207556 KB |
Output is correct |
43 |
Correct |
337 ms |
213444 KB |
Output is correct |
44 |
Correct |
246 ms |
213188 KB |
Output is correct |
45 |
Correct |
266 ms |
211400 KB |
Output is correct |
46 |
Correct |
244 ms |
210244 KB |
Output is correct |
47 |
Correct |
235 ms |
206020 KB |
Output is correct |
48 |
Correct |
247 ms |
206660 KB |
Output is correct |
49 |
Correct |
305 ms |
208920 KB |
Output is correct |
50 |
Correct |
291 ms |
213520 KB |
Output is correct |
51 |
Correct |
306 ms |
213384 KB |
Output is correct |
52 |
Correct |
324 ms |
209012 KB |
Output is correct |
53 |
Correct |
299 ms |
208324 KB |
Output is correct |
54 |
Correct |
208 ms |
201916 KB |
Output is correct |
55 |
Correct |
267 ms |
207300 KB |
Output is correct |
56 |
Correct |
340 ms |
213572 KB |
Output is correct |
57 |
Correct |
261 ms |
213072 KB |
Output is correct |
58 |
Correct |
283 ms |
211396 KB |
Output is correct |
59 |
Correct |
268 ms |
210224 KB |
Output is correct |
60 |
Correct |
246 ms |
205864 KB |
Output is correct |
61 |
Correct |
260 ms |
206660 KB |
Output is correct |
62 |
Correct |
302 ms |
208836 KB |
Output is correct |
63 |
Correct |
283 ms |
213444 KB |
Output is correct |
64 |
Correct |
292 ms |
213460 KB |
Output is correct |
65 |
Correct |
644 ms |
209728 KB |
Output is correct |
66 |
Correct |
624 ms |
209028 KB |
Output is correct |
67 |
Correct |
310 ms |
202608 KB |
Output is correct |
68 |
Correct |
382 ms |
208136 KB |
Output is correct |
69 |
Correct |
479 ms |
214212 KB |
Output is correct |
70 |
Correct |
365 ms |
213900 KB |
Output is correct |
71 |
Correct |
404 ms |
212292 KB |
Output is correct |
72 |
Correct |
372 ms |
211084 KB |
Output is correct |
73 |
Correct |
326 ms |
206616 KB |
Output is correct |
74 |
Correct |
355 ms |
207300 KB |
Output is correct |
75 |
Correct |
382 ms |
209456 KB |
Output is correct |
76 |
Correct |
424 ms |
214140 KB |
Output is correct |
77 |
Correct |
409 ms |
214184 KB |
Output is correct |
78 |
Correct |
425 ms |
207140 KB |
Output is correct |
79 |
Correct |
569 ms |
213284 KB |
Output is correct |
80 |
Correct |
569 ms |
212596 KB |
Output is correct |
81 |
Correct |
492 ms |
209680 KB |
Output is correct |
82 |
Correct |
530 ms |
209800 KB |
Output is correct |
83 |
Correct |
268 ms |
205892 KB |
Output is correct |
84 |
Correct |
557 ms |
213312 KB |
Output is correct |
85 |
Correct |
552 ms |
212548 KB |
Output is correct |
86 |
Correct |
552 ms |
209852 KB |
Output is correct |
87 |
Correct |
393 ms |
212272 KB |
Output is correct |
88 |
Correct |
394 ms |
213208 KB |
Output is correct |
89 |
Correct |
399 ms |
212704 KB |
Output is correct |
90 |
Correct |
374 ms |
209860 KB |
Output is correct |
91 |
Correct |
458 ms |
208832 KB |
Output is correct |