Codeforces 959F Mahmoud and Ehab and yet another xor task 线性基 (看题解)

Mahmoud and Ehab and yet another xor task

存在的元素的方案数都是一样的, 啊, 我好菜啊。

离线之后用线性基取check存不存在,然后计算答案。

#include<bits/stdc++.h>
#define LL long long
#define LD long double
#define ull unsigned long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end()
#define fio ios::sync_with_stdio(false); cin.tie(0);

using namespace std;

const int N = 1e5 + 7;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const double PI = acos(-1);

template<class T, class S> inline void add(T& a, S b) {a += b; if(a >= mod) a -= mod;}
template<class T, class S> inline void sub(T& a, S b) {a -= b; if(a < 0) a += mod;}
template<class T, class S> inline bool chkmax(T& a, S b) {return a < b ? a = b, true : false;}
template<class T, class S> inline bool chkmin(T& a, S b) {return a > b ? a = b, true : false;}

int n, q, a[N], ans[N];
vector<int> base;
vector<PII> qus[N];

int ok(int v) {
    for(auto& x : base) v = min(v, v ^ x);
    return v;
}

int main() {
    scanf("%d%d", &n, &q);
    for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for(int i = 1; i <= q; i++) {
        int l, x; scanf("%d%d", &l, &x);
        qus[l].push_back(mk(x, i));
    }
    int way = 1;
    for(int i = 1; i <= n; i++) {
        int val = ok(a[i]);
        if(!val) way = 1LL * way * 2 % mod;
        else base.push_back(val);
        for(auto& q : qus[i]) ans[q.se] = ok(q.fi) ? 0 : way;
    }
    for(int i = 1; i <= q; i++) printf("%d\n", ans[i]);
    return 0;
}

/*
*/

猜你喜欢

转载自www.cnblogs.com/CJLHY/p/10753227.html