QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#303417 | #5075. Fenwick Tree | myusername# | TL | 1ms | 4632kb | C++20 | 627b | 2024-01-12 15:10:42 | 2024-01-12 15:10:43 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
int LSB(int i){
return i & (-i);
}
int T,n;
char s[100010];
int cnt[100010];
signed main(){
scanf("%lld",&T);
while(T--){
memset(cnt,0,sizeof(cnt));
scanf("%lld",&n);
scanf("%s",s + 1);
int ans = 0;
for(int i = 1; i <= n; i++){
if(s[i] == '1' && !cnt[i]){
int x = i;
while(x <= n){
cnt[x]++;
x += LSB(x);
}
ans++;
}
if(s[i] == '0' && cnt[i]){
int x = i;
while(x <= n){
cnt[x]--;
x += LSB(x);
}
ans++;
}
}
printf("%lld\n",ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4632kb
input:
3 5 10110 5 00000 5 11111
output:
3 0 3
result:
ok 3 number(s): "3 0 3"
Test #2:
score: -100
Time Limit Exceeded
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 ...