CF1034E Little C Loves 3 III

https://www.luogu.com.cn/problem/CF1034E

首先设 c n t [ S ] cnt[S] cnt[S]表示 S S S在二进制下有多少个1
考虑设 f i = a i × 4 c n t [ i ] , g i = b i × 4 c n t [ i ] f_i=a_i \times 4^{cnt[i]},g_i=b_i\times 4^{cnt[i]} fi=ai×4cnt[i],gi=bi×4cnt[i]
然后设 C = F ∗ G C=F*G C=FG
答案就是 A N S i = C i 4 c n t [ i ] ANS_i=\frac{C_i}{4^{cnt[i]}} ANSi=4cnt[i]Ci
手推一下就可以发现是正确的
code:

#include<bits/stdc++.h>
#define lowbit(x) (x & -x)
#define ll long long
using namespace std;
const int N = (1 << 21) + 5;
void fwt(ll *a, int n, int o) {
    for(int len = 2; len <= n; len <<= 1)
        for(int j = 0; j < n; j += len)
            for(int k = j; k < j + (len >> 1); k ++)
                a[k + (len >> 1)] += a[k] * o;
}
int n; ll a[N], b[N];
char ch;
int main() {
    scanf("%d", &n); n = (1 << n);
    for(int i = 0; i < n; i ++) {
        scanf("%1lld", &a[i]);
        ll k = 2 * __builtin_popcount(i);
        a[i] <<= k;
    }
    for(int i = 0; i < n; i ++) {
        scanf("%1lld", &b[i]);
        ll k = 2 * __builtin_popcount(i);
        b[i] <<= k;
    }
    fwt(a, n, 1), fwt(b, n, 1);
    for(int i = 0; i < n; i ++) a[i] *= b[i];
    fwt(a, n, -1);
    for(int i = 0; i < n; i ++) {
        ll k = 2 * __builtin_popcount(i);
        a[i] >>= k;
        printf("%lld", a[i] & 3);
    }
    return 0;
}
posted @ 2021-07-30 09:29  lahlah  阅读(26)  评论(0编辑  收藏  举报