QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#549520 | #5075. Fenwick Tree | anlanyi | WA | 21ms | 7936kb | C++20 | 1.7kb | 2024-09-06 16:52:26 | 2024-09-06 16:52:26 |
Judging History
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 vis[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'&&!vis[g]){
vis[g]=1;
cnt++;
}
}
if(s[u]=='1'){
vis[u]=1;
// cout<<u<<' '<<cnt<<'\n';
ans+=max(cnt,1);
}else {
//cout<<u<<' '<<cnt<<'\n';
if(cnt==1){
ans+=2;
}else ans+=cnt;
}
}
void solve()
{
cin >> n;
ans=0;
for(int i=0;i<=n;i++){
h[i].clear();
vis[i]=0;
}
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 7712kb
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: 21ms
memory: 7936kb
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 1 0 0 0 1 0 1 2 0 0 1 2 2 0 2 1 0 0 2 2 2 0 1 2 1 0 2 2 0 0 2 2 0 0 2 0 1 1 0 0 0 0 0 0 0 1 2 2 1 0 1 0 2 1 0 1 1 0 2 2 0 1 0 1 0 0 2 1 0 0 0 1 1 0 1 0 0 0 0 1 2 0 0 0 0 0 0 2 0 2 1 0 2 2 2 0 0 0 0 0 0 0 1 0 0 0 2 0 2 0 0 0 1 0 1 0 0 2 0 0 0 1 0 0 1 2 0 0 1 0 1 0 0 2 0 2 0 0 0 1 0 0 1 2 1 0 ...
result:
wrong answer 5th numbers differ - expected: '2', found: '1'