Cattle-off practice match 26 D-xor sequence (linear base)

Meaning of the questions:

There is a small \ (n \) number, he raised a very interesting question: he wanted to know for any \ (x \) , \ (the y-\) , Can \ (x \) and it \ ( n-\) any number of a plurality of exclusive or any number of times after becomes \ (Y \) .

analysis:

Title obviously seeking: \ (X \) \ (\ Oplus \) \ (A [I] \) \ (\ Oplus \) \ (A [J] \) \ (\ Oplus \) \ (A [K] \) \ (\ oplus \) \ (... \) \ (the y-= \) .
Transposing this equation to give: \ (A [I] \) \ (\ Oplus \) \ (A [J] \) \ (\ Oplus \) \ (A [K] \) \ (\ Oplus \) \ (... \) \ (= \) \ (X \) \ (\ Oplus \) \ (Y \) .
So that whether linear group determination prosequence heterotrophic or the \ (X \) \ (\ Oplus \) \ (Y \) , i.e., whether the inserted \ (X \) \ (\ Oplus \) \ (Y \) The problem.

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

const int N = 2e5 + 5;

struct Base {
    int tot, flag;
    LL d[66], nd[66];

    void init() {
        tot = flag = 0;
        memset(d, 0, sizeof d);
        memset(nd, 0, sizeof nd);
    }

    bool ins(LL x) {
        for (int i = 62; ~i; i--) {
            if (x & (1LL << i)) {
                if (d[i]) {
                    x ^= d[i];
                } else {
                    d[i] = x;
                    return true;
                }
            }
        }
        flag = 1;
        return false;
    }
    
    bool canIns(LL x) {
        for (int i = 62; ~i; i--) {
            if (x & (1LL << i)) {
                if (d[i]) {
                    x ^= d[i];
                } else {
                    return true;
                }
            }
        }
        return false;
    }

    LL queryMax() {
        LL ans = 0;
        for (int i = 62; ~i; i--) ans = max(ans, ans ^ d[i]);
        return ans;
    }

    LL queryMin() {
        for (int i = 0; i <= 62; i++) if (d[i]) return d[i];
        return -1LL;
    }

    void rebuild() {
        for (int i = 62; ~i; i--) {
            for (int j = i - 1; ~j; j--) {
                if (d[i] & (1LL << j)) d[i] ^= d[j];
            }
        }
        for (int i = 0; i <= 62; i++) if (d[i])
                nd[tot++] = d[i];
    }

    LL kth(LL k) {
        if (flag) k--;
        if (!k) return 0LL;
        if (k >= (1LL << tot)) return -1LL;
        LL ans = 0;
        for (int i = 62; ~i; i--) {
            if (k & (1LL << i)) ans ^= nd[i];
        }
        return ans;
    }

    void merge(Base b) {//与b取并集
        for (int i = 62; ~i; i--) if (b.d[i])
                ins(b.d[i]);
    }

    Base mixed(Base B) {//与b取交集
        Base All, C, D;
        All.init(), C.init(), D.init();
        for (int i = 62; ~i; i--) {
            All.d[i] = d[i];
            D.d[i] = 1LL << i;
        }
        for (int i = 62; ~i; i--) {
            if (B.d[i]) {
                LL v = B.d[i], k = 0;
                bool can = true;
                for (int j = 62; ~j; j--) {
                    if (v & (1LL << j)) {
                        if (All.d[j]) {
                            v ^= All.d[j];
                            k ^= D.d[j];
                        } else {
                            can = false;
                            All.d[j] = v;
                            D.d[j] = k;
                            break;
                        }
                    }
                }

                if (can) {
                    LL v = 0;
                    for (int j = 62; ~j; j--) {
                        if (k & (1LL << j)) {
                            v ^= d[j];
                        }
                    }
                    C.ins(v);
                }
            }
        }
        return C;
    }

} lb;

int n, w, q, x, y;

int main() {
    scanf("%d", &n);
    lb.init();
    for (int i = 1; i <= n; i++) {
        scanf("%d", &w);
        lb.ins(w);
    }
    scanf("%d", &q);
    while (q--) {
        scanf("%d %d", &x, &y);
        if (lb.canIns(x ^ y)) puts("NO");
        else puts("YES");
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/ChaseNo1/p/11750092.html