QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#290188#5075. Fenwick TreeWilliamHuWA 0ms5620kbC++201.1kb2023-12-24 15:29:112023-12-24 15:29:11

Judging History

你现在查看的是最新测评结果

  • [2023-12-24 15:29:11]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:5620kb
  • [2023-12-24 15:29:11]
  • 提交

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;
}


Details

Tip: Click on the bar to expand more detailed information

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'