QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#185706 | #5075. Fenwick Tree | linzi# | WA | 1ms | 7764kb | C++17 | 821b | 2023-09-22 15:26:19 | 2023-09-22 15:26:20 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define inf 1e18
#define mn 1000005
using namespace std;
ll a[mn],c[mn],bj[mn],ans,n,m;
string s;
inline ll low(ll x)
{
return (x & (-x));
}
void add(ll pos,ll val,ll bjj)
{
while (pos <= n)
{
c[pos]+=val;
if(bjj==0)bj[pos]=0;
else bj[pos]+=bjj;
pos += pos & (-pos);
}
}
ll cal(ll i)
{
if(c[i]&&a[i]==0)return -c[i];
return 0;
}
int main()
{
ll t,x,y,z,i,j,k;
cin>>t;
while(t--)
{
scanf("%lld",&n);
cin>>s;
for(i=1;i<=n;i++)
{
a[i]=s[i-1]-'0';
c[i]=bj[i]=0;
}
ans=0;
for(i=1;i<=n;i++)
if((c[i]&&a[i])||(c[i]==0&&a[i]==0))continue;
else if(a[i]&&c[i]==0)
{
add(i,1,1);
ans++;
}
else {
if(bj[i]<1)ans++;
add(i,-c[i],0);
}
printf("%lld\n",ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 7764kb
input:
3 5 10110 5 00000 5 11111
output:
2 0 3
result:
wrong answer 1st numbers differ - expected: '3', found: '2'