[HDU-6129]Just do it

题目

传送门

题解

设原数组的第 \(i\) 位经过 \(j\) 次变换之后得到的数字为 \(f[i][j]\),那么显然有

\[f[i][j]=f[i-1][j]\oplus f[i][j-1] \]

考虑单独一个数对于最终的答案序列哪些位置有贡献:

对于数字 \(i\),显然他在第一次变换之后,从 \(i+1\)\(n\) 每个数都异或上了它,即它在之后所有的数中都存在了 \(1\) 次,而他自己所对应的位置,即 \(f[i][x]\),其中 \(x\) 为任意整数对于所有的 \(f[i][x]\),它的贡献全为 \(1\) 次,而又由于 \(f[i][j]=f[i-1][j]\oplus f[i][j-1]\),可以将异或操作想象为贡献次数的累加,那么这就是杨辉三角了。

对于一个数 \(i\),它对最总答案的第 \(j(j\ge i)\) 位的贡献为 \(C_{m-1+j-i}^{j-i}\),显然,如果这个数若 \(\bmod 2\)\(1\),那么 \(i\) 对第 \(j\) 位就会产生贡献,根据卢卡斯定理,有

\[C_n^m\bmod x=C_{n/x}^{m/x}\times C_{n\%x}^{m\%x}\bmod x \]

\(x=2\),发现规律:如果 \(m\) 的二进制表示是 \(n\) 二进制表示下的子集(不知道该用什么更好的方式了),说明 \(C_n^m\) 是个奇数,否则,答案一定会有 \(C_0^1=0\) 出现,这个时候 \(\bmod 2\) 的结果为 \(0\),是偶数。

考虑代码如何实现,如果我们枚举一个 \(i\),再枚举一个 \(j\),时间复杂度会达到 \(\mathcal O(Tn^2)\),无法承受,我们考虑枚举 \(j-i\) 的值,如果遇到一个合法的 \(j-i\),再考虑枚举 \(j\) 进而计算出 \(i\),这样会大大降低复杂度。

代码

#include<cstdio>

#define rep(i,__l,__r) for(signed i=(__l),i##_end_=(__r);i<=i##_end_;++i)
#define fep(i,__l,__r) for(signed i=(__l),i##_end_=(__r);i>=i##_end_;--i)
#define erep(i,u) for(signed i=tail[u],v=e[i].to;i;i=e[i].nxt,v=e[i].to)
#define writc(a,b) fwrit(a),putchar(b)
#define mp(a,b) make_pair(a,b)
#define fi first
#define se second
typedef long long LL;
// typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef unsigned uint;
#define Endl putchar('\n')
// #define int long long
// #define int unsigned
// #define int unsigned long long

#define cg (c=getchar())
template<class T>inline void read(T& x){
    char c;bool f=0;
    while(cg<'0'||'9'<c)f|=(c=='-');
    for(x=(c^48);'0'<=cg&&c<='9';x=(x<<1)+(x<<3)+(c^48));
    if(f)x=-x;
}
template<class T>inline T read(const T sample){
    T x=0;char c;bool f=0;
    while(cg<'0'||'9'<c)f|=(c=='-');
    for(x=(c^48);'0'<=cg&&c<='9';x=(x<<1)+(x<<3)+(c^48));
    return f?-x:x;
}
template<class T>void fwrit(const T x){//just short,int and long long
    if(x<0)return (void)(putchar('-'),fwrit(-x));
    if(x>9)fwrit(x/10);
    putchar(x%10^48);
}
template<class T>inline T Max(const T x,const T y){return x<y?y:x;}
template<class T>inline T Min(const T x,const T y){return x<y?x:y;}
template<class T>inline T fab(const T x){return x>0?x:-x;}
inline int gcd(const int a,const int b){return b?gcd(b,a%b):a;}
inline void getInv(int inv[],const int lim,const int MOD){
    inv[0]=inv[1]=1;for(int i=2;i<=lim;++i)inv[i]=1ll*inv[MOD%i]*(MOD-MOD/i)%MOD;
}
inline LL mulMod(const LL a,const LL b,const LL mod){//long long multiplie_mod
    return ((a*b-(LL)((long double)a/mod*b+1e-8)*mod)%mod+mod)%mod;
}

const int mod=1000000009;

int n,c,k;

signed main(){
    
    return 0;
}
posted @ 2020-09-07 09:25  Arextre  阅读(106)  评论(0编辑  收藏  举报