# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1105033 |
2024-10-25T08:05:53 Z |
flashmt |
Mosaic (IOI24_mosaic) |
C++17 |
|
193 ms |
52668 KB |
#include "mosaic.h"
#include <bits/stdc++.h>
using namespace std;
vector<long long> mosaic(
vector<int> X, vector<int> Y,
vector<int> T, vector<int> B,
vector<int> L, vector<int> R
) {
int n = size(X);
vector<vector<int>> a(n);
a[0] = X;
for (int i = 1; i < n; i++)
{
int len = i < 3 ? n : 3;
a[i].resize(len);
a[i][0] = Y[i];
for (int j = 1; j < len; j++)
a[i][j] = (a[i - 1][j] | a[i][j - 1]) ^ 1;
}
vector<vector<long long>> s(n);
for (int i = 0; i < n; i++)
{
int len = i < 3 ? n : 3;
s[i].resize(len);
s[i][0] = a[i][0];
if (i)
s[i][0] += s[i - 1][0];
for (int j = 1; j < len; j++)
{
s[i][j] = s[i][j - 1] + a[i][j];
if (i)
s[i][j] += s[i - 1][j] - s[i - 1][j - 1];
}
}
vector<long long> sumRow(n), sumCol(n), cntRow(n), cntCol(n);
for (int i = 2; i < n; i++)
{
sumRow[i] = sumRow[i - 1] + (a[2][i] ? i : 0);
cntRow[i] = cntRow[i - 1] + a[2][i];
sumCol[i] = sumCol[i - 1] + (a[i][2] ? i : 0);
cntCol[i] = cntCol[i - 1] + a[i][2];
}
auto getColTriangle = [&](int x, int xx)
{
return 1LL * xx * (cntCol[xx - 1] - cntCol[x - 2]) - (sumCol[xx - 1] - sumCol[x - 2]);
};
auto getRowTriangle = [&](int y, int yy)
{
return 1LL * yy * (cntRow[yy - 1] - cntRow[y - 2]) - (sumRow[yy - 1] - sumRow[y - 2]);
};
auto get = [&](int x, int y)
{
if (x < 0 || y < 0)
return 0LL;
if (x < 3 || y < 3)
return s[x][y];
long long res = s[2][y] + s[x][2] - s[2][2];
if (x <= y)
{
if (x >= 4)
res += getColTriangle(4, x);
res += getRowTriangle(y - (x - 3), y);
res += (cntRow[y - (x - 1)] - cntRow[1]) * (x - 2);
}
else
{
if (y >= 4)
res += getRowTriangle(4, y);
res += getColTriangle(x - (y - 3), x);
res += (cntCol[x - (y - 1)] - cntCol[1]) * (y - 2);
}
return res;
};
int q = size(T);
vector<long long> ans(q);
for (int i = 0; i < q; i++)
{
ans[i] = get(B[i], R[i]) + get(T[i] - 1, L[i] - 1);
ans[i] -= get(B[i], L[i] - 1) + get(T[i] - 1, R[i]);
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
436 KB |
Output is correct |
5 |
Correct |
1 ms |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
436 KB |
Output is correct |
5 |
Correct |
1 ms |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
114 ms |
50512 KB |
Output is correct |
2 |
Correct |
112 ms |
50504 KB |
Output is correct |
3 |
Correct |
123 ms |
49792 KB |
Output is correct |
4 |
Correct |
115 ms |
50432 KB |
Output is correct |
5 |
Correct |
81 ms |
30792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
436 KB |
Output is correct |
5 |
Correct |
1 ms |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
67 ms |
12872 KB |
Output is correct |
19 |
Correct |
65 ms |
12616 KB |
Output is correct |
20 |
Correct |
65 ms |
12360 KB |
Output is correct |
21 |
Correct |
65 ms |
12360 KB |
Output is correct |
22 |
Correct |
64 ms |
12372 KB |
Output is correct |
23 |
Correct |
65 ms |
11892 KB |
Output is correct |
24 |
Correct |
62 ms |
12104 KB |
Output is correct |
25 |
Correct |
69 ms |
12104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
9556 KB |
Output is correct |
2 |
Correct |
155 ms |
52296 KB |
Output is correct |
3 |
Correct |
144 ms |
51712 KB |
Output is correct |
4 |
Correct |
141 ms |
51528 KB |
Output is correct |
5 |
Correct |
128 ms |
51984 KB |
Output is correct |
6 |
Correct |
135 ms |
52296 KB |
Output is correct |
7 |
Correct |
165 ms |
52308 KB |
Output is correct |
8 |
Correct |
157 ms |
52220 KB |
Output is correct |
9 |
Correct |
118 ms |
31972 KB |
Output is correct |
10 |
Correct |
98 ms |
31980 KB |
Output is correct |
11 |
Correct |
100 ms |
32104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
134 ms |
52296 KB |
Output is correct |
2 |
Correct |
154 ms |
52296 KB |
Output is correct |
3 |
Correct |
117 ms |
50700 KB |
Output is correct |
4 |
Correct |
134 ms |
50760 KB |
Output is correct |
5 |
Correct |
122 ms |
52668 KB |
Output is correct |
6 |
Correct |
104 ms |
32504 KB |
Output is correct |
7 |
Correct |
94 ms |
23892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
114 ms |
50512 KB |
Output is correct |
2 |
Correct |
112 ms |
50504 KB |
Output is correct |
3 |
Correct |
123 ms |
49792 KB |
Output is correct |
4 |
Correct |
115 ms |
50432 KB |
Output is correct |
5 |
Correct |
81 ms |
30792 KB |
Output is correct |
6 |
Correct |
134 ms |
52296 KB |
Output is correct |
7 |
Correct |
154 ms |
52296 KB |
Output is correct |
8 |
Correct |
117 ms |
50700 KB |
Output is correct |
9 |
Correct |
134 ms |
50760 KB |
Output is correct |
10 |
Correct |
122 ms |
52668 KB |
Output is correct |
11 |
Correct |
104 ms |
32504 KB |
Output is correct |
12 |
Correct |
94 ms |
23892 KB |
Output is correct |
13 |
Correct |
160 ms |
52296 KB |
Output is correct |
14 |
Correct |
163 ms |
52408 KB |
Output is correct |
15 |
Correct |
142 ms |
52552 KB |
Output is correct |
16 |
Correct |
129 ms |
50888 KB |
Output is correct |
17 |
Correct |
144 ms |
51852 KB |
Output is correct |
18 |
Correct |
140 ms |
52296 KB |
Output is correct |
19 |
Correct |
107 ms |
27960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
1 ms |
436 KB |
Output is correct |
6 |
Correct |
1 ms |
504 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
114 ms |
50512 KB |
Output is correct |
20 |
Correct |
112 ms |
50504 KB |
Output is correct |
21 |
Correct |
123 ms |
49792 KB |
Output is correct |
22 |
Correct |
115 ms |
50432 KB |
Output is correct |
23 |
Correct |
81 ms |
30792 KB |
Output is correct |
24 |
Correct |
67 ms |
12872 KB |
Output is correct |
25 |
Correct |
65 ms |
12616 KB |
Output is correct |
26 |
Correct |
65 ms |
12360 KB |
Output is correct |
27 |
Correct |
65 ms |
12360 KB |
Output is correct |
28 |
Correct |
64 ms |
12372 KB |
Output is correct |
29 |
Correct |
65 ms |
11892 KB |
Output is correct |
30 |
Correct |
62 ms |
12104 KB |
Output is correct |
31 |
Correct |
69 ms |
12104 KB |
Output is correct |
32 |
Correct |
50 ms |
9556 KB |
Output is correct |
33 |
Correct |
155 ms |
52296 KB |
Output is correct |
34 |
Correct |
144 ms |
51712 KB |
Output is correct |
35 |
Correct |
141 ms |
51528 KB |
Output is correct |
36 |
Correct |
128 ms |
51984 KB |
Output is correct |
37 |
Correct |
135 ms |
52296 KB |
Output is correct |
38 |
Correct |
165 ms |
52308 KB |
Output is correct |
39 |
Correct |
157 ms |
52220 KB |
Output is correct |
40 |
Correct |
118 ms |
31972 KB |
Output is correct |
41 |
Correct |
98 ms |
31980 KB |
Output is correct |
42 |
Correct |
100 ms |
32104 KB |
Output is correct |
43 |
Correct |
134 ms |
52296 KB |
Output is correct |
44 |
Correct |
154 ms |
52296 KB |
Output is correct |
45 |
Correct |
117 ms |
50700 KB |
Output is correct |
46 |
Correct |
134 ms |
50760 KB |
Output is correct |
47 |
Correct |
122 ms |
52668 KB |
Output is correct |
48 |
Correct |
104 ms |
32504 KB |
Output is correct |
49 |
Correct |
94 ms |
23892 KB |
Output is correct |
50 |
Correct |
160 ms |
52296 KB |
Output is correct |
51 |
Correct |
163 ms |
52408 KB |
Output is correct |
52 |
Correct |
142 ms |
52552 KB |
Output is correct |
53 |
Correct |
129 ms |
50888 KB |
Output is correct |
54 |
Correct |
144 ms |
51852 KB |
Output is correct |
55 |
Correct |
140 ms |
52296 KB |
Output is correct |
56 |
Correct |
107 ms |
27960 KB |
Output is correct |
57 |
Correct |
168 ms |
52296 KB |
Output is correct |
58 |
Correct |
161 ms |
52032 KB |
Output is correct |
59 |
Correct |
193 ms |
52292 KB |
Output is correct |
60 |
Correct |
166 ms |
51784 KB |
Output is correct |
61 |
Correct |
167 ms |
51532 KB |
Output is correct |
62 |
Correct |
146 ms |
52040 KB |
Output is correct |
63 |
Correct |
115 ms |
32336 KB |
Output is correct |
64 |
Correct |
99 ms |
22600 KB |
Output is correct |