QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#569262 | #7877. Balanced Array | heige# | WA | 1ms | 7756kb | C++23 | 2.7kb | 2024-09-16 21:33:34 | 2024-09-16 21:33:35 |
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, kBase3 = 1333331;
int n;
int a[kMaxN], cnt[kMaxN];
u64 hs1[kMaxN], hs2[kMaxN], hs3[kMaxN], pw1[kMaxN], pw2[kMaxN], pw3[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]; }
u64 gethash3(int l, int r) { return hs3[r] - hs3[l - 1] * pw3[r - l + 1]; }
void prework() {
pw1[0] = pw2[0] = pw3[0] = 1;
for (int i = 1; i <= n; ++i) {
pw1[i] = kBase1 * pw1[i - 1];
pw2[i] = kBase2 * pw2[i - 1];
pw3[i] = kBase3 * pw3[i - 1];
hs1[i] = kBase1 * hs1[i - 1] + a[i];
hs2[i] = kBase2 * hs2[i - 1] + a[i];
hs3[i] = kBase3 * hs3[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) &&
gethash3(j, j + i - 1) + gethash3(j - 2 * i, j - i - 1) ==
2ull * gethash3(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) &&
gethash3(j, mid) + gethash3(j - 2 * i, mid - 2 * i) ==
2ull * gethash3(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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7692kb
input:
3 1 2 3
output:
001
result:
ok single line: '001'
Test #2:
score: 0
Accepted
time: 0ms
memory: 7748kb
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: 7688kb
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: 1ms
memory: 7756kb
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'