一个疑问
查看原帖
一个疑问
315448
whdywjd楼主2023/8/3 20:14

复杂度 O(2n×n+6×26×q)O(2^n\times n+6\times2^6\times q),其中 66 是一个 popcount 的复杂度。代码局部:

while(q--)
{
    ......
    
    for(int i = u; ~i; i = (i ? ((i - 1) & u) : -1)) // u 最多 6 个二进制位为 $1$
        if(popcount(i) & 1)
            ans -= s1[c + i]; // c 是一个变量
        else
            ans += s1[c + i];
    
    ......
}

请问为什么使用 std :: __builtin_popcount(x) 可以 754ms AC(https://www.luogu.com.cn/record/118862432),但使用如下代码 TLE(https://www.luogu.com.cn/record/118862591):

int popcount(int x)
{
    int ans = 0;
    while(x)
        x -= (x & -x), ans++;
    return ans;
}
2023/8/3 20:14
加载中...