QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#274096#5075. Fenwick TreexhguaWA 80ms3628kbC++141.0kb2023-12-03 09:35:442023-12-03 09:35:44

Judging History

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

  • [2023-12-03 09:35:44]
  • 评测
  • 测评结果:WA
  • 用时:80ms
  • 内存:3628kb
  • [2023-12-03 09:35:44]
  • 提交

answer

#include <array>
#include <vector>
#include <iostream>

using i64 = long long;

void solve() {
	int n;
	std::cin >> n;

	std::vector<int> a(n + 1);
	for (int i = 1; i <= n; i++) {
		char ch; std::cin >> ch;
		a[i] = (ch - '0');
	}

	std::array<std::vector<int>, 31> pos;
	for (int i = 1; i <= n; i++) pos[std::__lg(i & -i)].push_back(i);

	std::vector<int> b(n + 1, 0); int ans = 0;

	for (int i = 1; i <= n; i += 2) if (a[i] == 1) b[i] = 1, ans++;

	for (int lowbit = 1; lowbit < 31; lowbit++) {
		std::vector<int> sum(n + 1, 0);
		for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];

		for (auto x : pos[lowbit]) {
			if (a[x] == 0 && sum[x] - sum[x - (x & -x)] != 0) {
				b[x] = sum[x - (x & -x)] - sum[x];
				ans++;
			}

			if (a[x] == 1 && sum[x] - sum[x - (x & -x)] == 0) {
				b[x] = 1;
				ans++;
			}
		}
	}

	std::cout << ans << "\n";
}

int main() {

	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	int T;
	std::cin >> T;

	while (T--) solve();

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3628kb

input:

3
5
10110
5
00000
5
11111

output:

3
0
3

result:

ok 3 number(s): "3 0 3"

Test #2:

score: -100
Wrong Answer
time: 80ms
memory: 3564kb

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

result:

wrong answer 2nd numbers differ - expected: '1', found: '0'