#include "rainbow.h"
#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007
#define dancila 3.14159265359
#define eps 1e-9
using namespace std;
const int maxsz = 2e7;
int cnt = 1, segtree[maxsz], left_c[maxsz], right_c[maxsz];
struct aint
{
set<int> data[200002];
int roots[200002];
void add(int x, int y)
{
data[x].insert(y);
}
void build()
{
for(int i = 1; i <= 200000; ++i)
{
roots[i+1] = roots[i];
for(set<int> ::iterator it = data[i].begin(); it != data[i].end(); ++it)
update(*it, roots[i+1]);
}
}
void update(int pos, int &node, int l = 1, int r = 200000)
{
segtree[cnt] = segtree[node] + 1;
left_c[cnt] = left_c[node];
right_c[cnt] = right_c[node];
node = cnt++;
if (l == r)
return;
int mid = (l + r) / 2;
if (pos > mid)
update(pos, right_c[node], mid + 1, r);
else
update(pos, left_c[node], l, mid);
}
int query(int l1, int r1, int l2, int r2)
{
if (l2 > r2)
return 0;
return query2(l2, r2, roots[r1 + 1], 1, 200000) - query2(l2, r2, roots[l1], 1, 200000);
}
int query2(int a, int b, int node, int l, int r)
{
if (a > r || b < l)
return 0;
if (a <= l && b >= r)
return segtree[node];
int mid = (l + r) / 2;
return query2(a, b, left_c[node], l, mid) + query2(a, b, right_c[node], mid + 1, r);
}
} nod, muchiiH, muchiiV, rau;
int mxL, mnL = (1<<20), mxC, mnC = (1<<20);
void add_river(int L, int C)
{
mxL = max(mxL, L);
mxC = max(mxC, C);
mnL = min(mnL, L);
mnC = min(mnC, C);
nod.add(L, C);
nod.add(L + 1, C);
nod.add(L, C + 1);
nod.add(L + 1, C + 1);
muchiiH.add(L, C);
muchiiH.add(L + 1, C);
muchiiV.add(L, C);
muchiiV.add(L, C + 1);
rau.add(L, C);
}
void init(int R, int C, int sr, int sc, int M, char *S)
{
add_river(sr, sc);
for(int i = 0; i < M; ++i)
{
sr += (S[i] == 'S');
sr -= (S[i] == 'N');
sc += (S[i] == 'E');
sc -= (S[i] == 'W');
add_river(sr, sc);
}
nod.build();
muchiiH.build();
muchiiV.build();
rau.build();
}
int colour(int ar, int ac, int br, int bc)
{
int E = muchiiH.query(ar + 1, br, ac, bc) + muchiiV.query(ar, br, ac + 1, bc);
int V = nod.query(ar + 1, br, ac + 1, bc);
int R = rau.query(ar, br, ac, bc);
int C;
if(ar >= mnL || br <= mxL || ac >= mnC || bc <= mxC)
C = 1;
else
C = 2;
return E - V + C - R;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
41336 KB |
Output is correct |
2 |
Correct |
51 ms |
42360 KB |
Output is correct |
3 |
Correct |
47 ms |
41336 KB |
Output is correct |
4 |
Correct |
47 ms |
41464 KB |
Output is correct |
5 |
Correct |
50 ms |
42620 KB |
Output is correct |
6 |
Correct |
45 ms |
41052 KB |
Output is correct |
7 |
Correct |
44 ms |
41080 KB |
Output is correct |
8 |
Correct |
44 ms |
41080 KB |
Output is correct |
9 |
Correct |
44 ms |
41080 KB |
Output is correct |
10 |
Correct |
45 ms |
41080 KB |
Output is correct |
11 |
Correct |
50 ms |
41592 KB |
Output is correct |
12 |
Correct |
48 ms |
42104 KB |
Output is correct |
13 |
Correct |
50 ms |
43128 KB |
Output is correct |
14 |
Correct |
52 ms |
43640 KB |
Output is correct |
15 |
Correct |
46 ms |
41052 KB |
Output is correct |
16 |
Correct |
44 ms |
41080 KB |
Output is correct |
17 |
Correct |
43 ms |
41080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
41080 KB |
Output is correct |
2 |
Correct |
43 ms |
41080 KB |
Output is correct |
3 |
Correct |
755 ms |
140124 KB |
Output is correct |
4 |
Correct |
1018 ms |
204716 KB |
Output is correct |
5 |
Correct |
1045 ms |
203396 KB |
Output is correct |
6 |
Correct |
864 ms |
166904 KB |
Output is correct |
7 |
Correct |
991 ms |
164792 KB |
Output is correct |
8 |
Correct |
371 ms |
44844 KB |
Output is correct |
9 |
Correct |
1022 ms |
204540 KB |
Output is correct |
10 |
Correct |
1048 ms |
201904 KB |
Output is correct |
11 |
Correct |
894 ms |
163904 KB |
Output is correct |
12 |
Correct |
570 ms |
190452 KB |
Output is correct |
13 |
Correct |
559 ms |
201848 KB |
Output is correct |
14 |
Correct |
611 ms |
200436 KB |
Output is correct |
15 |
Correct |
526 ms |
164148 KB |
Output is correct |
16 |
Correct |
835 ms |
154960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
41052 KB |
Output is correct |
2 |
Correct |
534 ms |
201080 KB |
Output is correct |
3 |
Correct |
275 ms |
198648 KB |
Output is correct |
4 |
Correct |
304 ms |
201080 KB |
Output is correct |
5 |
Correct |
279 ms |
159952 KB |
Output is correct |
6 |
Correct |
138 ms |
71148 KB |
Output is correct |
7 |
Correct |
243 ms |
100856 KB |
Output is correct |
8 |
Correct |
417 ms |
183928 KB |
Output is correct |
9 |
Correct |
399 ms |
167772 KB |
Output is correct |
10 |
Correct |
154 ms |
72824 KB |
Output is correct |
11 |
Correct |
280 ms |
119800 KB |
Output is correct |
12 |
Correct |
533 ms |
201024 KB |
Output is correct |
13 |
Correct |
296 ms |
198636 KB |
Output is correct |
14 |
Correct |
309 ms |
201104 KB |
Output is correct |
15 |
Correct |
282 ms |
159992 KB |
Output is correct |
16 |
Correct |
152 ms |
65272 KB |
Output is correct |
17 |
Correct |
221 ms |
100940 KB |
Output is correct |
18 |
Correct |
411 ms |
201340 KB |
Output is correct |
19 |
Correct |
385 ms |
202332 KB |
Output is correct |
20 |
Correct |
387 ms |
202104 KB |
Output is correct |
21 |
Correct |
415 ms |
183960 KB |
Output is correct |
22 |
Correct |
398 ms |
167928 KB |
Output is correct |
23 |
Correct |
153 ms |
72700 KB |
Output is correct |
24 |
Correct |
280 ms |
119544 KB |
Output is correct |
25 |
Correct |
535 ms |
201208 KB |
Output is correct |
26 |
Correct |
272 ms |
198648 KB |
Output is correct |
27 |
Correct |
303 ms |
201080 KB |
Output is correct |
28 |
Correct |
280 ms |
159852 KB |
Output is correct |
29 |
Correct |
130 ms |
65116 KB |
Output is correct |
30 |
Correct |
221 ms |
100876 KB |
Output is correct |
31 |
Correct |
411 ms |
201208 KB |
Output is correct |
32 |
Correct |
389 ms |
202104 KB |
Output is correct |
33 |
Correct |
391 ms |
202232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
41336 KB |
Output is correct |
2 |
Correct |
51 ms |
42360 KB |
Output is correct |
3 |
Correct |
47 ms |
41336 KB |
Output is correct |
4 |
Correct |
47 ms |
41464 KB |
Output is correct |
5 |
Correct |
50 ms |
42620 KB |
Output is correct |
6 |
Correct |
45 ms |
41052 KB |
Output is correct |
7 |
Correct |
44 ms |
41080 KB |
Output is correct |
8 |
Correct |
44 ms |
41080 KB |
Output is correct |
9 |
Correct |
44 ms |
41080 KB |
Output is correct |
10 |
Correct |
45 ms |
41080 KB |
Output is correct |
11 |
Correct |
50 ms |
41592 KB |
Output is correct |
12 |
Correct |
48 ms |
42104 KB |
Output is correct |
13 |
Correct |
50 ms |
43128 KB |
Output is correct |
14 |
Correct |
52 ms |
43640 KB |
Output is correct |
15 |
Correct |
46 ms |
41052 KB |
Output is correct |
16 |
Correct |
44 ms |
41080 KB |
Output is correct |
17 |
Correct |
43 ms |
41080 KB |
Output is correct |
18 |
Correct |
966 ms |
125660 KB |
Output is correct |
19 |
Correct |
325 ms |
48324 KB |
Output is correct |
20 |
Correct |
251 ms |
45228 KB |
Output is correct |
21 |
Correct |
272 ms |
45840 KB |
Output is correct |
22 |
Correct |
288 ms |
46456 KB |
Output is correct |
23 |
Correct |
334 ms |
48044 KB |
Output is correct |
24 |
Correct |
256 ms |
45616 KB |
Output is correct |
25 |
Correct |
284 ms |
46492 KB |
Output is correct |
26 |
Correct |
293 ms |
46876 KB |
Output is correct |
27 |
Correct |
606 ms |
109944 KB |
Output is correct |
28 |
Correct |
432 ms |
75896 KB |
Output is correct |
29 |
Correct |
593 ms |
104344 KB |
Output is correct |
30 |
Correct |
863 ms |
204664 KB |
Output is correct |
31 |
Correct |
49 ms |
41208 KB |
Output is correct |
32 |
Correct |
827 ms |
110712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
41336 KB |
Output is correct |
2 |
Correct |
51 ms |
42360 KB |
Output is correct |
3 |
Correct |
47 ms |
41336 KB |
Output is correct |
4 |
Correct |
47 ms |
41464 KB |
Output is correct |
5 |
Correct |
50 ms |
42620 KB |
Output is correct |
6 |
Correct |
45 ms |
41052 KB |
Output is correct |
7 |
Correct |
44 ms |
41080 KB |
Output is correct |
8 |
Correct |
44 ms |
41080 KB |
Output is correct |
9 |
Correct |
44 ms |
41080 KB |
Output is correct |
10 |
Correct |
45 ms |
41080 KB |
Output is correct |
11 |
Correct |
50 ms |
41592 KB |
Output is correct |
12 |
Correct |
48 ms |
42104 KB |
Output is correct |
13 |
Correct |
50 ms |
43128 KB |
Output is correct |
14 |
Correct |
52 ms |
43640 KB |
Output is correct |
15 |
Correct |
46 ms |
41052 KB |
Output is correct |
16 |
Correct |
44 ms |
41080 KB |
Output is correct |
17 |
Correct |
43 ms |
41080 KB |
Output is correct |
18 |
Correct |
966 ms |
125660 KB |
Output is correct |
19 |
Correct |
325 ms |
48324 KB |
Output is correct |
20 |
Correct |
251 ms |
45228 KB |
Output is correct |
21 |
Correct |
272 ms |
45840 KB |
Output is correct |
22 |
Correct |
288 ms |
46456 KB |
Output is correct |
23 |
Correct |
334 ms |
48044 KB |
Output is correct |
24 |
Correct |
256 ms |
45616 KB |
Output is correct |
25 |
Correct |
284 ms |
46492 KB |
Output is correct |
26 |
Correct |
293 ms |
46876 KB |
Output is correct |
27 |
Correct |
606 ms |
109944 KB |
Output is correct |
28 |
Correct |
432 ms |
75896 KB |
Output is correct |
29 |
Correct |
593 ms |
104344 KB |
Output is correct |
30 |
Correct |
863 ms |
204664 KB |
Output is correct |
31 |
Correct |
49 ms |
41208 KB |
Output is correct |
32 |
Correct |
827 ms |
110712 KB |
Output is correct |
33 |
Correct |
534 ms |
201080 KB |
Output is correct |
34 |
Correct |
275 ms |
198648 KB |
Output is correct |
35 |
Correct |
304 ms |
201080 KB |
Output is correct |
36 |
Correct |
279 ms |
159952 KB |
Output is correct |
37 |
Correct |
138 ms |
71148 KB |
Output is correct |
38 |
Correct |
243 ms |
100856 KB |
Output is correct |
39 |
Correct |
417 ms |
183928 KB |
Output is correct |
40 |
Correct |
399 ms |
167772 KB |
Output is correct |
41 |
Correct |
154 ms |
72824 KB |
Output is correct |
42 |
Correct |
280 ms |
119800 KB |
Output is correct |
43 |
Correct |
533 ms |
201024 KB |
Output is correct |
44 |
Correct |
296 ms |
198636 KB |
Output is correct |
45 |
Correct |
309 ms |
201104 KB |
Output is correct |
46 |
Correct |
282 ms |
159992 KB |
Output is correct |
47 |
Correct |
152 ms |
65272 KB |
Output is correct |
48 |
Correct |
221 ms |
100940 KB |
Output is correct |
49 |
Correct |
411 ms |
201340 KB |
Output is correct |
50 |
Correct |
385 ms |
202332 KB |
Output is correct |
51 |
Correct |
387 ms |
202104 KB |
Output is correct |
52 |
Correct |
415 ms |
183960 KB |
Output is correct |
53 |
Correct |
398 ms |
167928 KB |
Output is correct |
54 |
Correct |
153 ms |
72700 KB |
Output is correct |
55 |
Correct |
280 ms |
119544 KB |
Output is correct |
56 |
Correct |
535 ms |
201208 KB |
Output is correct |
57 |
Correct |
272 ms |
198648 KB |
Output is correct |
58 |
Correct |
303 ms |
201080 KB |
Output is correct |
59 |
Correct |
280 ms |
159852 KB |
Output is correct |
60 |
Correct |
130 ms |
65116 KB |
Output is correct |
61 |
Correct |
221 ms |
100876 KB |
Output is correct |
62 |
Correct |
411 ms |
201208 KB |
Output is correct |
63 |
Correct |
389 ms |
202104 KB |
Output is correct |
64 |
Correct |
391 ms |
202232 KB |
Output is correct |
65 |
Correct |
1599 ms |
187520 KB |
Output is correct |
66 |
Correct |
1406 ms |
171300 KB |
Output is correct |
67 |
Correct |
589 ms |
76412 KB |
Output is correct |
68 |
Correct |
703 ms |
123128 KB |
Output is correct |
69 |
Correct |
1058 ms |
204804 KB |
Output is correct |
70 |
Correct |
734 ms |
202104 KB |
Output is correct |
71 |
Correct |
766 ms |
204576 KB |
Output is correct |
72 |
Correct |
717 ms |
163320 KB |
Output is correct |
73 |
Correct |
487 ms |
68600 KB |
Output is correct |
74 |
Correct |
589 ms |
104440 KB |
Output is correct |
75 |
Correct |
769 ms |
204648 KB |
Output is correct |
76 |
Correct |
956 ms |
205660 KB |
Output is correct |
77 |
Correct |
817 ms |
205688 KB |
Output is correct |
78 |
Correct |
755 ms |
140124 KB |
Output is correct |
79 |
Correct |
1018 ms |
204716 KB |
Output is correct |
80 |
Correct |
1045 ms |
203396 KB |
Output is correct |
81 |
Correct |
864 ms |
166904 KB |
Output is correct |
82 |
Correct |
991 ms |
164792 KB |
Output is correct |
83 |
Correct |
371 ms |
44844 KB |
Output is correct |
84 |
Correct |
1022 ms |
204540 KB |
Output is correct |
85 |
Correct |
1048 ms |
201904 KB |
Output is correct |
86 |
Correct |
894 ms |
163904 KB |
Output is correct |
87 |
Correct |
570 ms |
190452 KB |
Output is correct |
88 |
Correct |
559 ms |
201848 KB |
Output is correct |
89 |
Correct |
611 ms |
200436 KB |
Output is correct |
90 |
Correct |
526 ms |
164148 KB |
Output is correct |
91 |
Correct |
835 ms |
154960 KB |
Output is correct |