[ARC144D] AND OR Equation
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),那么
\]
共有 \(K-s1+s2+1\) 种选法
注意到 \(s1-s2=\sum\limits_{i=0}^n|f(2^i)|\)
我们可以往这个方向去列式子。枚举最后的绝对值之和。
\]
\]
\]
\]
\]
此时我们还要给每个数分配正负,发现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);
}
[ARC144D] AND OR Equation的更多相关文章
- CodeForces460B. Little Dima and Equation
B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input s ...
- ACM: FZU 2102 Solve equation - 手速题
FZU 2102 Solve equation Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
- HDU 5937 Equation
题意: 有1~9数字各有a1, a2, -, a9个, 有无穷多的+和=. 问只用这些数字, 最多能组成多少个不同的等式x+y=z, 其中x,y,z∈[1,9]. 等式中只要有一个数字不一样 就是不一 ...
- coursera机器学习笔记-多元线性回归,normal equation
#对coursera上Andrew Ng老师开的机器学习课程的笔记和心得: #注:此笔记是我自己认为本节课里比较重要.难理解或容易忘记的内容并做了些补充,并非是课堂详细笔记和要点: #标记为<补 ...
- CF460B Little Dima and Equation (水题?
Codeforces Round #262 (Div. 2) B B - Little Dima and Equation B. Little Dima and Equation time limit ...
- Linear regression with multiple variables(多特征的线型回归)算法实例_梯度下降解法(Gradient DesentMulti)以及正规方程解法(Normal Equation)
,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, , ...
- ACM:HDU 2199 Can you solve this equation? 解题报告 -二分、三分
Can you solve this equation? Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Su ...
- [ACM_数学] Counting Solutions to an Integral Equation (x+2y+2z=n 组合种类)
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27938#problem/E 题目大意:Given, n, count the numbe ...
- hdu 2199 Can you solve this equation?(二分搜索)
Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- SGU 106 The equation
H - The equation Time Limit:250MS Memory Limit:4096KB 64bit IO Format:%I64d & %I64u Subm ...
随机推荐
- 从0开始,Cloudreve开源云盘在centos7上部署,并可在外网访问(资料整合)
全程我在网络上收集这些资料,太零碎了,每一个一看就会,一动手就废,而且很多都不能实现我白嫖的梦想 我一个人折腾了快一周,现在可以正常访问手机电脑多端访问 给个赞再走吧 此处为没有公网IP(回去折腾你家 ...
- Geotools实现shape文件的写入
众所周知Geotools作为开源的Java GIS三方库,已经成为GIS服务器端的主流开源库,其功能非常强大,涉及到GIS业务的方方面面,其中就包括GIS数据的读写,今天小编就借助Geotools来实 ...
- 微服务集成seata完成分布式事务,解决数据不一致问题
细心的盆友可能已经发现了,我们的跨行转账并没有保证数据一致性,比如小明扣除了100,但是因为各种问题小红在添加100金额的时候遇到了异常,这个时候数据就出现不一致性 我们可以选择seata来进行分布式 ...
- 10、Mybatis之缓存
10.1.环境搭建 10.1.1.创建新module 创建名为mybatis_cache的新module,过程参考5.1节 10.1.2.创建Mapper接口和映射文件 package org.rai ...
- 深入了解商品详情API接口的使用方法与数据获取
作为程序员,了解和熟悉如何调用API接口获取淘宝商品数据是非常重要的.在现今的电商环境中,准确.及时地获取商品详情信息对于开发者和商家来说至关重要.本文将以程序员的视角,详细介绍如何调用API接口 ...
- 运行解压版tomcat中的startup.bat一闪而退的解决办法
Tomcat的startup.bat,它调用了catalina.bat,而catalina.bat则调用了setclasspath.bat,只要在setclasspath.bat的开头声明环境变量(红 ...
- 杰哥教你面试之一百问系列:java集合
目录 1. 什么是Java集合?请简要介绍一下集合框架. 2. Java集合框架主要分为哪几种类型? 3. 什么是迭代器(Iterator)?它的作用是什么? 4. ArrayList和LinkedL ...
- WebAPI接口文档快速编写
近期项目使用了WebAPI,需要先给出接口文档,本着能省事就省事的原则,自然最好是能找到自动生成文档的方式. 一.使用Apifox,官网写着这是个API一体化协作平台,说白了,对于我来说,这就是个测试 ...
- 简述Spring Cache缓存策略
一.简介 Spring框架提供了一种名为Spring Cache的缓存策略.Spring Cache是一种抽象层,它提供了一种方便的方式来管理缓存,并与Spring应用程序中的各种缓存实现(如EhCa ...
- JUC并发编程(2)—synchronized锁原理
目录 乐观锁和悲观锁介绍 synchronized用法介绍 synchronized和ReentrantLock的区别 经典8锁问题案例 从字节码角度分析synchronized实现 synchron ...