QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#549511#5075. Fenwick TreeanlanyiWA 20ms5628kbC++201.6kb2024-09-06 16:39:312024-09-06 16:39:31

Judging History

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

  • [2024-09-06 16:39:31]
  • 评测
  • 测评结果:WA
  • 用时:20ms
  • 内存:5628kb
  • [2024-09-06 16:39:31]
  • 提交

answer

// #pragma GCC optimize(3,"Ofast","inline")
// #pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define point(n) fixed << setprecision(n)
#define IOS                      \
    ios::sync_with_stdio(false); \
    cin.tie(0), cout.tie(0);
#define endl '\n'
#define inf 0x3f3f3f3f
typedef long long ll;
typedef pair<ll, ll> PII;
typedef pair<ll, array<ll, 2>> PIA;
const int N = 1e6 + 10,mod=1e9+7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
int n, m, k;
int f[N];
ll e[N];int ans=0;
vector<int >h[N],d[N];
int p[N];   string s;
int lowbit(int x)
{
    return x&-x;
}
void dfs(int u)
{
    int cnt=0;
    for(auto g:h[u]){
        if(h[g].size()!=0)
        dfs(g);
        if(s[g]=='1'){
            cnt++;
        }
    }
    if(s[u]=='1'){
       // cout<<u<<' '<<cnt<<'\n';
       ans++;
    }else {
        //cout<<u<<' '<<cnt<<'\n';
        if(cnt==1)ans+=2;
    }
   
}
void solve()
{   
    cin >> n;
    ans=0;
    for(int i=0;i<=n;i++){
        h[i].clear();
    }
 
    cin >> s;
    s=" "+s;
    vector<int >cnt(n+1);
   for(int i=1;i<=n;i++){
        int t=lowbit(i);
        if(i+t<=n){
            cnt[i]++;
            h[i+t].push_back(i);      
           // cout<<i+t<<' '<<i<<'\n';
        }
   }
   for(int i=1;i<=n;i++){
        if(!cnt[i]){
            dfs(i);
            //cout<<ans<<'\n';
        }
   }
   cout<<ans<<'\n';
   
   

 
}
int main()
{
    IOS;
    int _ = 1;
    cin >> _;
    while (_--)
    {
        solve();
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 5616kb

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: 20ms
memory: 5628kb

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

result:

wrong answer 5th numbers differ - expected: '2', found: '3'