• HDU6129 规律


    LINK

    题意:n个数进行m次前缀和异或和后的情况,其中$n,m(1leq nleq2 imes10^5,1leq mleq10^9)$。

    思路:看到m这么大,肯定要分解m的,又是异或和,二进制分解后,发现第i的位置上值为与i相距 [m分解后的各个值]位置上的异或,复杂度O(nlogm)。

    /** @Date    : 2017-08-18 16:10:51
      * @FileName: 1010 规律.cpp
      * @Platform: Windows
      * @Author  : Lweleth (SoungEarlf@gmail.com)
      * @Link    : https://github.com/
      * @Version : $Id$
      */
    #include <bits/stdc++.h>
    #define LL long long
    #define PII pair<int ,int>
    #define MP(x, y) make_pair((x),(y))
    #define fi first
    #define se second
    #define PB(x) push_back((x))
    #define MMG(x) memset((x), -1,sizeof(x))
    #define MMF(x) memset((x),0,sizeof(x))
    #define MMI(x) memset((x), INF, sizeof(x))
    using namespace std;
    
    const int INF = 0x3f3f3f3f;
    const int N = 5e5+20;
    const double eps = 1e-8;
    
    LL a[N];
    int main()
    {
    	int T;
    	cin >> T;
    	while(T--)
    	{
    		LL n, m;
    		scanf("%lld%lld", &n, &m);
    		for(int i = 0; i < n; i++)
    			scanf("%lld", a + i);
    		for(int i = 0; i < 32; i++)
    		{
    			if((m & (1LL << i)) == 0)//注意优先级...
    				continue;
    			for(int j = 0; j < n; j++)
    			{
    				if(j - (1 << i) >= 0)
    					a[j] ^= a[j - (1 << i)];
    				//printf("%lld%s", a[j], j==n-1?"
    ":" ");
    			}
    
    		}
    		for(int i = 0; i < n; i++)
    			printf("%lld%s", a[i], i==n-1?"
    ":" ");
    	}
        return 0;
    }
    
  • 相关阅读:
    vim 常用操作
    Zookeeper 一种简单的原子操作机制:
    用习惯的vimrc配置,在这里记录一下,以后可以继续完善使用
    static_cast, dynamic_cast, const_cast探讨【转】
    常用CSS标签使用
    Java基础
    Hibernate的第一个程序
    Hibernate的优缺点
    python基础语法
    ansible-role安装nginx,keepalived,tomcat
  • 原文地址:https://www.cnblogs.com/Yumesenya/p/7392121.html
Copyright © 2020-2023  润新知