QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#569251 | #7877. Balanced Array | heige# | WA | 1ms | 5928kb | C++23 | 2.3kb | 2024-09-16 21:30:50 | 2024-09-16 21:30:50 |
Judging History
answer
#include <bits/stdc++.h>
// #define int int64_t
using u64 = uint64_t;
const int kMaxN = 2e6 + 5;
const u64 kBase1 = 13331, kBase2 = 12347;
int n;
int a[kMaxN], cnt[kMaxN];
u64 hs1[kMaxN], hs2[kMaxN], pw1[kMaxN], pw2[kMaxN];
u64 gethash1(int l, int r) { return hs1[r] - hs1[l - 1] * pw1[r - l + 1]; }
u64 gethash2(int l, int r) { return hs2[r] - hs2[l - 1] * pw2[r - l + 1]; }
void prework() {
pw1[0] = pw2[0] = 1;
for (int i = 1; i <= n; ++i) {
pw1[i] = kBase1 * pw1[i - 1];
pw2[i] = kBase2 * pw2[i - 1];
hs1[i] = kBase1 * hs1[i - 1] + a[i];
hs2[i] = kBase2 * hs2[i - 1] + a[i];
}
}
void dickdreamer() {
std::cin >> n;
for (int i = 1; i <= n; ++i) {
std::string str;
std::cin >> str;
for (auto c : str) {
if (c >= '0' && c <= '9')
a[i] = 62 * a[i] + c - '0';
else if (c >= 'a' && c <= 'z')
a[i] = 62 * a[i] + c - 'a' + 10;
else
a[i] = 62 * a[i] + c - 'A' + 36;
}
}
prework();
for (int i = 1; i <= (n - 1) / 2; ++i) {
for (int j = 2 * i + 1; j <= n; j += i) {
if (j + i - 1 <= n &&
gethash1(j, j + i - 1) + gethash1(j - 2 * i, j - i - 1) ==
2ull * gethash1(j - i, j - 1) &&
gethash2(j, j + i - 1) + gethash2(j - 2 * i, j - i - 1) ==
2ull * gethash2(j - i, j - 1)) {
++cnt[j], --cnt[j + i];
} else {
int L = j - 1, R = std::min(j + i - 1, n) + 1, res = j - 1;
while (L + 1 < R) {
int mid = (L + R) >> 1;
if (gethash1(j, mid) + gethash1(j - 2 * i, mid - 2 * i) ==
2ull * gethash1(j - i, mid - i) &&
gethash2(j, mid) + gethash2(j - 2 * i, mid - 2 * i) ==
2ull * gethash2(j - i, mid - i))
L = res = mid;
else
R = mid;
}
++cnt[j], --cnt[res + 1];
}
}
}
for (int i = 1; i <= n; ++i) {
cnt[i] += cnt[i - 1];
std::cout << (bool)cnt[i];
}
}
int32_t main() {
#ifdef ORZXKR
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
std::ios::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0);
int T = 1;
// std::cin >> T;
while (T--) dickdreamer();
// std::cerr << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5616kb
input:
3 1 2 3
output:
001
result:
ok single line: '001'
Test #2:
score: 0
Accepted
time: 1ms
memory: 5876kb
input:
9 1 2 3 2 5 4 3 8 5
output:
001010111
result:
ok single line: '001010111'
Test #3:
score: 0
Accepted
time: 1ms
memory: 5840kb
input:
9 1C 3f 4S 3h 88 6x 4W d1 8c
output:
001010111
result:
ok single line: '001010111'
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 5928kb
input:
49 71FjQ 71FzG 71FjR 71FjG 71FjS 71F3G 71FjT 71ENG 71FjU 71ExG 71FzG 71Fko 71FjW 71FOM 71FPm 71FzG 71FPO 71FP9 71FzG 71Fkc 71FzG 7AXBr 71FPH 8nKLh 71Fk2 71FzG 71FkK 4AGIE 71Fk9 6EfCL 71FPN 71FjJ 71FPb 7H3TC 71Gks 71FzG 71FPI 71FzG 6Oayg 71FPc 71FPw 71FPN 71Fkm 71FPK 71FPK 6Az4J 71FPI 71FzG 71Fke
output:
0000111111001000000010001100000000110000100000001
result:
wrong answer 1st lines differ - expected: '0000111111001000000000001000000000110000100000001', found: '0000111111001000000010001100000000110000100000001'