首页 > 其他分享 >[ARC144D] AND OR Equation

[ARC144D] AND OR Equation

时间:2023-04-29 12:22:24浏览次数:37  
标签:le limits int Equation iv ARC144D leq sum

Problem Statement

You are given positive integers $N$ and $K$. Find the number, modulo $998244353$, of integer sequences $\bigl(f(0), f(1), \ldots, f(2^N-1)\bigr)$ that satisfy all of the following conditions:

  • $0\leq f(x)\leq K$ for all non-negative integers $x$ ($0\leq x \leq 2^N-1$).
  • $f(x) + f(y) = f(x \,\mathrm{AND}\, y) + f(x \,\mathrm{OR}\, y)$ for all non-negative integers $x$ and $y$ ($0\leq x, y \leq 2^N-1$)

Here, $\mathrm{AND}$ and $\mathrm{OR}$ denote the bitwise AND and OR, respectively.

Constraints

  • $1\leq N\leq 3\times 10^5$
  • $1\leq K\leq 10^{18}$

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)\cdots f(2^n)\) 时,整个函数就确定了

具体写出来,就是 \(f(2^{p_1}+2^{p_2}+\cdots+2^{p_m})=(\sum\limits_{i=1}^mf(2^{p_i})-f(0))+f(0)\)

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

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

注意有 \(f(x)\) 的限制,所以要满足任意的数,\(0\le (\sum\limits_{i=1}^m(f(2^{p_i})-f(0)))+f(0)\le K\)

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

\[s2+f(0)\ge 0,s1+f(0)\le k,-s2\le f(0)\le K-s1 \]

共有 \(K-s1+s2+1\) 种选法

注意到 \(s1-s2=\sum\limits_{i=0}^n|f(2^i)|\)

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

\[\sum\limits_{i=n}^{K+1}(K-i+1)C_{i-1}^{n-1} \]

\[=(K+1)\sum\limits_{i=n}^{K+1}C_{i-1}^{n-1}-\sum\limits_{i=n}^{K+1}iC_{i-1}^{n-1} \]

\[=(K+1)\sum\limits_{i=n}^{K+1}C_{i-1}^{n-1}-n\sum\limits_{i=n}^{K+1}C_i^n(融入公式) \]

\[=(K+1)C_{K+1}^n-nC_{K+2}^{n+1}(上指标求和) \]

\[=C_{K+1}^{n+1}(通分可得,不写了) \]

此时我们还要给每个数分配正负,发现0我们无法分配。枚举有多少个非0点,然后给答案加上 \(C_{K+1}^{i+1}\times 2^i\times C_n^i\)

#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);
}

标签:le,limits,int,Equation,iv,ARC144D,leq,sum
From: https://www.cnblogs.com/mekoszc/p/17363792.html

相关文章

  • 15 Ray Tracing (Rendering Equation)
    关键点BRDF(BidirectionalReflectanceDistributionFunction)ReflectionEquationRenderingEquation1.BidirectionalReflectanceDistributionFunction(BRDF)1.1BRDF反射可以理解为光线打到物体表面被吸收,然后按照某些方向再辐射出去一部分。BRDF定义了从某一个......
  • Topcoder 10880 - Functional Equation
    首先分析一下这个鬼畜的函数,我们考虑\(f(x)+2C\)\(=f(2f(x)-x+1)+C\)\(=f(2f(2f(x)-x+1)-(2f(x)-x+1)+1)\)\(=f(2(f(x)+C)-2f(x)+x-1+1)\)\(=f(x+2C)\)也就是\(f(x)=f(x\bmod2C)+2C\lfloor\dfrac{x}{2C}\rfloor\)也就是,只要决定了\(f(x)\),\(f(x+2mC)\)也就被确定了。......
  • AtCoder Regular Contest 158 D - Equation
    题目链接原本看着式子直接晕了,觉得是高深的硬核数论,于是放弃(然后E也没想出来,sad)关键的思路在于,考虑构造由(a,b,c)->(ta,tb,tc)这样的求解方式。在看到这个做法后,会发现它很好地利用了题目齐次的性质;至于如何由齐次式想到这个做法,可能需要足够的天赋或者经验吧(悲)化简后得到\(At......
  • MATH1851 Ordinary differential equations
    课程内容笔记,自用,不涉及任何assignment,exam答案Notesforself-use,donotincludeanyassignmentsorexamsMATH1851的第二节:主要学习常微分方程ODE:Ordinary......
  • 「解题报告」ARC158D Equation
    好神仙的题。考虑形如\(F(x,y,z)=x^i+y^i+z^i\)的函数有一个性质:\(F(tx,ty,tz)=t^iF(x,y,z)\)。原式要求\((x+y+z)(x^n+y^n+z^n)(x^{2n}+y^{2n}+z^{2n......
  • HDU2199 Can you solve this equation? (二分查找)
    Canyousolvethisequation?TimeLimit:2000/1000MS(Java/Others)    MemoryLimit:32768/32768K(Java/Others)TotalSubmission(s):12794    AcceptedS......
  • MATH1851 Calculus and ordinary differential equations
    课程内容笔记,自用,不涉及任何assignment,exam答案Notesforselfuse,notincludedanyassignmentsorexams由于提前预习了微积分(见微积分\(I\),微积分\(II\))......
  • Functions, Equations and Polynomials (Pure Math)
    MO题乱做\(f:\mathbb{N}^*\mapsto\mathbb{N}^*,\foralln\in\mathbb{N}^*,f(f(n))<f(n+1)\).求\(f(n)\).有一个很厉害的做法.首先我们证明\(f(1)\)是\(\{f(k)|......
  • The Human Equation
    TheHumanEquation关键赛后随便猜了一下,竟然过了。只能说当时还是太急了,毕竟对E多少有点害怕。不行,以后要到能出E的水平代码#include<bits/stdc++.h>usingnamespa......
  • HDU 6439 2018CCPC网络赛 Congruence equationI(杜教筛 + 莫比乌斯反演 + 伯努利数)
      大致题意:给你一个长度为k的序列a。对于序列c,当  时,;当时,取[0,m)中任意一个数字。令  表示满足  的序列c的方案数。现在让你求 。          ......