[ARC144D] AND OR Equation

Problem Statement

You are given positive integers N and K. Find the number, modulo 998244353, of integer sequences (f(0),f(1),,f(2N1)) that satisfy all of the following conditions:

  • 0f(x)K for all non-negative integers x (0x2N1).
  • f(x)+f(y)=f(xANDy)+f(xORy) for all non-negative integers x and y (0x,y2N1)

Here, AND and OR denote the bitwise AND and OR, respectively.

Constraints

  • 1N3×105
  • 1K1018

Input

Input is given from Standard Input in the following format:

$N$ $K$

Output

Print the number, modulo 998244353, of integer sequences that satisfy the conditions.


Sample Input 1

2 1

Sample Output 1

6

The following six integer sequences satisfy the conditions:

  • (0,0,0,0)
  • (0,1,0,1)
  • (0,0,1,1)
  • (1,0,1,0)
  • (1,1,0,0)
  • (1,1,1,1)

Sample Input 2

2 2

Sample Output 2

19

Sample Input 3

100 123456789123456789

二进制的题,考虑拆位处理。

那么会发现,当我们确定了 f(0),f(1)f(2n) 时,整个函数就确定了

具体写出来,就是 f(2p1+2p2++2pm)=(i=1mf(2pi)f(0))+f(0)

这个式子可以直接打表推出来

那么此时我们知道了所有 f(2ip)f(0) 的值,我们能否知道有多少个合法的 f(0)

注意有 f(x) 的限制,所以要满足任意的数,0(i=1m(f(2pi)f(0)))+f(0)K

上面这个式子的最大值和最小值一定是所有正数的和(设为 s1)和所有负数的和(设为s2),那么

s2+f(0)0,s1+f(0)k,s2f(0)Ks1

共有 Ks1+s2+1 种选法

注意到 s1s2=i=0n|f(2i)|

我们可以往这个方向去列式子。枚举最后的绝对值之和。

i=nK+1(Ki+1)Ci1n1

=(K+1)i=nK+1Ci1n1i=nK+1iCi1n1

=(K+1)i=nK+1Ci1n1ni=nK+1Cin()

=(K+1)CK+1nnCK+2n+1()

=CK+1n+1()

此时我们还要给每个数分配正负,发现0我们无法分配。枚举有多少个非0点,然后给答案加上 CK+1i+1×2i×Cni

#include<bits/stdc++.h>
using namespace std;
const int N=3e5+5,P=998244353;
int n,f[N],iv[N],inv[N],c[N],ans;
long long k;
int C(int x,int y)
{
	return 1LL*f[x]*iv[y]%P*iv[x-y]%P;
}
int main()
{
	scanf("%d%lld",&n,&k);
	c[f[0]=f[1]=iv[0]=iv[1]=inv[1]=c[0]=1]=(k+1)%P;
	for(int i=2;i<N;i++)
	{
		f[i]=1LL*f[i-1]*i%P;
		inv[i]=(P-P/i)*1LL*inv[P%i]%P;
		iv[i]=1LL*iv[i-1]*inv[i]%P;
		c[i]=c[i-1]*((k-i+2)%P)%P*inv[i]%P;
	}
	for(int i=0,pw=1;i<=n;i++,(pw<<=1)%=P)
		(ans+=1LL*pw*C(n,i)%P*c[i+1]%P)%=P;
//		printf("%d %d %d\n",i,pw,c[i+1]);
	printf("%d",ans);
}
posted @   灰鲭鲨  阅读(27)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
历史上的今天:
2022-04-29 [ZRpj9C] chess
2022-04-29 [ZRpj9A] Part
2022-04-29 [ZRpj10C] Dist
2022-04-29 [ZRpj10B] And
2022-04-29 [ZRpj10A] Scape
点击右上角即可分享
微信分享提示