复杂度 O(2n×n+6×26×q),其中 6 是一个 popcount 的复杂度。代码局部:
while(q--)
{
......
for(int i = u; ~i; i = (i ? ((i - 1) & u) : -1))
if(popcount(i) & 1)
ans -= s1[c + i];
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;
}