zoukankan      html  css  js  c++  java
  • CF1101G (Zero XOR Subset)-less

    (color{#0066ff}{ 题目描述 })

    给出一个序列({a_i}),试将其划分为尽可能多的非空子段,满足每一个元素出现且仅出现在其中一个子段中,且在这些子段中任取若干子段,它们包含的所有数的异或和不能为(0)

    (color{#0066ff}{输入格式})

    第一行一个整数(n(1 leq n leq 10^5))表示序列长度

    接下来一行(n)个整数(a_i(0 leq a_i leq 10^9))描述这个序列

    (color{#0066ff}{输出格式})

    一行,如果不存在方案输出-1,否则输出所有合法的划分方案中最大的划分数

    (color{#0066ff}{输入样例})

    4
    5 5 7 2
    
        
    3
    1 2 3
    
        
    3
    3 1 10
    

    (color{#0066ff}{输出样例})

    2
     
        
    -1
       
        
    3
    

    (color{#0066ff}{数据范围与提示})

    none

    (color{#0066ff}{ 题解 })

    求一下前缀异或和

    把所有前缀插入线性基

    答案就是线性基张成空间大小

    #include<bits/stdc++.h>
    #define LL long long
    #define ing long long
    LL in() {
    	char ch; LL x = 0, f = 1;
    	while(!isdigit(ch = getchar()))(ch == '-') && (f = -f);
    	for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 1) + (x << 3) + (ch ^ 48));
    	return x * f;
    }
    const int maxn = 4e5 + 10;
    int b[255], a[maxn];
    void ins(int x) {
    	for(int i = 40; i >= 0; i--) {
    		if(x & (1LL << i)) {
    			if(!b[i]) {
    				b[i] = x;
    				break;
    			}
    			x ^= b[i];
    		}
    	}
    }
    
    signed main() {
    	int n = in();
    	for(int i = 1; i <= n; i++) a[i] = a[i - 1] ^ in();
    	if(a[n] == 0) printf("-1");
    	else {
    		for(int i = 1; i <= n; i++) ins(a[i]);
    		int ans = 0;
    		for(int i = 0; i <= 40; i++) if(b[i]) ans++;
    		printf("%d
    ", ans);
    	}
    	return 0;
    }
    
  • 相关阅读:
    一些端口
    outlook 的微软手册
    目录摘要
    L2TP的包过滤规则
    outlook 的外出时助理程序对外部邮箱不起作用。1个解决办法和另外一个可能性
    用editplus 正则表达式修改联系人表
    Cisco NAT的理解。
    outlook 2003 无法记住密码
    ERD commander 2005的下载地址。
    outlook 2003启用日志记录排除故障。
  • 原文地址:https://www.cnblogs.com/olinr/p/10290391.html
Copyright © 2011-2022 走看看