[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 ...
随机推荐
- Nginx Ingress Contoller 通过 Envoy 代理和 Jaeger 进行分布式追踪(二)
1.概述 在<应用程序通过 Envoy 代理和 Jaeger 进行分布式追踪(一)>一文中,我们详细介绍了单个应用程序如何通过 Envoy 和 Jaeger 实现链路追踪的过程.然而,单独 ...
- 【pytorch】从零开始,利用yolov5、crnn+ctc进行车牌识别
笔者的运行环境:python3.8+pytorch2.0.1+pycharm+kaggle用到的网络框架:yolov5.crnn+ctc项目地址:GitHub - WangPengxing/plate ...
- CodeForces-1324E-Sleeping-Schedule
题意 \(Vova\)有一个睡眠时间表,一天有\(h\)小时,\(Vova\)会睡\(n\)次觉,一次睡一天,在第\(i-1\)次睡醒后,\(Vova\)在\(a_i\)或\(a_i-1\)个小时候可 ...
- C++ 学习笔记、01 | 开发简单职工管理系统遇到的一些问题
记录开发简单职工管理系统遇到的一些问题,黑马教程 https://www.bilibili.com/video/BV1et411b73Z P147 ~ P166 头文件与源文件 头文件只声明,源文件来 ...
- nginx Ingress Controller Packaged by Bitnami
环境介绍 节点 master01 work01 work02 主机/ip calico-master01/192.168.195.135 calico-master01/192.168.195.135 ...
- 【Python爬虫】使用代理ip进行网站爬取
使用代理IP进行网站爬取可以有效地隐藏你的真实IP地址,让网站难以追踪你的访问行为.本文将介绍Python如何使用代理IP进行网站爬取的实现,包括代理IP的获取.代理IP的验证.以及如何把代理IP应用 ...
- 其它——Postman做接口测试
文章目录 一 介绍 二 下载安装 三 使用 四 批量接口测试(创建collections) 五 导出与导入同事的接口 5.1 导出 5.2 导入 一 介绍 在前后端分离开发时,后端工作人员完成系统接口 ...
- Python网络编程——操作系统基础、网络通信原理、.网络通信实现、DNS域名解析、 网络通信流程
文章目录 一.操作系统基础 二.网络通信原理 2.1 互联网的本质就是一系列的网络协议 2.2 osi七层协议 2.3 tcp/ip五层模型讲解 2.3.1 物理层 2.3.2 数据链路层 2.3.3 ...
- crontab guru
https://crontab.guru/every-5-minutes Cron Job Monitoring crontab guru The quick and simple editor fo ...
- Android项目Library导入的问题整理
Android项目Library导入的问题整理 本来帮助朋友找寻一下android的一些特效的demo,结果找到了一个,朋友试验可以,自己却是在导入项目需要的library的时候总是出问题,真的很是丢 ...