/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
// lethal option
#include"rainbow.h"
#include<bits/stdc++.h>
using namespace std;
#define all(flg) flg.begin(), flg.end()
#define pb push_back
#define fi first
#define se second
#define endl "\n"
#define eb emplace_back
#define ii pair<int, int>
#define PI 3.141592653589793238462643383279502884
#define ll long long
#define for1(i, ff, gg) for(int i = ff; i <= gg; ++i)
#define for2(i, ff, gg) for(int i = ff; i >= gg; --i)
const int mod = 1e9 + 7;
const int maxN = 1 << 20;
int n, m;
int x, y, z, k;
int cnt = 0;
int a[maxN * 26];
struct sextree{
vector<ii> vac;
int sta[200005];
int sz[200005];
void plug(int x, int y){
vac.pb(ii(x, y));
}
void extract(){
sort(all(vac));
vac.resize(unique(all(vac)) - vac.begin());
memset(sz, 0, sizeof(sz));
for(ii pr : vac){
x = pr.fi;
while(x < 200005){
++sz[x];
x += x & -x;
}
}
for1(i, 0, 200005 - 1){
sta[i] = cnt;
cnt += sz[i];
sz[i] = 0;
}
for(ii pr : vac){
x = pr.fi; y = pr.se;
while(x < 200005){
a[sta[x] + sz[x]] = y;
++sz[x];
x += x & -x;
}
}
for1(i, 0, 200005 - 1) sort(a + sta[i], a + sta[i] + sz[i]);
}
int skim(int id, int le, int ri){
--le;
int res = 0;
while(id){
int* sus1 = a + sta[id];
int* sus2 = sus1 + sz[id];
res += upper_bound(sus1, sus2, ri)
- upper_bound(sus1, sus2, le);
id -= (id & -id);
}
return res;
}
int rect(int ar, int ac, int br, int bc){
return skim(br, ac, bc) - skim(ar - 1, ac, bc);
}
};
sextree only, edcol, edrow, cluster;
int repr[128];
int xx[] = {-1, 0, 1, 0};
int yy[] = {0, 1, 0, -1};
// N E S W
int maxr = 0, maxc = 0, minr = maxN, minc = maxN;
void init(int non, int mon, int sn, int sm, int len, char* s){
n = non; m = mon;
repr['N'] = 0;
repr['E'] = 1;
repr['S'] = 2;
repr['W'] = 3;
vector<ii> sus;
sus.pb({sn, sm});
for1(i, 0, len - 1){
char cc = s[i];
sn += xx[repr[cc]];
sm += yy[repr[cc]];
sus.pb({sn, sm});
}
sort(all(sus)); sus.resize(unique(all(sus)) - sus.begin());
for(ii pr : sus){
x = pr.fi; y = pr.se;
// cout << x << " " << y << endl;
maxr = max(maxr, x);
minr = min(minr, x);
maxc = max(maxc, y);
minc = min(minc, y);
only.plug(x, y);
edcol.plug(x, y);
edcol.plug(x + 1, y);
edrow.plug(x, y);
edrow.plug(x, y + 1);
cluster.plug(x + 1, y + 1);
cluster.plug(x + 1, y);
cluster.plug(x, y + 1);
cluster.plug(x, y);
}
only.extract();
edcol.extract();
edrow.extract();
cluster.extract();
}
int colour(int ar, int ac, int br, int bc){
int ans = 0;
if(ar < minr && br > maxr && ac < minc && bc > maxc) ans = 1;
// for(ii pr : edcol.vac) cout << pr.fi << " " << pr.se << endl;
// cout << edcol.rect(ar, ac, br - 1, bc) << endl;
// exit(0);
ans += edcol.rect(ar + 1, ac, br, bc);
ans += edrow.rect(ar, ac + 1, br, bc);
ans -= only.rect(ar, ac, br, bc);
ans -= cluster.rect(ar + 1, ac + 1, br, bc);
++ans;
return ans;
}
Compilation message
rainbow.cpp: In function 'void init(int, int, int, int, int, char*)':
rainbow.cpp:100:23: warning: array subscript has type 'char' [-Wchar-subscripts]
100 | sn += xx[repr[cc]];
| ^~
rainbow.cpp:101:23: warning: array subscript has type 'char' [-Wchar-subscripts]
101 | sm += yy[repr[cc]];
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
6612 KB |
Output is correct |
2 |
Correct |
10 ms |
6944 KB |
Output is correct |
3 |
Correct |
7 ms |
6612 KB |
Output is correct |
4 |
Correct |
6 ms |
6612 KB |
Output is correct |
5 |
Correct |
10 ms |
7124 KB |
Output is correct |
6 |
Correct |
5 ms |
6484 KB |
Output is correct |
7 |
Correct |
4 ms |
6480 KB |
Output is correct |
8 |
Correct |
5 ms |
6484 KB |
Output is correct |
9 |
Correct |
4 ms |
6484 KB |
Output is correct |
10 |
Correct |
5 ms |
6484 KB |
Output is correct |
11 |
Correct |
9 ms |
6740 KB |
Output is correct |
12 |
Correct |
8 ms |
6868 KB |
Output is correct |
13 |
Correct |
13 ms |
7256 KB |
Output is correct |
14 |
Correct |
13 ms |
7404 KB |
Output is correct |
15 |
Correct |
5 ms |
6480 KB |
Output is correct |
16 |
Correct |
5 ms |
6484 KB |
Output is correct |
17 |
Correct |
4 ms |
6484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
6484 KB |
Output is correct |
2 |
Correct |
4 ms |
6484 KB |
Output is correct |
3 |
Correct |
457 ms |
39272 KB |
Output is correct |
4 |
Correct |
716 ms |
60228 KB |
Output is correct |
5 |
Correct |
722 ms |
59836 KB |
Output is correct |
6 |
Correct |
583 ms |
49444 KB |
Output is correct |
7 |
Correct |
559 ms |
48348 KB |
Output is correct |
8 |
Correct |
68 ms |
10244 KB |
Output is correct |
9 |
Correct |
625 ms |
60208 KB |
Output is correct |
10 |
Correct |
670 ms |
59904 KB |
Output is correct |
11 |
Correct |
544 ms |
49512 KB |
Output is correct |
12 |
Correct |
779 ms |
56572 KB |
Output is correct |
13 |
Correct |
656 ms |
60028 KB |
Output is correct |
14 |
Correct |
593 ms |
59752 KB |
Output is correct |
15 |
Correct |
503 ms |
49516 KB |
Output is correct |
16 |
Correct |
557 ms |
46212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
6480 KB |
Output is correct |
2 |
Correct |
348 ms |
38708 KB |
Output is correct |
3 |
Correct |
116 ms |
38248 KB |
Output is correct |
4 |
Correct |
139 ms |
41192 KB |
Output is correct |
5 |
Correct |
140 ms |
31668 KB |
Output is correct |
6 |
Correct |
60 ms |
15068 KB |
Output is correct |
7 |
Correct |
91 ms |
19332 KB |
Output is correct |
8 |
Correct |
423 ms |
51336 KB |
Output is correct |
9 |
Correct |
382 ms |
46380 KB |
Output is correct |
10 |
Correct |
62 ms |
13960 KB |
Output is correct |
11 |
Correct |
140 ms |
23924 KB |
Output is correct |
12 |
Correct |
345 ms |
38712 KB |
Output is correct |
13 |
Correct |
108 ms |
38244 KB |
Output is correct |
14 |
Correct |
137 ms |
41072 KB |
Output is correct |
15 |
Correct |
143 ms |
31708 KB |
Output is correct |
16 |
Correct |
53 ms |
14072 KB |
Output is correct |
17 |
Correct |
112 ms |
22316 KB |
Output is correct |
18 |
Correct |
321 ms |
48976 KB |
Output is correct |
19 |
Correct |
227 ms |
39476 KB |
Output is correct |
20 |
Correct |
266 ms |
42532 KB |
Output is correct |
21 |
Correct |
418 ms |
51340 KB |
Output is correct |
22 |
Correct |
383 ms |
46516 KB |
Output is correct |
23 |
Correct |
62 ms |
13972 KB |
Output is correct |
24 |
Correct |
138 ms |
23924 KB |
Output is correct |
25 |
Correct |
344 ms |
38588 KB |
Output is correct |
26 |
Correct |
109 ms |
38312 KB |
Output is correct |
27 |
Correct |
137 ms |
41080 KB |
Output is correct |
28 |
Correct |
146 ms |
31768 KB |
Output is correct |
29 |
Correct |
51 ms |
13984 KB |
Output is correct |
30 |
Correct |
123 ms |
22316 KB |
Output is correct |
31 |
Correct |
333 ms |
48976 KB |
Output is correct |
32 |
Correct |
232 ms |
39516 KB |
Output is correct |
33 |
Correct |
264 ms |
42632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
6612 KB |
Output is correct |
2 |
Correct |
10 ms |
6944 KB |
Output is correct |
3 |
Correct |
7 ms |
6612 KB |
Output is correct |
4 |
Correct |
6 ms |
6612 KB |
Output is correct |
5 |
Correct |
10 ms |
7124 KB |
Output is correct |
6 |
Correct |
5 ms |
6484 KB |
Output is correct |
7 |
Correct |
4 ms |
6480 KB |
Output is correct |
8 |
Correct |
5 ms |
6484 KB |
Output is correct |
9 |
Correct |
4 ms |
6484 KB |
Output is correct |
10 |
Correct |
5 ms |
6484 KB |
Output is correct |
11 |
Correct |
9 ms |
6740 KB |
Output is correct |
12 |
Correct |
8 ms |
6868 KB |
Output is correct |
13 |
Correct |
13 ms |
7256 KB |
Output is correct |
14 |
Correct |
13 ms |
7404 KB |
Output is correct |
15 |
Correct |
5 ms |
6480 KB |
Output is correct |
16 |
Correct |
5 ms |
6484 KB |
Output is correct |
17 |
Correct |
4 ms |
6484 KB |
Output is correct |
18 |
Correct |
847 ms |
30824 KB |
Output is correct |
19 |
Correct |
229 ms |
11236 KB |
Output is correct |
20 |
Correct |
172 ms |
10100 KB |
Output is correct |
21 |
Correct |
206 ms |
10316 KB |
Output is correct |
22 |
Correct |
210 ms |
10580 KB |
Output is correct |
23 |
Correct |
216 ms |
11200 KB |
Output is correct |
24 |
Correct |
231 ms |
10368 KB |
Output is correct |
25 |
Correct |
230 ms |
10652 KB |
Output is correct |
26 |
Correct |
231 ms |
10628 KB |
Output is correct |
27 |
Correct |
333 ms |
26924 KB |
Output is correct |
28 |
Correct |
279 ms |
19412 KB |
Output is correct |
29 |
Correct |
313 ms |
25824 KB |
Output is correct |
30 |
Correct |
765 ms |
51668 KB |
Output is correct |
31 |
Correct |
7 ms |
6612 KB |
Output is correct |
32 |
Correct |
585 ms |
27864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
6612 KB |
Output is correct |
2 |
Correct |
10 ms |
6944 KB |
Output is correct |
3 |
Correct |
7 ms |
6612 KB |
Output is correct |
4 |
Correct |
6 ms |
6612 KB |
Output is correct |
5 |
Correct |
10 ms |
7124 KB |
Output is correct |
6 |
Correct |
5 ms |
6484 KB |
Output is correct |
7 |
Correct |
4 ms |
6480 KB |
Output is correct |
8 |
Correct |
5 ms |
6484 KB |
Output is correct |
9 |
Correct |
4 ms |
6484 KB |
Output is correct |
10 |
Correct |
5 ms |
6484 KB |
Output is correct |
11 |
Correct |
9 ms |
6740 KB |
Output is correct |
12 |
Correct |
8 ms |
6868 KB |
Output is correct |
13 |
Correct |
13 ms |
7256 KB |
Output is correct |
14 |
Correct |
13 ms |
7404 KB |
Output is correct |
15 |
Correct |
5 ms |
6480 KB |
Output is correct |
16 |
Correct |
5 ms |
6484 KB |
Output is correct |
17 |
Correct |
4 ms |
6484 KB |
Output is correct |
18 |
Correct |
847 ms |
30824 KB |
Output is correct |
19 |
Correct |
229 ms |
11236 KB |
Output is correct |
20 |
Correct |
172 ms |
10100 KB |
Output is correct |
21 |
Correct |
206 ms |
10316 KB |
Output is correct |
22 |
Correct |
210 ms |
10580 KB |
Output is correct |
23 |
Correct |
216 ms |
11200 KB |
Output is correct |
24 |
Correct |
231 ms |
10368 KB |
Output is correct |
25 |
Correct |
230 ms |
10652 KB |
Output is correct |
26 |
Correct |
231 ms |
10628 KB |
Output is correct |
27 |
Correct |
333 ms |
26924 KB |
Output is correct |
28 |
Correct |
279 ms |
19412 KB |
Output is correct |
29 |
Correct |
313 ms |
25824 KB |
Output is correct |
30 |
Correct |
765 ms |
51668 KB |
Output is correct |
31 |
Correct |
7 ms |
6612 KB |
Output is correct |
32 |
Correct |
585 ms |
27864 KB |
Output is correct |
33 |
Correct |
348 ms |
38708 KB |
Output is correct |
34 |
Correct |
116 ms |
38248 KB |
Output is correct |
35 |
Correct |
139 ms |
41192 KB |
Output is correct |
36 |
Correct |
140 ms |
31668 KB |
Output is correct |
37 |
Correct |
60 ms |
15068 KB |
Output is correct |
38 |
Correct |
91 ms |
19332 KB |
Output is correct |
39 |
Correct |
423 ms |
51336 KB |
Output is correct |
40 |
Correct |
382 ms |
46380 KB |
Output is correct |
41 |
Correct |
62 ms |
13960 KB |
Output is correct |
42 |
Correct |
140 ms |
23924 KB |
Output is correct |
43 |
Correct |
345 ms |
38712 KB |
Output is correct |
44 |
Correct |
108 ms |
38244 KB |
Output is correct |
45 |
Correct |
137 ms |
41072 KB |
Output is correct |
46 |
Correct |
143 ms |
31708 KB |
Output is correct |
47 |
Correct |
53 ms |
14072 KB |
Output is correct |
48 |
Correct |
112 ms |
22316 KB |
Output is correct |
49 |
Correct |
321 ms |
48976 KB |
Output is correct |
50 |
Correct |
227 ms |
39476 KB |
Output is correct |
51 |
Correct |
266 ms |
42532 KB |
Output is correct |
52 |
Correct |
418 ms |
51340 KB |
Output is correct |
53 |
Correct |
383 ms |
46516 KB |
Output is correct |
54 |
Correct |
62 ms |
13972 KB |
Output is correct |
55 |
Correct |
138 ms |
23924 KB |
Output is correct |
56 |
Correct |
344 ms |
38588 KB |
Output is correct |
57 |
Correct |
109 ms |
38312 KB |
Output is correct |
58 |
Correct |
137 ms |
41080 KB |
Output is correct |
59 |
Correct |
146 ms |
31768 KB |
Output is correct |
60 |
Correct |
51 ms |
13984 KB |
Output is correct |
61 |
Correct |
123 ms |
22316 KB |
Output is correct |
62 |
Correct |
333 ms |
48976 KB |
Output is correct |
63 |
Correct |
232 ms |
39516 KB |
Output is correct |
64 |
Correct |
264 ms |
42632 KB |
Output is correct |
65 |
Correct |
457 ms |
39272 KB |
Output is correct |
66 |
Correct |
716 ms |
60228 KB |
Output is correct |
67 |
Correct |
722 ms |
59836 KB |
Output is correct |
68 |
Correct |
583 ms |
49444 KB |
Output is correct |
69 |
Correct |
559 ms |
48348 KB |
Output is correct |
70 |
Correct |
68 ms |
10244 KB |
Output is correct |
71 |
Correct |
625 ms |
60208 KB |
Output is correct |
72 |
Correct |
670 ms |
59904 KB |
Output is correct |
73 |
Correct |
544 ms |
49512 KB |
Output is correct |
74 |
Correct |
779 ms |
56572 KB |
Output is correct |
75 |
Correct |
656 ms |
60028 KB |
Output is correct |
76 |
Correct |
593 ms |
59752 KB |
Output is correct |
77 |
Correct |
503 ms |
49516 KB |
Output is correct |
78 |
Correct |
557 ms |
46212 KB |
Output is correct |
79 |
Correct |
753 ms |
53956 KB |
Output is correct |
80 |
Correct |
720 ms |
49208 KB |
Output is correct |
81 |
Correct |
304 ms |
17008 KB |
Output is correct |
82 |
Correct |
398 ms |
26596 KB |
Output is correct |
83 |
Correct |
599 ms |
41444 KB |
Output is correct |
84 |
Correct |
523 ms |
40976 KB |
Output is correct |
85 |
Correct |
435 ms |
43824 KB |
Output is correct |
86 |
Correct |
417 ms |
34500 KB |
Output is correct |
87 |
Correct |
183 ms |
16812 KB |
Output is correct |
88 |
Correct |
272 ms |
25080 KB |
Output is correct |
89 |
Correct |
482 ms |
51656 KB |
Output is correct |
90 |
Correct |
577 ms |
42208 KB |
Output is correct |
91 |
Correct |
502 ms |
45280 KB |
Output is correct |