QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#290196#5075. Fenwick TreeWilliamHuWA 47ms5740kbC++201.2kb2023-12-24 15:51:342023-12-24 15:51:34

Judging History

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

  • [2023-12-24 15:51:34]
  • 评测
  • 测评结果:WA
  • 用时:47ms
  • 内存:5740kb
  • [2023-12-24 15:51:34]
  • 提交

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])
			{
				if(b[i] > 1)
				{
					int x = i, y = b[i];
					while(x <= n)
					{
					//	cout<<x<<' '<<y<<endl;
						b[x] -= y;
						x += lowbit(x);
					}
					continue;
				}
				int x = i, y = b[i];
				while(x <= n)
				{
				//	cout<<x<<' '<<y<<endl;
					if(b[x])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: 100
Accepted
time: 0ms
memory: 5592kb

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: 47ms
memory: 5600kb

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: 47ms
memory: 5740kb

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
3
3
4
4
2
3
6
6
3
0
5
6
5
4
3
2
3
2
3
2
4
0
3
4
2
2
0
3
2
2
2
2
4
3
2
2
5
5
2
3
0
3
2
6
4
2
3
0
4
4
3
2
0
5
4
6
3
0
2
2
2
1
4
2
2
5
2
0
3
0
0
4
5
0
0
2
4
3
2
4
1
0
2
4
3
2
1
2
2
2
3
2
4
3
3
1
2
3
0
0
2
5
4
2
3
0
4
6
4
2
6
3
2
4
3
5
0
3
3
4
2
2
0
3
2
0
4
4
8
2
2
4
5
2
6
4
2
0
5
2
1
2
3
6
6
0
2
1
...

result:

wrong answer 3rd numbers differ - expected: '4', found: '3'