QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#290107 | #5075. Fenwick Tree | Remakee# | WA | 14ms | 3924kb | C++14 | 973b | 2023-12-24 13:29:20 | 2023-12-24 13:29:20 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
int x=0,f=1;
char ch=getchar();
while(!isdigit(ch))
{
if(ch=='-') f=-1;
ch=getchar();
}
while(isdigit(ch))
{
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
const int N=1e5+10;
int T,n,ans;
char str[N];
namespace BIT
{
int vis[N];
#define lowbit(x) ((x)&(-x))
inline void Add(int x,int v)
{
for(x;x<=n;x+=lowbit(x)) vis[x]+=v;
}
}
using namespace BIT;
int main()
{
T=read();
while(T--)
{
n=read();
for(int i=1;i<=n;i++) vis[i]=0;
scanf("%s",str+1);
int ans=0;
for(int i=1;i<=n;i++)
{
if(str[i]=='1'&&!vis[i]) Add(i,1),ans++;
if(str[i]=='0'&&vis[i]==1) Add(i,-1),ans++;
if(str[i]=='0'&&vis[i]>1) Add(i,-vis[i]);
}
printf("%d\n",ans);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3880kb
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: 12ms
memory: 3924kb
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: 14ms
memory: 3832kb
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 4 4 3 5 4 2 3 6 7 3 0 5 6 6 3 4 4 3 3 4 2 4 0 3 3 2 2 0 4 2 2 2 2 4 4 2 2 5 5 2 3 0 4 2 6 6 3 3 0 4 5 4 2 0 6 4 7 3 0 2 2 2 1 4 2 2 5 3 0 4 0 0 4 5 0 0 2 5 3 2 4 1 0 2 4 3 2 1 2 2 2 4 2 5 3 3 1 2 4 0 0 2 5 4 2 4 0 5 7 5 2 7 3 2 4 4 5 0 3 4 4 2 2 0 4 2 0 4 4 9 2 2 5 6 2 6 4 2 0 5 2 1 2 4 6 6 0 2 1 ...
result:
wrong answer 1075th numbers differ - expected: '5', found: '4'