• 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
    ", ans[i]);
        return 0;
    }
    
    /*
    */
  • 相关阅读:
    华为实习日记——第三十八天
    华为实习日记——第三十七天
    华为实习日记——第三十六天
    华为实习日记——第三十五天
    华为实习日记——第三十四天
    华为实习日记——第三十三天
    华为实习日记——第三十二天
    华为实习日记——第三十一天
    华为实习日记——第三十天
    一些事情(征标题)
  • 原文地址:https://www.cnblogs.com/CJLHY/p/10753227.html
Copyright © 2020-2023  润新知