QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#848709 | #9915. General Symmetry | hhoppitree | WA | 1ms | 8032kb | C++23 | 1.6kb | 2025-01-09 08:48:32 | 2025-01-09 08:48:32 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, V = 1005;
bitset<N> f[2005], g[V];
int a[N];
signed main() {
int n, m; scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
for (int j = max(a[i] - m, 1); j <= min(a[i] + m, 1000); ++j) g[j][i] = 1;
}
bitset<N> now, tf;
for (int i = 1; i <= n; ++i) {
now = 1;
tf = (tf >> 1) & g[a[i]];
tf[i] = 1;
if (i && abs(a[i] - a[i - 1]) <= m) tf[i - 1] = 1;
tf &= now;
if (i % 1000 == 0) f[i / 1000] = tf;
}
auto check = [&](int l, int r) {
int p = r / 1000 * 1000;
++p;
if (p * 1000 > n) return 0;
return (int)f[p][l - (p * 1000 - r)];
};
for (int i = 1; i <= n; ++i) {
int L = 1, R = min(i - 1, n - i), res = 0;
while (L <= R) {
int mid = (L + R) >> 1;
if (check(i - mid, i + mid)) res = mid, L = mid + 1;
else R = mid - 1;
}
while (res < min(i - 1, n - i) && abs(a[i + res] - a[i - res]) <= m) ++res;
printf("%d%c", res * 2 + 1, " \n"[i == n]);
}
for (int i = 1; i < n; ++i) {
int L = 1, R = min(i, n - i), res = 0;
while (L <= R) {
int mid = (L + R) >> 1;
if (check(i - mid + 1, i + mid)) res = mid, L = mid + 1;
else R = mid - 1;
}
while (res < min(i, n - i) && abs(a[i + res + 1] - a[i - res]) <= m) ++res;
printf("%d%c", res * 2, " \n"[i == n - 1]);
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3988kb
input:
5 0 1 2 1 2 1
output:
1 3 5 3 1 0 0 0 0
result:
ok 9 numbers
Test #2:
score: 0
Accepted
time: 0ms
memory: 6084kb
input:
5 1 1 2 1 3 1
output:
1 3 5 3 1 2 2 0 0
result:
ok 9 numbers
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 8032kb
input:
10 0 1 2 3 4 500 5 501 6 499 503
output:
1 3 3 3 3 3 3 3 3 1 0 0 0 0 0 0 0 0 0
result:
wrong answer 2nd numbers differ - expected: '1', found: '3'