HPrefix Sum

study from : https://blog.csdn.net/mitsuha_/article/details/81774727

k较小。分离x和k。

另外的可能:求a[k][x],x不确定,想到的是求sum(a[k][1]+a[k][2]+...+a[k][x]),树状数组 sum(x)-sum(x-1)。这题用不上。

 #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <iostream>
using namespace std; #define ll long long const int maxn=1e5+;
const int maxk=+;
const int inf=1e9;
const ll mod=1e9+;
const double eps=1e-; ll f[maxk][maxn],mul[maxn],chu[maxn];
int n,k; ll C(int x,int y)
{
if (x<)
{
x=y--x;
return (y&?-:)*mul[x]*chu[x-y]%mod*chu[y]%mod;
}
if (x<y)
return ;
return mul[x]*chu[x-y]%mod*chu[y]%mod;
} ll _pow(ll a,ll b)
{
ll y=;
while (b)
{
if (b &)
y=y*a%mod;
a=a*a%mod;
b>>=;
}
return y;
} void update(int x,ll y,int j)
{
while (x<=n)
{
f[j][x]=(f[j][x]+y)%mod;
x+=x&-x;
}
} ll cal(int x,int j)
{
ll sum=;
while (x)
{
sum=(sum+f[j][x])%mod;
x-=x&-x;
}
return sum;
} int main()
{
int m,i,j,mode,x;
ll sum=,y;
scanf("%d%d%d",&n,&m,&k);
k--;
mul[]=;
for (i=;i<=n;i++)
mul[i]=mul[i-]*i%mod;
chu[n]=_pow(mul[n],mod-);
for (i=n-;i>=;i--)
chu[i]=chu[i+]*(i+)%mod;
while (m--)
{
scanf("%d",&mode);
if (mode)
{
scanf("%d",&x);
sum=;
for (j=;j<=k;j++)
sum=(sum+C(x,j)*cal(x,j))%mod;
printf("%lld\n",sum);
}
else
{
scanf("%d%lld",&x,&y);
for (j=;j<=k;j++)
update(x,C(k-x,k-j)*y%mod,j);
}
}
return ;
}
/*
4 11 3
0 3 1
1 4
*/

CGambling

 #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <iostream>
using namespace std; #define ll long long const int maxn=1e5+;
const int inf=1e9;
const double eps=1e-;
const ll mod=1e9+; ll mul[maxn<<],chu[maxn<<]; ll _pow(ll a,ll b)
{
ll y=;
while (b)
{
if (b&)
y=y*a%mod;
a=a*a%mod;
b>>=;
}
return y;
} ll C(ll x,ll y)
{
return mul[x]*chu[x-y]%mod*chu[y]%mod;
} int main()
{
int n,i,j,a;
scanf("%d",&n);
mul[]=;
for (i=;i<=*n;i++)
mul[i]=mul[i-]*i%mod;
chu[*n]=_pow(mul[*n],mod-);
for (i=*n-;i>=;i--)
chu[i]=chu[i+]*(i+)%mod;
i=,j=;
while (~scanf("%d",&a))
{
printf("%lld\n",_pow(,+i+j)*C(*n--i-j,n-i-)%mod);
i+=(a==),j+=(a==);
}
return ;
}
/* */

GLongest Common Subsequence

牛客网暑期ACM多校训练营 第九场的更多相关文章

  1. 牛客网暑期ACM多校训练营(第四场):A Ternary String(欧拉降幂)

    链接:牛客网暑期ACM多校训练营(第四场):A Ternary String 题意:给出一段数列 s,只包含 0.1.2 三种数.每秒在每个 2 后面会插入一个 1 ,每个 1 后面会插入一个 0,之 ...

  2. 牛客网暑期ACM多校训练营(第五场):F - take

    链接:牛客网暑期ACM多校训练营(第五场):F - take 题意: Kanade有n个盒子,第i个盒子有p [i]概率有一个d [i]大小的钻石. 起初,Kanade有一颗0号钻石.她将从第1到第n ...

  3. 牛客网 暑期ACM多校训练营(第二场)A.run-动态规划 or 递推?

    牛客网暑期ACM多校训练营(第二场) 水博客. A.run 题意就是一个人一秒可以走1步或者跑K步,不能连续跑2秒,他从0开始移动,移动到[L,R]的某一点就可以结束.问一共有多少种移动的方式. 个人 ...

  4. 牛客网 暑期ACM多校训练营(第一场)A.Monotonic Matrix-矩阵转化为格子路径的非降路径计数,Lindström-Gessel-Viennot引理-组合数学

    牛客网暑期ACM多校训练营(第一场) A.Monotonic Matrix 这个题就是给你一个n*m的矩阵,往里面填{0,1,2}这三种数,要求是Ai,j⩽Ai+1,j,Ai,j⩽Ai,j+1 ,问你 ...

  5. 牛客网暑期ACM多校训练营(第三场)H Diff-prime Pairs (贡献)

    牛客网暑期ACM多校训练营(第三场)H Diff-prime Pairs (贡献) 链接:https://ac.nowcoder.com/acm/contest/141/H来源:牛客网 Eddy ha ...

  6. 2018牛客网暑期ACM多校训练营(第二场)I- car ( 思维)

    2018牛客网暑期ACM多校训练营(第二场)I- car 链接:https://ac.nowcoder.com/acm/contest/140/I来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 ...

  7. 牛客网暑期ACM多校训练营(第七场)Bit Compression

    链接:https://www.nowcoder.com/acm/contest/145/C 来源:牛客网 题目描述 A binary string s of length N = 2n is give ...

  8. 牛客网暑期ACM多校训练营(第一场) - J Different Integers(线段数组or莫队)

    链接:https://www.nowcoder.com/acm/contest/139/J来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 524288K,其他语言1048 ...

  9. 牛客网暑期ACM多校训练营(第九场) A题 FWT

    链接:https://www.nowcoder.com/acm/contest/147/A来源:牛客网 Niuniu has recently learned how to use Gaussian ...

随机推荐

  1. python之路--管道, 事件, 信号量, 进程池

    一 . 管道 (了解) from multiprocessing import Process, Pipe def f1(conn): # 管道的recv 里面不用写数字 from_main_proc ...

  2. QTP 自动化测试桌面程序--笔记(关闭 启动程序脚本) 、安装

    0 安装qtp .exe 文件 安装 插件文件(如delph) 1 关闭 启动程序: 将要操作的程序-存入localdatatable中 设置 迭代一次 rem SystemUtil.ClosePro ...

  3. Running Web API using Docker and Kubernetes

    Context As companies are continuously seeking ways to become more Agile and embracing DevOps culture ...

  4. [TaskList] 省选前板子补完计划

    省选前本子补完计划 [ ] 带权并查集 [ ] 树上莫队 - UOJ58 [WC2013]糖果公园 loj2485「CEOI2017」Chase

  5. mysql语句-DML语句

    DML语句 DML是指对数据库中表记录的操作,主要包括数据的增删改查以及更新,下面依次介绍 首先创建一张表:: 表名:emp 字段:ename varchar(20),hiredate date ,s ...

  6. django中怎么使用自定义管理后台xadmin

    django中怎么使用自定义管理后台xadmin 2018年05月19日 15:48:08 LH_python 阅读数:1001   首先创建基本的django项目,配置好基本的model ,url, ...

  7. sql server对已创建的表增加属性(自动增序)

    新建此表时把ID设为INT类型,然后设Identity为yes,种子为1递增就可以了.如果这张表已经建了,你在最后加一个字段叫ID,然后和上面一样操作,然后保存即可自增.(一定要设置完在保存) alt ...

  8. 了解AutoCAD对象层次结构 —— 3 ——数据库

    数据库的结构是什么样的?对象是如何存储在数据库中的?这些问题我们需要搞明白.在此我们可以借助工具ArxDbg或MgdDbg来查看数据库结构及其内容.下图就是利用MgdDbg工具查看到的内容,我们可以看 ...

  9. BZOJ1324Exca王者之剑&BZOJ1475方格取数——二分图最大独立集

    题目描述   输入 第一行给出数字N,M代表行列数.N,M均小于等于100 下面N行M列用于描述数字矩阵 输出 输出最多可以拿到多少块宝石 样例输入 2 2 1 2 2 1 样例输出 4   题意就是 ...

  10. 【AGC018F】Two Trees 构造 黑白染色

    题目描述 有两棵有根树,顶点的编号都是\(1\)~\(n\). 你要给每个点一个权值\(a_i\),使得对于两棵树的所有顶点\(x\),满足\(|x\)的子树的权值和\(|=1\) \(n\leq 1 ...