QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#274096 | #5075. Fenwick Tree | xhgua | WA | 80ms | 3628kb | C++14 | 1.0kb | 2023-12-03 09:35:44 | 2023-12-03 09:35:44 |
Judging History
answer
#include <array>
#include <vector>
#include <iostream>
using i64 = long long;
void solve() {
int n;
std::cin >> n;
std::vector<int> a(n + 1);
for (int i = 1; i <= n; i++) {
char ch; std::cin >> ch;
a[i] = (ch - '0');
}
std::array<std::vector<int>, 31> pos;
for (int i = 1; i <= n; i++) pos[std::__lg(i & -i)].push_back(i);
std::vector<int> b(n + 1, 0); int ans = 0;
for (int i = 1; i <= n; i += 2) if (a[i] == 1) b[i] = 1, ans++;
for (int lowbit = 1; lowbit < 31; lowbit++) {
std::vector<int> sum(n + 1, 0);
for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];
for (auto x : pos[lowbit]) {
if (a[x] == 0 && sum[x] - sum[x - (x & -x)] != 0) {
b[x] = sum[x - (x & -x)] - sum[x];
ans++;
}
if (a[x] == 1 && sum[x] - sum[x - (x & -x)] == 0) {
b[x] = 1;
ans++;
}
}
}
std::cout << ans << "\n";
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int T;
std::cin >> T;
while (T--) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3628kb
input:
3 5 10110 5 00000 5 11111
output:
3 0 3
result:
ok 3 number(s): "3 0 3"
Test #2:
score: -100
Wrong Answer
time: 80ms
memory: 3564kb
input:
100000 10 0000000000 10 0000000100 10 0000000000 10 1000000000 10 0000010000 10 0000000000 10 0000000000 10 0000000000 10 0100000000 10 0000000000 10 0000000001 10 0000001000 10 0000000000 10 0000000000 10 0000000001 10 0000100000 10 0010000000 10 0000000000 10 0010000000 10 0000000001 10 0000000000...
output:
0 0 0 4 1 0 0 0 2 0 0 2 0 0 0 3 3 0 3 0 0 0 2 2 3 0 1 3 2 0 3 2 0 0 4 2 0 0 2 0 2 2 0 0 0 0 0 0 0 1 3 3 1 0 0 0 2 1 0 1 2 0 2 4 0 0 0 1 0 0 3 2 0 0 0 0 2 0 1 0 0 0 0 1 2 0 0 0 0 0 0 2 0 2 1 0 3 4 2 0 0 0 0 0 0 0 0 0 0 0 4 0 2 0 0 0 1 0 2 0 0 2 0 0 0 0 0 0 0 2 0 0 1 0 2 0 0 2 0 3 0 0 0 2 0 0 2 3 0 0 ...
result:
wrong answer 2nd numbers differ - expected: '1', found: '0'