#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define fir first
#define sec second
#define pushf push_front
#define pushb push_back
#define popf pop_front
#define popb pop_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define FOR(i, s, e) for(int i = s; i < e; i++)
#define RFOR(i, s, e) for(int i = e-1; i >= s; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
typedef vector<vpii> vvpii;
typedef vector<vpll> vvpll;
typedef queue<int> qi;
typedef queue<ll> qll;
typedef queue<pii> qpii;
typedef queue<pll> qpll;
typedef deque<int> dqi;
typedef deque<ll> dqll;
typedef deque<pii> dqpii;
typedef deque<pll> dqpll;
typedef priority_queue<int> pqi;
typedef priority_queue<ll> pqll;
typedef priority_queue<pii> pqpii;
typedef priority_queue<pll> pqpll;
typedef priority_queue<int, vi, greater<int> > r_pqi;
typedef priority_queue<ll, vll, greater<ll> > r_pqll;
typedef priority_queue<pii, vpii, greater<pii> > r_pqpii;
typedef priority_queue<pll, vpll, greater<pll> > r_pqpll;
const int maxn = 2e5 + 5;
int R, C;
struct BIT
{
vi com[maxn], pre[maxn];
BIT() {}
void update(int x, int y)
{
for (int i = x; i <= R; i += (i & (-i)))
com[i].pushb(y);
}
void build(int x)
{
sort(com[x].begin(), com[x].end());
vector<int> cur = com[x];
com[x].clear();
for (int y : cur)
{
if (com[x].empty() || com[x].back() != y)
{
com[x].pushb(y);
pre[x].pushb(1);
}
else
pre[x].back()++;
}
for (int i = 1; i < (int)com[x].size(); i++)
pre[x][i] += pre[x][i - 1];
}
void init(vpii &A)
{
sort(A.begin(), A.end());
A.erase(unique(A.begin(), A.end()), A.end());
for (auto [x, y] : A)
update(x, y);
for (int i = 1; i <= R; i++)
build(i);
}
int query(int x, int y)
{
int res = 0;
for (int i = x; i >= 1; i -= (i & (-i)))
{
int pos = upper_bound(com[i].begin(), com[i].end(), y) - com[i].begin() - 1;
res += (pos < 0 ? 0 : pre[i][pos]);
}
return res;
}
int get(int sx, int sy, int tx, int ty)
{
return query(tx, ty) - query(tx, sy - 1) - query(sx - 1, ty) + query(sx - 1, sy - 1);
}
} g, p, cc, rw;
void init(int _R, int _C, int x, int y, int M, char *S)
{
vector<pii> row, col, G, P;
R = _R + 1;
C = _C + 1;
for (int i = 0; i <= M; i++)
{
G.pushb({x, y});
for (int a = 0; a <= 1; a++)
for (int b = 0; b <= 1; b++)
{
P.pushb({x + a, y + b});
if (!b)
row.pushb({x + a, y + b});
if (!a)
col.pushb({x + a, y + b});
}
// cout << x << ' ' << y << '\n';
if (i == M)
break;
if (S[i] == 'N')
x--;
else if (S[i] == 'S')
x++;
else if (S[i] == 'W')
y--;
else
y++;
}
g.init(G);
p.init(P);
rw.init(row);
cc.init(col);
}
int colour(int ar, int ac, int br, int bc)
{
int V = p.get(ar + 1, ac + 1, br, bc);
int E = rw.get(ar + 1, ac, br, bc) + cc.get(ar, ac + 1, br, bc);
int total = g.get(ar, ac, br, bc), mid = 0;
if (ar + 2 <= br && ac + 2 <= bc)
mid = g.get(ar + 1, ac + 1, br - 1, bc - 1);
int CC = 1;
if (V >= 1 && total == mid)
CC++;
// cout << E << ' ' << V << ' ' << CC << ' ' << total << '\n';
return E - V + CC - total;
}
Compilation message
rainbow.cpp: In member function 'void BIT::init(vpii&)':
rainbow.cpp:86:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
86 | for (auto [x, y] : A)
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
37968 KB |
Output is correct |
2 |
Correct |
10 ms |
38304 KB |
Output is correct |
3 |
Correct |
8 ms |
37968 KB |
Output is correct |
4 |
Correct |
8 ms |
37968 KB |
Output is correct |
5 |
Correct |
11 ms |
38396 KB |
Output is correct |
6 |
Correct |
7 ms |
37968 KB |
Output is correct |
7 |
Correct |
7 ms |
37968 KB |
Output is correct |
8 |
Correct |
7 ms |
37796 KB |
Output is correct |
9 |
Correct |
8 ms |
37996 KB |
Output is correct |
10 |
Correct |
7 ms |
38140 KB |
Output is correct |
11 |
Correct |
9 ms |
37968 KB |
Output is correct |
12 |
Correct |
10 ms |
38032 KB |
Output is correct |
13 |
Correct |
10 ms |
38224 KB |
Output is correct |
14 |
Correct |
11 ms |
38480 KB |
Output is correct |
15 |
Correct |
7 ms |
37968 KB |
Output is correct |
16 |
Correct |
8 ms |
38136 KB |
Output is correct |
17 |
Correct |
7 ms |
37968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
38136 KB |
Output is correct |
2 |
Correct |
7 ms |
37968 KB |
Output is correct |
3 |
Correct |
151 ms |
48712 KB |
Output is correct |
4 |
Correct |
234 ms |
55216 KB |
Output is correct |
5 |
Correct |
241 ms |
55220 KB |
Output is correct |
6 |
Correct |
196 ms |
53168 KB |
Output is correct |
7 |
Correct |
226 ms |
52960 KB |
Output is correct |
8 |
Correct |
84 ms |
48576 KB |
Output is correct |
9 |
Correct |
225 ms |
55216 KB |
Output is correct |
10 |
Correct |
232 ms |
55216 KB |
Output is correct |
11 |
Correct |
207 ms |
53156 KB |
Output is correct |
12 |
Correct |
147 ms |
54448 KB |
Output is correct |
13 |
Correct |
136 ms |
55380 KB |
Output is correct |
14 |
Correct |
150 ms |
55216 KB |
Output is correct |
15 |
Correct |
144 ms |
53168 KB |
Output is correct |
16 |
Correct |
182 ms |
52912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
37968 KB |
Output is correct |
2 |
Correct |
367 ms |
89776 KB |
Output is correct |
3 |
Correct |
185 ms |
89780 KB |
Output is correct |
4 |
Correct |
198 ms |
94896 KB |
Output is correct |
5 |
Correct |
199 ms |
79792 KB |
Output is correct |
6 |
Correct |
107 ms |
53092 KB |
Output is correct |
7 |
Correct |
135 ms |
57264 KB |
Output is correct |
8 |
Correct |
105 ms |
55728 KB |
Output is correct |
9 |
Correct |
115 ms |
55568 KB |
Output is correct |
10 |
Correct |
53 ms |
44472 KB |
Output is correct |
11 |
Correct |
104 ms |
52912 KB |
Output is correct |
12 |
Correct |
359 ms |
89780 KB |
Output is correct |
13 |
Correct |
174 ms |
89960 KB |
Output is correct |
14 |
Correct |
198 ms |
94916 KB |
Output is correct |
15 |
Correct |
195 ms |
79792 KB |
Output is correct |
16 |
Correct |
103 ms |
52096 KB |
Output is correct |
17 |
Correct |
158 ms |
60860 KB |
Output is correct |
18 |
Correct |
362 ms |
90296 KB |
Output is correct |
19 |
Correct |
266 ms |
90320 KB |
Output is correct |
20 |
Correct |
318 ms |
96432 KB |
Output is correct |
21 |
Correct |
101 ms |
55780 KB |
Output is correct |
22 |
Correct |
117 ms |
55728 KB |
Output is correct |
23 |
Correct |
54 ms |
44472 KB |
Output is correct |
24 |
Correct |
96 ms |
52912 KB |
Output is correct |
25 |
Correct |
362 ms |
89772 KB |
Output is correct |
26 |
Correct |
172 ms |
89948 KB |
Output is correct |
27 |
Correct |
181 ms |
94924 KB |
Output is correct |
28 |
Correct |
192 ms |
79792 KB |
Output is correct |
29 |
Correct |
102 ms |
51888 KB |
Output is correct |
30 |
Correct |
156 ms |
60896 KB |
Output is correct |
31 |
Correct |
369 ms |
90032 KB |
Output is correct |
32 |
Correct |
273 ms |
90336 KB |
Output is correct |
33 |
Correct |
317 ms |
96560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
37968 KB |
Output is correct |
2 |
Correct |
10 ms |
38304 KB |
Output is correct |
3 |
Correct |
8 ms |
37968 KB |
Output is correct |
4 |
Correct |
8 ms |
37968 KB |
Output is correct |
5 |
Correct |
11 ms |
38396 KB |
Output is correct |
6 |
Correct |
7 ms |
37968 KB |
Output is correct |
7 |
Correct |
7 ms |
37968 KB |
Output is correct |
8 |
Correct |
7 ms |
37796 KB |
Output is correct |
9 |
Correct |
8 ms |
37996 KB |
Output is correct |
10 |
Correct |
7 ms |
38140 KB |
Output is correct |
11 |
Correct |
9 ms |
37968 KB |
Output is correct |
12 |
Correct |
10 ms |
38032 KB |
Output is correct |
13 |
Correct |
10 ms |
38224 KB |
Output is correct |
14 |
Correct |
11 ms |
38480 KB |
Output is correct |
15 |
Correct |
7 ms |
37968 KB |
Output is correct |
16 |
Correct |
8 ms |
38136 KB |
Output is correct |
17 |
Correct |
7 ms |
37968 KB |
Output is correct |
18 |
Correct |
518 ms |
56496 KB |
Output is correct |
19 |
Correct |
215 ms |
41972 KB |
Output is correct |
20 |
Correct |
149 ms |
41552 KB |
Output is correct |
21 |
Correct |
174 ms |
41544 KB |
Output is correct |
22 |
Correct |
184 ms |
41804 KB |
Output is correct |
23 |
Correct |
203 ms |
41984 KB |
Output is correct |
24 |
Correct |
182 ms |
41732 KB |
Output is correct |
25 |
Correct |
182 ms |
41852 KB |
Output is correct |
26 |
Correct |
194 ms |
41908 KB |
Output is correct |
27 |
Correct |
260 ms |
53716 KB |
Output is correct |
28 |
Correct |
243 ms |
50864 KB |
Output is correct |
29 |
Correct |
243 ms |
53168 KB |
Output is correct |
30 |
Correct |
408 ms |
67248 KB |
Output is correct |
31 |
Correct |
14 ms |
37968 KB |
Output is correct |
32 |
Correct |
396 ms |
54880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
37968 KB |
Output is correct |
2 |
Correct |
10 ms |
38304 KB |
Output is correct |
3 |
Correct |
8 ms |
37968 KB |
Output is correct |
4 |
Correct |
8 ms |
37968 KB |
Output is correct |
5 |
Correct |
11 ms |
38396 KB |
Output is correct |
6 |
Correct |
7 ms |
37968 KB |
Output is correct |
7 |
Correct |
7 ms |
37968 KB |
Output is correct |
8 |
Correct |
7 ms |
37796 KB |
Output is correct |
9 |
Correct |
8 ms |
37996 KB |
Output is correct |
10 |
Correct |
7 ms |
38140 KB |
Output is correct |
11 |
Correct |
9 ms |
37968 KB |
Output is correct |
12 |
Correct |
10 ms |
38032 KB |
Output is correct |
13 |
Correct |
10 ms |
38224 KB |
Output is correct |
14 |
Correct |
11 ms |
38480 KB |
Output is correct |
15 |
Correct |
7 ms |
37968 KB |
Output is correct |
16 |
Correct |
8 ms |
38136 KB |
Output is correct |
17 |
Correct |
7 ms |
37968 KB |
Output is correct |
18 |
Correct |
518 ms |
56496 KB |
Output is correct |
19 |
Correct |
215 ms |
41972 KB |
Output is correct |
20 |
Correct |
149 ms |
41552 KB |
Output is correct |
21 |
Correct |
174 ms |
41544 KB |
Output is correct |
22 |
Correct |
184 ms |
41804 KB |
Output is correct |
23 |
Correct |
203 ms |
41984 KB |
Output is correct |
24 |
Correct |
182 ms |
41732 KB |
Output is correct |
25 |
Correct |
182 ms |
41852 KB |
Output is correct |
26 |
Correct |
194 ms |
41908 KB |
Output is correct |
27 |
Correct |
260 ms |
53716 KB |
Output is correct |
28 |
Correct |
243 ms |
50864 KB |
Output is correct |
29 |
Correct |
243 ms |
53168 KB |
Output is correct |
30 |
Correct |
408 ms |
67248 KB |
Output is correct |
31 |
Correct |
14 ms |
37968 KB |
Output is correct |
32 |
Correct |
396 ms |
54880 KB |
Output is correct |
33 |
Correct |
367 ms |
89776 KB |
Output is correct |
34 |
Correct |
185 ms |
89780 KB |
Output is correct |
35 |
Correct |
198 ms |
94896 KB |
Output is correct |
36 |
Correct |
199 ms |
79792 KB |
Output is correct |
37 |
Correct |
107 ms |
53092 KB |
Output is correct |
38 |
Correct |
135 ms |
57264 KB |
Output is correct |
39 |
Correct |
105 ms |
55728 KB |
Output is correct |
40 |
Correct |
115 ms |
55568 KB |
Output is correct |
41 |
Correct |
53 ms |
44472 KB |
Output is correct |
42 |
Correct |
104 ms |
52912 KB |
Output is correct |
43 |
Correct |
359 ms |
89780 KB |
Output is correct |
44 |
Correct |
174 ms |
89960 KB |
Output is correct |
45 |
Correct |
198 ms |
94916 KB |
Output is correct |
46 |
Correct |
195 ms |
79792 KB |
Output is correct |
47 |
Correct |
103 ms |
52096 KB |
Output is correct |
48 |
Correct |
158 ms |
60860 KB |
Output is correct |
49 |
Correct |
362 ms |
90296 KB |
Output is correct |
50 |
Correct |
266 ms |
90320 KB |
Output is correct |
51 |
Correct |
318 ms |
96432 KB |
Output is correct |
52 |
Correct |
101 ms |
55780 KB |
Output is correct |
53 |
Correct |
117 ms |
55728 KB |
Output is correct |
54 |
Correct |
54 ms |
44472 KB |
Output is correct |
55 |
Correct |
96 ms |
52912 KB |
Output is correct |
56 |
Correct |
362 ms |
89772 KB |
Output is correct |
57 |
Correct |
172 ms |
89948 KB |
Output is correct |
58 |
Correct |
181 ms |
94924 KB |
Output is correct |
59 |
Correct |
192 ms |
79792 KB |
Output is correct |
60 |
Correct |
102 ms |
51888 KB |
Output is correct |
61 |
Correct |
156 ms |
60896 KB |
Output is correct |
62 |
Correct |
369 ms |
90032 KB |
Output is correct |
63 |
Correct |
273 ms |
90336 KB |
Output is correct |
64 |
Correct |
317 ms |
96560 KB |
Output is correct |
65 |
Correct |
151 ms |
48712 KB |
Output is correct |
66 |
Correct |
234 ms |
55216 KB |
Output is correct |
67 |
Correct |
241 ms |
55220 KB |
Output is correct |
68 |
Correct |
196 ms |
53168 KB |
Output is correct |
69 |
Correct |
226 ms |
52960 KB |
Output is correct |
70 |
Correct |
84 ms |
48576 KB |
Output is correct |
71 |
Correct |
225 ms |
55216 KB |
Output is correct |
72 |
Correct |
232 ms |
55216 KB |
Output is correct |
73 |
Correct |
207 ms |
53156 KB |
Output is correct |
74 |
Correct |
147 ms |
54448 KB |
Output is correct |
75 |
Correct |
136 ms |
55380 KB |
Output is correct |
76 |
Correct |
150 ms |
55216 KB |
Output is correct |
77 |
Correct |
144 ms |
53168 KB |
Output is correct |
78 |
Correct |
182 ms |
52912 KB |
Output is correct |
79 |
Correct |
434 ms |
55728 KB |
Output is correct |
80 |
Correct |
515 ms |
55728 KB |
Output is correct |
81 |
Correct |
283 ms |
45920 KB |
Output is correct |
82 |
Correct |
296 ms |
52908 KB |
Output is correct |
83 |
Correct |
546 ms |
89956 KB |
Output is correct |
84 |
Correct |
355 ms |
89980 KB |
Output is correct |
85 |
Correct |
399 ms |
95072 KB |
Output is correct |
86 |
Correct |
384 ms |
80816 KB |
Output is correct |
87 |
Correct |
210 ms |
52132 KB |
Output is correct |
88 |
Correct |
262 ms |
60440 KB |
Output is correct |
89 |
Correct |
460 ms |
90292 KB |
Output is correct |
90 |
Correct |
506 ms |
90488 KB |
Output is correct |
91 |
Correct |
474 ms |
96516 KB |
Output is correct |