QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#694387#5075. Fenwick TreeyangylWA 16ms3852kbC++20831b2024-10-31 17:50:452024-10-31 17:50:46

Judging History

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

  • [2024-10-31 17:50:46]
  • 评测
  • 测评结果:WA
  • 用时:16ms
  • 内存:3852kb
  • [2024-10-31 17:50:45]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define endl "\n"
using ll = long long;

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

	string s;
	cin >> s;
	vector<int> tr(n + 1);
	auto add = [&](int x, int v) {
		for (int i = x; i <= n; i += i & -i) {
			tr[i] += v;
		}
	};
	auto query = [&](int x) {
		int res = 0;
		for (int i = x; i; i -= i & -i) {
			res += tr[i];
		}
		return res;
	};

	ll ans = 0;
	for (int i = 0; i < n; i++) {
		int v = tr[i + 1];
		if (v > 0 && s[i] != '0') continue;
		if (v == 0 && s[i] != '0') {
			ans++;
			add(i + 1, 1);
		} else if (v > 0 && s[i] == '0') {
			ans += v;
			add(i + 1, -v);
		}
	}
	cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(0);

    int t;
    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: 3556kb

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: 14ms
memory: 3572kb

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: 16ms
memory: 3852kb

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

result:

wrong answer 2nd numbers differ - expected: '4', found: '6'