# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1101136 |
2024-10-15T15:23:48 Z |
rainboy |
Mosaic (IOI24_mosaic) |
C++17 |
|
133 ms |
31680 KB |
#include "mosaic.h"
#include <vector>
using namespace std;
typedef vector<int> vi;
typedef vector<long long> vl;
const int N = 200000;
int dp[3][N], dq[N][3];
int ss[3][N], tt[N][3];
int uu[N * 2]; long long vv[N * 2];
int n;
int sum(int l, int r) {
return l > r ? 0 : uu[r] - (l == 0 ? 0 : uu[l - 1]);
}
long long sum_incr(int l, int r) {
return l > r ? 0 : vv[r] - (l == 0 ? 0 : vv[l - 1]) - (long long) sum(l, r) * (l - 1);
}
long long sum_decr(int l, int r) {
return l > r ? 0 : (long long) sum(l, r) * (r - l + 2) - sum_incr(l, r);
}
long long solve(int i, int j) {
if (i < 0 || j < 0)
return 0;
if (i < 3)
return ss[i][j];
if (j < 3)
return tt[i][j];
long long ans = ss[2][j] + tt[i][2] - ss[2][2];
if (i < j)
ans += sum_incr(n - 1 + 3 - i, n - 2) + (long long) sum(n - 1, n - 1 + j - i) * (i - 2) + sum_decr(n + j - i, n - 1 + j - 3);
else
ans += sum_incr(n - 1 + 3 - i, n - 2 + j - i) + (long long) sum(n - 1 + j - i, n - 1) * (j - 2) + sum_decr(n, n - 1 + j - 3);
return ans;
}
vl mosaic(vi xx, vi yy, vi iil, vi iir, vi jjl, vi jjr) {
n = xx.size(); int q = iil.size();
if (n < 4) {
xx.resize(4), yy.resize(4);
for (int i = n; i < 4; i++)
xx[i] = yy[i] = 0;
n = 4;
}
vl ans(q, 0);
for (int i = 0; i < 3; i++)
for (int j = 0; j < n; j++)
if (i == 0)
dp[i][j] = xx[j];
else if (j == 0)
dp[i][j] = yy[i];
else
dp[i][j] = !dp[i - 1][j] && !dp[i][j - 1];
for (int i = 0; i < n; i++)
for (int j = 0; j < 3; j++)
if (i == 0)
dq[i][j] = xx[j];
else if (j == 0)
dq[i][j] = yy[i];
else
dq[i][j] = !dq[i - 1][j] && !dq[i][j - 1];
for (int i = 0; i < 3; i++)
for (int j = 0; j < n; j++)
ss[i][j] = dp[i][j];
for (int i = 0; i < 3; i++)
for (int j = 1; j < n; j++)
ss[i][j] += ss[i][j - 1];
for (int i = 1; i < 3; i++)
for (int j = 0; j < n; j++)
ss[i][j] += ss[i - 1][j];
for (int i = 0; i < n; i++)
for (int j = 0; j < 3; j++)
tt[i][j] = dq[i][j];
for (int i = 0; i < n; i++)
for (int j = 1; j < 3; j++)
tt[i][j] += tt[i][j - 1];
for (int i = 1; i < n; i++)
for (int j = 0; j < 3; j++)
tt[i][j] += tt[i - 1][j];
for (int i = 2, j = 2; i < n; i++) {
uu[n - 1 + j - i] = dq[i][j];
vv[n - 1 + j - i] = (long long) dq[i][j] * (n - 1 + j - i);
}
for (int i = 2, j = 2; j < n; j++) {
uu[n - 1 + j - i] = dp[i][j];
vv[n - 1 + j - i] = (long long) dp[i][j] * (n - 1 + j - i);
}
for (int d = 1; d < n * 2; d++)
uu[d] += uu[d - 1];
for (int d = 1; d < n * 2; d++)
vv[d] += vv[d - 1];
for (int h = 0; h < q; h++) {
int il = iil[h], jl = jjl[h], ir = iir[h], jr = jjr[h];
ans[h] = solve(ir, jr) - solve(ir, jl - 1) - solve(il - 1, jr) + solve(il - 1, jl - 1);
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
10580 KB |
Output is correct |
2 |
Correct |
2 ms |
10580 KB |
Output is correct |
3 |
Correct |
1 ms |
10580 KB |
Output is correct |
4 |
Correct |
2 ms |
10744 KB |
Output is correct |
5 |
Correct |
2 ms |
10580 KB |
Output is correct |
6 |
Correct |
2 ms |
10676 KB |
Output is correct |
7 |
Correct |
2 ms |
10744 KB |
Output is correct |
8 |
Correct |
2 ms |
10580 KB |
Output is correct |
9 |
Correct |
2 ms |
10580 KB |
Output is correct |
10 |
Correct |
2 ms |
10580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
10580 KB |
Output is correct |
2 |
Correct |
2 ms |
10580 KB |
Output is correct |
3 |
Correct |
1 ms |
10580 KB |
Output is correct |
4 |
Correct |
2 ms |
10744 KB |
Output is correct |
5 |
Correct |
2 ms |
10580 KB |
Output is correct |
6 |
Correct |
2 ms |
10676 KB |
Output is correct |
7 |
Correct |
2 ms |
10744 KB |
Output is correct |
8 |
Correct |
2 ms |
10580 KB |
Output is correct |
9 |
Correct |
2 ms |
10580 KB |
Output is correct |
10 |
Correct |
2 ms |
10580 KB |
Output is correct |
11 |
Correct |
2 ms |
10580 KB |
Output is correct |
12 |
Correct |
2 ms |
10580 KB |
Output is correct |
13 |
Correct |
2 ms |
10580 KB |
Output is correct |
14 |
Correct |
2 ms |
10580 KB |
Output is correct |
15 |
Correct |
2 ms |
10680 KB |
Output is correct |
16 |
Correct |
2 ms |
10580 KB |
Output is correct |
17 |
Correct |
2 ms |
10592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
125 ms |
29508 KB |
Output is correct |
2 |
Correct |
96 ms |
29256 KB |
Output is correct |
3 |
Correct |
105 ms |
28748 KB |
Output is correct |
4 |
Correct |
108 ms |
29272 KB |
Output is correct |
5 |
Correct |
77 ms |
26888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
10580 KB |
Output is correct |
2 |
Correct |
2 ms |
10580 KB |
Output is correct |
3 |
Correct |
1 ms |
10580 KB |
Output is correct |
4 |
Correct |
2 ms |
10744 KB |
Output is correct |
5 |
Correct |
2 ms |
10580 KB |
Output is correct |
6 |
Correct |
2 ms |
10676 KB |
Output is correct |
7 |
Correct |
2 ms |
10744 KB |
Output is correct |
8 |
Correct |
2 ms |
10580 KB |
Output is correct |
9 |
Correct |
2 ms |
10580 KB |
Output is correct |
10 |
Correct |
2 ms |
10580 KB |
Output is correct |
11 |
Correct |
2 ms |
10580 KB |
Output is correct |
12 |
Correct |
2 ms |
10580 KB |
Output is correct |
13 |
Correct |
2 ms |
10580 KB |
Output is correct |
14 |
Correct |
2 ms |
10580 KB |
Output is correct |
15 |
Correct |
2 ms |
10680 KB |
Output is correct |
16 |
Correct |
2 ms |
10580 KB |
Output is correct |
17 |
Correct |
2 ms |
10592 KB |
Output is correct |
18 |
Correct |
74 ms |
22280 KB |
Output is correct |
19 |
Correct |
95 ms |
22100 KB |
Output is correct |
20 |
Correct |
86 ms |
22024 KB |
Output is correct |
21 |
Correct |
85 ms |
21832 KB |
Output is correct |
22 |
Correct |
70 ms |
21904 KB |
Output is correct |
23 |
Correct |
74 ms |
22004 KB |
Output is correct |
24 |
Correct |
74 ms |
22128 KB |
Output is correct |
25 |
Correct |
66 ms |
22132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
20076 KB |
Output is correct |
2 |
Correct |
108 ms |
31168 KB |
Output is correct |
3 |
Correct |
122 ms |
30596 KB |
Output is correct |
4 |
Correct |
104 ms |
30472 KB |
Output is correct |
5 |
Correct |
113 ms |
30908 KB |
Output is correct |
6 |
Correct |
112 ms |
31240 KB |
Output is correct |
7 |
Correct |
133 ms |
31304 KB |
Output is correct |
8 |
Correct |
118 ms |
31196 KB |
Output is correct |
9 |
Correct |
96 ms |
28332 KB |
Output is correct |
10 |
Correct |
104 ms |
28456 KB |
Output is correct |
11 |
Correct |
105 ms |
28488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
112 ms |
31248 KB |
Output is correct |
2 |
Correct |
110 ms |
31304 KB |
Output is correct |
3 |
Correct |
119 ms |
29764 KB |
Output is correct |
4 |
Correct |
109 ms |
29760 KB |
Output is correct |
5 |
Correct |
119 ms |
31680 KB |
Output is correct |
6 |
Correct |
87 ms |
28488 KB |
Output is correct |
7 |
Correct |
90 ms |
25160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
125 ms |
29508 KB |
Output is correct |
2 |
Correct |
96 ms |
29256 KB |
Output is correct |
3 |
Correct |
105 ms |
28748 KB |
Output is correct |
4 |
Correct |
108 ms |
29272 KB |
Output is correct |
5 |
Correct |
77 ms |
26888 KB |
Output is correct |
6 |
Correct |
112 ms |
31248 KB |
Output is correct |
7 |
Correct |
110 ms |
31304 KB |
Output is correct |
8 |
Correct |
119 ms |
29764 KB |
Output is correct |
9 |
Correct |
109 ms |
29760 KB |
Output is correct |
10 |
Correct |
119 ms |
31680 KB |
Output is correct |
11 |
Correct |
87 ms |
28488 KB |
Output is correct |
12 |
Correct |
90 ms |
25160 KB |
Output is correct |
13 |
Correct |
117 ms |
31108 KB |
Output is correct |
14 |
Correct |
106 ms |
31168 KB |
Output is correct |
15 |
Correct |
110 ms |
31304 KB |
Output is correct |
16 |
Correct |
104 ms |
29624 KB |
Output is correct |
17 |
Correct |
103 ms |
30792 KB |
Output is correct |
18 |
Correct |
109 ms |
31296 KB |
Output is correct |
19 |
Correct |
88 ms |
27976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10580 KB |
Output is correct |
2 |
Correct |
1 ms |
10580 KB |
Output is correct |
3 |
Correct |
2 ms |
10580 KB |
Output is correct |
4 |
Correct |
1 ms |
10580 KB |
Output is correct |
5 |
Correct |
2 ms |
10744 KB |
Output is correct |
6 |
Correct |
2 ms |
10580 KB |
Output is correct |
7 |
Correct |
2 ms |
10676 KB |
Output is correct |
8 |
Correct |
2 ms |
10744 KB |
Output is correct |
9 |
Correct |
2 ms |
10580 KB |
Output is correct |
10 |
Correct |
2 ms |
10580 KB |
Output is correct |
11 |
Correct |
2 ms |
10580 KB |
Output is correct |
12 |
Correct |
2 ms |
10580 KB |
Output is correct |
13 |
Correct |
2 ms |
10580 KB |
Output is correct |
14 |
Correct |
2 ms |
10580 KB |
Output is correct |
15 |
Correct |
2 ms |
10580 KB |
Output is correct |
16 |
Correct |
2 ms |
10680 KB |
Output is correct |
17 |
Correct |
2 ms |
10580 KB |
Output is correct |
18 |
Correct |
2 ms |
10592 KB |
Output is correct |
19 |
Correct |
125 ms |
29508 KB |
Output is correct |
20 |
Correct |
96 ms |
29256 KB |
Output is correct |
21 |
Correct |
105 ms |
28748 KB |
Output is correct |
22 |
Correct |
108 ms |
29272 KB |
Output is correct |
23 |
Correct |
77 ms |
26888 KB |
Output is correct |
24 |
Correct |
74 ms |
22280 KB |
Output is correct |
25 |
Correct |
95 ms |
22100 KB |
Output is correct |
26 |
Correct |
86 ms |
22024 KB |
Output is correct |
27 |
Correct |
85 ms |
21832 KB |
Output is correct |
28 |
Correct |
70 ms |
21904 KB |
Output is correct |
29 |
Correct |
74 ms |
22004 KB |
Output is correct |
30 |
Correct |
74 ms |
22128 KB |
Output is correct |
31 |
Correct |
66 ms |
22132 KB |
Output is correct |
32 |
Correct |
56 ms |
20076 KB |
Output is correct |
33 |
Correct |
108 ms |
31168 KB |
Output is correct |
34 |
Correct |
122 ms |
30596 KB |
Output is correct |
35 |
Correct |
104 ms |
30472 KB |
Output is correct |
36 |
Correct |
113 ms |
30908 KB |
Output is correct |
37 |
Correct |
112 ms |
31240 KB |
Output is correct |
38 |
Correct |
133 ms |
31304 KB |
Output is correct |
39 |
Correct |
118 ms |
31196 KB |
Output is correct |
40 |
Correct |
96 ms |
28332 KB |
Output is correct |
41 |
Correct |
104 ms |
28456 KB |
Output is correct |
42 |
Correct |
105 ms |
28488 KB |
Output is correct |
43 |
Correct |
112 ms |
31248 KB |
Output is correct |
44 |
Correct |
110 ms |
31304 KB |
Output is correct |
45 |
Correct |
119 ms |
29764 KB |
Output is correct |
46 |
Correct |
109 ms |
29760 KB |
Output is correct |
47 |
Correct |
119 ms |
31680 KB |
Output is correct |
48 |
Correct |
87 ms |
28488 KB |
Output is correct |
49 |
Correct |
90 ms |
25160 KB |
Output is correct |
50 |
Correct |
117 ms |
31108 KB |
Output is correct |
51 |
Correct |
106 ms |
31168 KB |
Output is correct |
52 |
Correct |
110 ms |
31304 KB |
Output is correct |
53 |
Correct |
104 ms |
29624 KB |
Output is correct |
54 |
Correct |
103 ms |
30792 KB |
Output is correct |
55 |
Correct |
109 ms |
31296 KB |
Output is correct |
56 |
Correct |
88 ms |
27976 KB |
Output is correct |
57 |
Correct |
119 ms |
31108 KB |
Output is correct |
58 |
Correct |
131 ms |
30908 KB |
Output is correct |
59 |
Correct |
103 ms |
31048 KB |
Output is correct |
60 |
Correct |
113 ms |
30600 KB |
Output is correct |
61 |
Correct |
116 ms |
30604 KB |
Output is correct |
62 |
Correct |
112 ms |
30856 KB |
Output is correct |
63 |
Correct |
92 ms |
28336 KB |
Output is correct |
64 |
Correct |
93 ms |
24828 KB |
Output is correct |