QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#185877#5075. Fenwick TreeykpcxWA 14ms3804kbC++17810b2023-09-22 18:20:082023-09-22 18:20:08

Judging History

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

  • [2023-09-22 18:20:08]
  • 评测
  • 测评结果:WA
  • 用时:14ms
  • 内存:3804kb
  • [2023-09-22 18:20:08]
  • 提交

answer

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <bitset>

using namespace std;
using ll = long long;
const int N = 1e5 + 5;

int n, a[N];

void solve() {
  cin >> n;
  string s; cin >> s;
  for (int i = 0; i < n; i++) {
    a[i+1] = s[i] - '0';
  }

  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (i & 1) {
      cnt += a[i];
      continue;
    }
    int t = 0;
    int idx = i-1;
    while (idx) {
      t += a[idx];
      idx -= idx & -idx;
    }

    // printf("i=%d t=%d\n", i, t);
    if (a[i] + t == 1) cnt++;
  }

  printf("%d\n", cnt);
}

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: 3804kb

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

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

result:

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