A bitset exercises

The meaning of problems

Here Insert Picture Description
among them a [ i ] < = 2 k a[i]<=2^k , n k < = 2 e 6 n*k<=2e6 , x = = 3 x==3
data partition
for the case of large k, can n 2 k n^2*k violence, there can be optimized by hand bitset
here because they do not know n, k so the use of variable length arrays (and in fact the same vector)
t i p s : tips: Variable-length array is actually a pointer to an array, you need to manually assign initial values to normal use.
For small k, the power to consider the contribution of 3:
enumerate three position, handpicked these positions are the result of an XOR 1. calculate for the program to meet the conditions of the number of
reasons to consider their exclusive oR result, there are only eight kinds (when we last calculated only to enumerate four kinds of programs that we need another two programs XOR makes up each location is 1, the other four have been counted a).
then, we can determine the number of programs in each of the exclusive oR input.
now the number of calculated solutions satisfies the condition:
COE represents the position where the display order of the program because only the number h recorded program without recording order.
this complexity is n k 3 n*k^3 of

#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
const int maxn=2e6+5;
const int mod=998244353;
inline int read(){
	char c=getchar();int t=0,f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){t=(t<<3)+(t<<1)+(c^48);c=getchar();}
	return t*f;
}
int n,k,x;
unsigned int seed;
unsigned int get01(){
	seed^=seed<<13;
	seed^=seed>>17;
	seed^=seed<<5;
	return seed&1;
}
unsigned int *a[maxn],b[maxn];
inline int am(int x){
	return x>=mod?x-mod:x;
}
int pre[maxn];
inline int ksm(int a,int b){
	int ans=1;
	while(b){
		if(b&1)ans=1ll*ans*a%mod;
		a=1ll*a*a%mod;b>>=1;
	}
	return ans;
}
int g[maxn],h[60][60][60][8];
signed main(){
	n=read(),k=read(),x=read();
	scanf("%u",&seed);
	if(k>=60){
		int len=(k-1)/32+1;
		for(int i=1;i<=n;i++){
			a[i]=b+i*len;
			for(int j=0;j<k;j++){
				if(get01()){
					a[i][j>>5]=a[i][j>>5]+(1u<<(j%32));
				}
			}
		}
		pre[0]=1;
		for(int i=1;i<=len;i++)pre[i]=ksm(2,i*32);
		unsigned int ans=0;
		for(int i=1;i<=n;i++){
			for(int j=i+1;j<=n;j++){
				unsigned int tmp=0;
				for(int k=0;k<len;k++){
					tmp=am(tmp+(ull)(a[i][k]^a[j][k])*pre[k]%mod);
					//printf("%d %u %u %d %u\n",k,a[i][k],a[j][k],pre[k],tmp);
				}
				ans=am(ans+1ll*tmp*tmp%mod*tmp%mod);
			}
		}
		printf("%u\n",ans);
		return 0;
	}
	int ans=0;
	pre[0]=1;
	for(int i=1;i<=n;i++)pre[i]=2ll*pre[i-1]%mod;
	for(int i=1;i<=n;i++){
		for(int j=0;j<k;j++)
		g[j]=get01();
		for(int k1=0;k1<k;k1++)
		for(int k2=k1;k2<k;k2++)
		for(int k3=k2;k3<k;k3++){
			//printf("%d %d %d %d\n",k1,k2,k3,g[k1]|(g[k2]<<1)|(g[k3]<<2));
			h[k1][k2][k3][g[k1]|(g[k2]<<1)|(g[k3]<<2)]++;
		}
	}
	for(int k1=0;k1<k;k1++){
		for(int k2=k1;k2<k;k2++){
			for(int k3=k2;k3<k;k3++){
				for(int r=0;r<4;r++){
					int q=7^r,coe=1;
					if((k1!=k2)&&(k2!=k3))coe=6;
					else if((k1!=k2)||(k2!=k3))coe=3;
					coe=1ll*coe*h[k1][k2][k3][q]%mod*h[k1][k2][k3][r]%mod;
					ans=am(ans+1ll*pre[k1]*pre[k2]%mod*pre[k3]%mod*coe%mod);
				}
			}
		}
	}
	printf("%d\n",ans%mod);
}
Published 62 original articles · won praise 1 · views 985

Guess you like

Origin blog.csdn.net/wmhtxdy/article/details/103875665