QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#555954 | #9240. Mosaic | A_programmer | 5 | 74ms | 27164kb | C++20 | 2.3kb | 2024-09-10 13:07:01 | 2024-09-10 13:07:01 |
Judging History
answer
#include "mosaic.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const int maxn = 2e5 + 5;
const int N = 4e5 + 5;
int n, q, len;
bool rw[maxn][4], cl[maxn][4], arr[N];
int pr[maxn][4], pc[maxn][4], sum[N];
ll sum2[N];
ll calc(int l, int r) { return sum2[r] - sum2[l - 1] - 1ll * (l - 1) * (sum[r] - sum[l - 1]); }
vector<ll> mosaic(vi X, vi Y, vi T, vi B, vi L, vi R)
{
n = X.size(), q = T.size();
X.resize(n + 1), Y.resize(n + 1);
for (int i = n; i; i--) X[i] = X[i - 1]; X[0] = 0;
for (int i = n; i; i--) Y[i] = Y[i - 1]; Y[0] = 0;
if (n <= 2)
{
vector<ll> res; res.resize(q);
for (int Q = 0; Q < q; Q++)
{
int l = L[Q] + 1, r = R[Q] + 1, x = T[Q] + 1, y = B[Q] + 1; ll ans = 0;
for (int i = x; i <= y; i++)
for (int j = l; j <= r; j++)
if (i == 1 && j == 1) ans += X[1];
else if (i == 2 && j == 2) ans += (!X[2] && !Y[2]);
else ans += (i == 2 ? Y[2] : X[2]);
res[Q] = ans;
}
return res;
}
for (int i = 1; i <= n; i++) rw[i][1] = Y[i], cl[i][1] = X[i];
rw[1][2] = X[2], cl[1][2] = Y[2]; rw[1][3] = X[3], cl[1][3] = Y[3];
for (int j = 2; j <= 3; j++)
for (int i = 2; i <= n; i++) rw[i][j] = !rw[i - 1][j] && !rw[i][j - 1], cl[i][j] = !cl[i - 1][j] && !cl[i][j - 1];
for (int j = 1; j <= 3; j++)
for (int i = 1; i <= n; i++) pr[i][j] = pr[i - 1][j] + rw[i][j], pc[i][j] = pc[i - 1][j] + cl[i][j];
int len = 2 * n - 5;
for (int i = 1; i <= n - 2; i++) arr[i] = rw[n - i + 1][3];
for (int i = n - 1; i <= len; i++) arr[i] = cl[i - (n - 5)][3];
for (int i = 1; i <= len; i++) sum[i] = sum[i - 1] + arr[i], sum2[i] = sum2[i - 1] + (arr[i] ? i : 0);
vector<ll> res; res.resize(q);
for (int Q = 0; Q < q; Q++)
{
int l = L[Q] + 1, r = R[Q] + 1, x = T[Q] + 1, y = B[Q] + 1; ll ans = 0;
for (int i = x; i <= 2; i++) ans += pc[r][i] - pc[l - 1][i];
if (y <= 2) { res[Q] = ans; continue; }
for (int i = l; i <= 2; i++) ans += pr[y][i] - pr[2][i];
if (r <= 2) { res[Q] = ans; continue; }
l = max(l, 3), x = max(x, 3);
int p1 = l - y + n - 2, p2 = l - x + n - 2, p3 = r - y + n - 2, p4 = r - x + n - 2, dis = min(r - l, y - x);
if (p2 > p3) swap(p2, p3);
ans += 1ll * (sum[p3 - 1] - sum[p2]) * dis;
ans += calc(p1, p2) + 1ll * (dis + 1) * (sum[p4] - sum[p3 - 1]) - calc(p3, p4);
res[Q] = ans;
}
return res;
}
詳細信息
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 0ms
memory: 3872kb
input:
njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq 1 0 0 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
output:
Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9 OK 0 0 0 0 0 0 0 0 0 0
result:
ok
Test #2:
score: 5
Accepted
time: 0ms
memory: 3776kb
input:
njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq 1 1 1 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
output:
Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9 OK 1 1 1 1 1 1 1 1 1 1
result:
ok
Test #3:
score: 5
Accepted
time: 0ms
memory: 4080kb
input:
njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq 2 1 0 1 0 10 1 1 0 1 1 1 0 1 0 0 0 0 0 1 0 1 0 1 0 1 1 1 0 0 0 1 0 1 0 1 1 1 1 1 0 1 0 0 0 1
output:
Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9 OK 1 1 1 2 2 0 2 1 1 1
result:
ok
Test #4:
score: 5
Accepted
time: 0ms
memory: 3860kb
input:
njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq 2 1 0 1 0 10 0 1 1 1 0 1 0 1 0 1 0 0 1 1 0 1 0 1 0 1 0 1 0 0 1 1 1 1 0 0 0 1 0 1 0 0 1 1 0 0
output:
Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9 OK 1 2 1 1 2 1 1 1 1 0
result:
ok
Test #5:
score: 5
Accepted
time: 0ms
memory: 3856kb
input:
njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq 2 0 1 0 0 10 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 1 1 1 0 1 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1
output:
Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9 OK 0 1 0 0 0 0 1 1 1 1
result:
ok
Test #6:
score: 5
Accepted
time: 0ms
memory: 3776kb
input:
njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq 2 1 1 1 0 10 0 0 0 1 0 0 0 1 1 1 0 1 0 1 0 1 0 1 0 0 0 1 1 1 1 1 0 1 0 0 1 1 0 1 0 0 0 1 0 0
output:
Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9 OK 2 2 0 2 1 1 0 1 1 1
result:
ok
Test #7:
score: 5
Accepted
time: 0ms
memory: 4080kb
input:
njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq 2 0 0 0 1 10 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 0 0 1 1 0 0 0 1 0 1 0 0 1 1 0 1 1 1 0 1
output:
Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9 OK 0 1 1 1 0 0 0 1 1 1
result:
ok
Test #8:
score: 5
Accepted
time: 0ms
memory: 3872kb
input:
njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq 2 1 0 1 1 10 0 1 0 0 1 1 0 1 0 0 0 1 1 1 1 1 1 1 0 0 0 1 1 1 0 1 0 0 0 0 1 1 1 1 0 1 0 1 0 1
output:
Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9 OK 2 1 1 0 1 0 2 0 1 2
result:
ok
Test #9:
score: 5
Accepted
time: 0ms
memory: 3780kb
input:
njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq 2 0 1 0 1 10 0 1 0 1 0 1 0 1 1 1 1 1 0 1 0 1 0 0 1 1 0 1 0 1 0 1 1 1 0 0 0 0 0 1 0 0 0 1 0 1
output:
Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9 OK 2 2 0 2 1 2 1 0 1 2
result:
ok
Test #10:
score: 5
Accepted
time: 0ms
memory: 3780kb
input:
njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq 2 1 1 1 1 10 0 0 0 1 0 1 0 0 0 1 0 0 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 1 0 1 1 1 0 1 0 1 1 1 1 1
output:
Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9 OK 2 2 2 3 1 3 3 1 3 0
result:
ok
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #11:
score: 0
Wrong Answer
time: 0ms
memory: 5936kb
input:
njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq 199 0 0 1 0 0 1 0 0 0 1 0 0 1 1 1 0 1 0 1 1 1 1 0 1 0 1 1 1 0 0 1 1 0 1 1 0 0 1 1 0 1 0 1 1 0 1 0 0 1 0 1 0 1 1 1 1 0 0 1 1 1 1 0 1 1 0 0 1 0 1 1 1 1 1 1 0 0 0 1 0 0 1 0 0 0 0 0 1 0 0 1 0 0 1 0 0 1 1 1 0 0 0 1 1 1 0 0 1 1 1 0 1 1 1 0 1 0 1 0 1 0 1 1 0 1 0 1 0 0 0 0 1...
output:
Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9 OK 1055 5015 874 412 10311 1226 1700 4257 682 1822 30 408 674 5618 5245 606 1 7 181 378 3011 59 4022 43 1331 1177 75 1399 1044 4980 5492 2635 52 2495 1046 0 3648 1964 311 2740 402 1489 515 1578 731 5205 1895 1859 229 3481 1945 4315 903 1464 1928 1783 38 9781 1216 323...
result:
wrong answer 3rd lines differ - on the 1st token, expected: '1078', found: '1055'
Subtask #3:
score: 0
Wrong Answer
Test #18:
score: 0
Wrong Answer
time: 59ms
memory: 26952kb
input:
njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq 199999 0 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 0 0 0 1 0 0 0 0 1 1 1 0 1 0 0 0 1 0 1 1 0 1 1 1 0 1 0 0 1 1 0 1 1 0 0 0 1 1 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 1 0 1 1 1 1 1 0 0 0 1 0 0 0 0 1 0 0 0 1 1 1 1 0 1 0 1 1 1 0 1 0 1 0 0 0 1 1 1 1 0 0 0 1 1 1 1 0 1 0 1 1 0 0 0 0 ...
output:
Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9 OK 2210 132110 22036 105836 45191 144168 35165 88467 24088 23177 109895 111508 22254 39828 61771 94346 116336 108213 123502 69557 84505 2297 108812 97420 40575 97235 48897 98655 64973 8246 100817 38957 100565 21387 42808 13584 28336 93597 18163 12068 50319 122693 926...
result:
wrong answer 3rd lines differ - on the 1st token, expected: '1314', found: '2210'
Subtask #4:
score: 0
Skipped
Dependency #2:
0%
Subtask #5:
score: 0
Wrong Answer
Test #31:
score: 0
Wrong Answer
time: 30ms
memory: 13132kb
input:
njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 200000 1 7 0 4 3 4 3 4 3 6 2 5 4 5 6 7 5 7 2 8 0 6 4 7 0 5 6 7 1 3 9 9 6 9 1 7 2 9 4 6 4 4 6 7 0 1 8 8 7 7 0 3 0 4 1 7 2 2 0 9 3 9 4 6 3 9 0 9 1 8 4 6 4 5 5 7 0 6 2 3 2 3 0 6 1 9 8 8 2 4 3 4 3 6 2 9 3 9 2 7 1 3 0 3 0 8 2 4 3...
output:
Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9 OK 11 2 6 2 7 10 4 2 14 8 1 0 3 12 1 7 28 9 2 4 4 0 2 12 18 5 9 5 4 8 9 0 6 2 6 12 4 3 5 7 13 22 1 3 8 6 12 2 0 9 3 5 19 0 0 4 4 0 1 3 1 0 5 5 16 29 8 1 4 5 2 9 8 4 3 3 8 5 0 13 7 12 5 1 2 6 18 3 2 2 3 12 18 11 7 1 2 1 1 13 17 4 1 5 1 13 13 8 33 8 4 4 6 7 10 2 5 3 19...
result:
wrong answer 3rd lines differ - on the 1st token, expected: '14', found: '11'
Subtask #6:
score: 0
Wrong Answer
Test #42:
score: 0
Wrong Answer
time: 74ms
memory: 27164kb
input:
njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq 199999 0 1 0 0 0 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 0 0 0 1 1 0 1 0 1 1 0 0 1 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 1 0 0 1 1 1 1 1 0 1 1 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1 1 1 0 0 1 1 1 1 0 1 0 0 0 0 0 1 1 1 0 1 1 0 1 1 0 0 1 1 0 0 0 0 1 0 1 ...
output:
Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9 OK 0 1 0 1 0 1 0 0 1 1 1 1 0 1 0 1 1 1 0 0 1 1 1 0 0 1 0 0 0 1 0 0 1 0 1 0 1 1 1 1 1 0 1 0 0 0 0 1 1 0 1 0 0 0 1 0 0 0 0 1 0 1 0 0 0 0 1 0 0 0 0 1 0 1 0 1 0 0 0 1 0 0 1 0 0 0 0 0 1 0 1 0 0 1 0 1 1 0 1 1 1 1 1 0 0 1 0 0 1 0 0 1 0 0 0 0 0 1 1 1 0 1 1 1 0 1 0 1 0 1 0 1 ...
result:
wrong answer 116933rd lines differ - on the 1st token, expected: '0', found: '4950'
Subtask #7:
score: 0
Skipped
Dependency #3:
0%
Subtask #8:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%