QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#600962 | #5075. Fenwick Tree | 333zhan | WA | 14ms | 3800kb | C++20 | 1.6kb | 2024-09-29 20:11:07 | 2024-09-29 20:11:10 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
struct BIT {
vector <int> tr;
int n;
BIT (int n_) {
n = n_;
tr.resize (n + 1);
}
int lowbit (int x) {
return x & -x;
}
void add (int x, int c) {
for (int i = x; i <= n; i += lowbit (i)) {
tr[i] += c;
}
}
int query (int x) {
if (x <= 0) {
return 0;
}
int ans = 0;
for (int i = x; i > 0; i -= lowbit (i)) {
ans += tr[i];
}
return ans;
}
int ask (int x) {
return query (x) - query (x - 1);
}
};
void solve () {
int n;
cin >> n;
string s;
cin >> s;
s = " " + s;
BIT bit (n);
int ans = 0;
for (int i = 1; i <= n; i ++) {
if (s[i] == '0') {
int t = bit.tr[i];
if (t == 1) {
ans ++;
bit.add (i, 1);
}
} else {
int t = bit.tr[i];
if (t == 0) {
ans ++;
bit.add (i, 1);
}
// if (t == 0) {
// ans ++;
// bit.add (i, 1);
// } else if (t % 2 == 0) {
// bit.add (i, 1);
// }
}
// cerr << i << " " << ans << '\n';
}
cout << ans << '\n';
}
signed main () {
ios::sync_with_stdio (false);
cin.tie (nullptr);
int T = 1;
cin >> T;
while (T --) {
solve ();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3800kb
input:
3 5 10110 5 00000 5 11111
output:
3 0 3
result:
ok 3 number(s): "3 0 3"
Test #2:
score: 0
Accepted
time: 14ms
memory: 3460kb
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 1 0 2 2 0 0 0 2 0 1 2 0 0 1 2 2 0 2 1 0 0 2 2 2 0 2 2 2 0 2 2 0 0 2 2 0 0 2 0 2 2 0 0 0 0 0 0 0 2 2 2 2 0 1 0 2 2 0 2 2 0 2 2 0 1 0 2 0 0 2 2 0 0 0 1 2 0 2 0 0 0 0 2 2 0 0 0 0 0 0 2 0 2 2 0 2 2 2 0 0 0 0 0 0 0 1 0 0 0 2 0 2 0 0 0 2 0 2 0 0 2 0 0 0 1 0 0 1 2 0 0 2 0 2 0 0 2 0 2 0 0 0 2 0 0 2 2 1 0 ...
result:
ok 100000 numbers
Test #3:
score: -100
Wrong Answer
time: 13ms
memory: 3580kb
input:
100000 10 0000001010 10 1110010000 10 0100010000 10 0001010011 10 0100001001 10 0010100000 10 0101000000 10 0100110100 10 1000001010 10 1000101001 10 1000000011 10 0000000000 10 0100011001 10 1000100101 10 0110101000 10 1000110100 10 0011100000 10 1001000000 10 0111001100 10 1100000100 10 1100110000...
output:
4 3 3 3 4 4 2 3 5 6 3 0 5 5 5 3 3 2 3 2 3 2 4 0 2 3 2 2 0 3 2 2 2 2 4 3 2 2 5 4 2 3 0 3 2 6 4 2 3 0 4 4 3 2 0 4 4 6 3 0 2 2 2 1 4 2 2 4 2 0 3 0 0 4 5 0 0 2 4 3 2 4 1 0 2 3 3 2 1 2 2 2 3 2 4 3 3 1 2 3 0 0 2 5 3 2 3 0 4 5 4 2 6 3 2 4 3 4 0 3 3 4 2 2 0 3 2 0 4 4 7 2 2 4 4 2 5 4 2 0 5 2 1 2 3 6 5 0 2 1 ...
result:
wrong answer 2nd numbers differ - expected: '4', found: '3'