CF959F Mahmoud and Ehab and yet another xor task

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

碰巧模拟赛遇到了巨大加强版类似的

首先肯定是离线下来,一个个插入线性基中

分析后容易发现,满秩后插不进去的那些就是可选可不选的
所以答案就是 2 k 2^k 2k插不进去的那些

code:

#include<bits/stdc++.h>
#define mod 1000000007
#define N 200050
using namespace std;
int p[25], a[N], cnt;
void insert(int x) {
    for(int i = 20; i >= 0; i --) if((x >> i) & 1) {
        if(!p[i]) {
            p[i] = x;
            return;
        }
        x ^= p[i];
    }
    cnt ++;
}
int query(int x) {
    for(int i = 20; i >= 0; i --) if((x >> i) & 1) {
        if(!p[i]) return 0;
        x ^= p[i];
    }
    return 1;
}
struct Q {
    int x, id;
};
vector<Q> q[N];
int n, m, ans[N], pw[N];
int main() {
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; i ++) scanf("%d", &a[i]);
    for(int i = 1; i <= m; i ++) {
        int x, y;
        scanf("%d%d", &x, &y);
        q[x].push_back((Q){y, i});
    }

    pw[0] = 1;
    for(int i = 1; i <= n; i ++) pw[i] = pw[i - 1] * 2 % mod;
    for(int i = 1; i <= n; i ++) {
        insert(a[i]);
        for(int j = 0; j < q[i].size(); j ++) {
            ans[q[i][j].id] = query(q[i][j].x) * pw[cnt];
        }
    }
    for(int i = 1; i <= m; i ++) printf("%d\n", ans[i]);
    return 0;
}
posted @ 2021-11-05 18:45  lahlah  阅读(58)  评论(0编辑  收藏  举报