QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#276016#5075. Fenwick TreezhaohaikunWA 18ms3548kbC++141.3kb2023-12-05 14:38:032023-12-05 14:38:05

Judging History

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

  • [2023-12-05 14:38:05]
  • 评测
  • 测评结果:WA
  • 用时:18ms
  • 内存:3548kb
  • [2023-12-05 14:38:03]
  • 提交

answer

// MagicDark
#include <bits/stdc++.h>
#define debug cerr << "[" << __LINE__ << "] "
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> inline void chkmax(T &x, T y) {x = max(x, y);}
template <typename T> inline void chkmin(T &x, T y) {x = min(x, y);}
template <typename T> inline void read(T &x) {
	x = 0; int f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	x *= f;
}
const int N = 1e5 + 10;
int n, t[N];
string st;
void add(int x, int y) {
	for (; x <= n; x += x & -x) t[x] += y;
}
int query(int x) {
	int s = 0;
	for (; x; x -= x & -x) s += t[x];
	return s;
}
void zhk() {
	cin >> n >> st; st = ' ' + st;
	int s = 0;
	F(i, 1, n) t[i] = 0;
	F(i, 1, n) {
		if (st[i] == '0') {
			if (t[i]) add(i, -t[i]), s++;
		} else {
			if (!t[i]) add(i, 1), s++;
		}
	}
	cout << s << '\n';
}
signed main() {
	cin.tie(0) -> sync_with_stdio(0);
	int _ = 1;
	cin >> _;
	while (_--) zhk();
	return 0;
}
/* why?
*/

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3548kb

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

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: 18ms
memory: 3448kb

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

result:

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