Keep some things

table of Contents

@

Linear yl

struct Base {
    int b[BASE_MAX + 1];
    int& operator [](int x) {
        return b[x];
    }
    int operator [](int x)const {
        return b[x];
    }
    void clear(int f) {
        if(f == 0) memset(b, 0, sizeof(int)*(BASE_MAX+1));
        else {
            for(int i = 0; i <= BASE_MAX; ++i) b[i] = (1<<i);
        }
    }
    bool check(int x) {
        for(int i = BASE_MAX; i >= 0; --i) {
            if(x & (1 << i)) x ^= b[i];
        }
        return (x == 0);
    }
    void out() {
        for(int i = 0; i <= BASE_MAX; ++i) printf("%d ", b[i]);
        printf("\n");
    }
}bs[MXN];
bool insert(int x, int *bs) {
    for(int j = BASE_MAX; j >= 0; --j) {
        if(!(x >> j)) continue;
        if(bs[j]) x ^= bs[j];
        else {
            bs[j] = x;
            for(int k = j-1; k >= 0; --k) if(bs[k]&&(bs[j]&(1LL<<k))) bs[j]^=bs[k];
            for(int k = j+1; k <= BASE_MAX; ++k) if(bs[k]&(1LL<<j)) bs[k]^=bs[j];
            return true;
        }
    }
    return false;
}
Base merge(const Base&a, const Base&b) {//600ms
    Base c = b, d = b, rt = {};
    for(int i = 0; i <= BASE_MAX; ++i) assert(rt[i] == 0);
    for (int i = 0, x; i <= BASE_MAX; ++i) {
        x = a[i];
        if (!x)continue;
        int j = i, T = 0;
        for (; j >= 0; --j) {
            if ((x >> j) & 1)
                if (c[j]) { x ^= c[j]; T ^= d[j]; }
                else break;
        }
        if (!x) rt[i] = T;
        else { c[j] = x; d[j] = T; }
    }
    return rt;
}
Base merge1(const Base&a, const Base&b) {//400ms
    int cur, d;
    Base tot = a, na = a, rt = {};
    for(int i = 0; i <= BASE_MAX; ++i) assert(rt[i] == 0);
    for(int i = 0; i <= BASE_MAX; ++i) if(b[i]) {
            cur = 0, d = b[i];
            for(int j = i; j >= 0; --j) if(d >> j & 1) {
                    if(tot[j]) {
                        d ^= tot[j], cur ^= na[j];
                        if(d == 0) { rt[i] = cur; break; }
                    } else {
                        tot[j] = d;
                        na[j] = cur;
                        break;
                    }
                }
        }
    return rt;
}

Guess you like

Origin www.cnblogs.com/Cwolf9/p/11297903.html