QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#290188 | #5075. Fenwick Tree | WilliamHu | WA | 0ms | 5620kb | C++20 | 1.1kb | 2023-12-24 15:29:11 | 2023-12-24 15:29:11 |
Judging History
answer
#include <bits/stdc++.h>
//#define int long long
using namespace std;
int n, T, a[1000010], b[1000010];
int read()
{
int x = 0, f = 1;
char c = getchar();
while(c != EOF and !isdigit(c))
{
if(c == '-')f = -1;
c = getchar();
}
while(isdigit(c))
{
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
int lowbit(int x){
return x & (-x);
}
string s;
signed main()
{
T = read();
while(T --)
{
n = read();
int cnt = 0;
cin>>s;
for(int i = 1;i <= n;i ++)
{
a[i] = s[i - 1] - '0';
}
for(int i = 1;i <= n;i ++)
{
if(a[i] == 1)
{
int x = i;
while(x <= n)
{
//cout<<x<<' '<<a[x]<<endl;
if(a[x])a[x] = 2;
else b[x] ++;
x += lowbit(x);
}
cnt ++;
}
}
for(int i = 1;i <= n;i ++)
{
if(b[i])
{
int x = i, y = b[i];
while(x <= n)
{
// cout<<x<<' '<<y<<endl;
b[x] -= y;
x += lowbit(x);
}
cnt ++;
}
}
cout<<cnt<<endl;
for(int i = 0;i <= n;i ++)a[i] = b[i] = 0;
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 5620kb
input:
3 5 10110 5 00000 5 11111
output:
4 0 3
result:
wrong answer 1st numbers differ - expected: '3', found: '4'