codeforces 407C Curious Array
codeforces 407C Curious Array
UPD: 我觉得这个做法比较好理解啊
参考题解:https://www.cnblogs.com/ChopsticksAN/p/4908377.html
1、杨辉三角可以由多维前缀和求得。
2、“搭顺风车”的思想。
3、// 右端点减去的那个数可以用组合数学的方法思考。
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define sz(x) (int)x.size()
#define de(x) cout<< #x<<" = "<<x<<endl
#define dd(x) cout<< #x<<" = "<<x<<" "
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int N=101010, P=1e9+7;
int n,m;
int a[N];
ll b[111][N], jc[N], inv[N];
ll kpow(ll a,ll b) {
ll res=1;
while(b) {
if(b&1) res=res*a%P;
a=a*a%P;
b>>=1;
}
return res;
}
ll upd(ll &a, ll b) {
a=(a+b)%P;
if(a<0) a+=P;
}
void init() {
jc[0]=1;
rep(i,1,N) jc[i]=jc[i-1]*i%P;
inv[N-1]=kpow(jc[N-1], P-2);
for(int i=N-2;~i;--i) inv[i]=inv[i+1]*(i+1)%P;
}
ll C(int n,int m) {
return jc[n]*inv[m]%P*inv[n-m]%P;
}
int main() {
init();
while(~scanf("%d%d",&n,&m)) {
///init
memset(b,0,sizeof(b));
///read
rep(i,1,n+1) scanf("%d",a+i);
int ma=0;
rep(i,0,m) {
int l,r,k;scanf("%d%d%d",&l,&r,&k);
ma=max(ma, k);
upd(b[k+1][l], 1);
rep(j,1,k+2) upd(b[j][r+1], -C(k-j+r-l+1, k+1-j));
}
///solve
for(int i=ma;~i;--i) {
ll pre=0;
rep(j,1,n+1) {
upd(pre, b[i+1][j]);
upd(b[i][j], pre);
}
}
rep(i,1,n+1) printf("%lld%c",(a[i]+b[0][i])%P," \n"[i==n]);
}
return 0;
}
codeforces 407C Curious Array的更多相关文章
- CodeForces 408E Curious Array(组合数学+差分)
You've got an array consisting of n integers: a[1], a[2], ..., a[n]. Moreover, there are m queries, ...
- Codeforces 408 E. Curious Array
$ >Codeforces \space 408 E. Curious Array<$ 题目大意 : 有一个长度为 \(n\) 的序列 \(a\) ,\(m\) 次操作,每一次操作给出 \ ...
- Codeforces 482B Interesting Array(线段树)
题目链接:Codeforces 482B Interesting Array 题目大意:给定一个长度为N的数组,如今有M个限制,每一个限制有l,r,q,表示从a[l]~a[r]取且后的数一定为q,问是 ...
- Codeforces 1077C Good Array 坑 C
Codeforces 1077C Good Array https://vjudge.net/problem/CodeForces-1077C 题目: Let's call an array good ...
- codeforces 482B. Interesting Array【线段树区间更新】
题目:codeforces 482B. Interesting Array 题意:给你一个值n和m中操作,每种操作就是三个数 l ,r,val. 就是区间l---r上的与的值为val,最后问你原来的数 ...
- codeforces 797 E. Array Queries【dp,暴力】
题目链接:codeforces 797 E. Array Queries 题意:给你一个长度为n的数组a,和q个询问,每次询问为(p,k),相应的把p转换为p+a[p]+k,直到p > n为 ...
- Curious Array Codeforces - 407C(高阶差分(?)) || sequence
https://codeforces.com/problemset/problem/407/C (自用,勿看) 手模一下找一找规律,可以发现,对于一个修改(l,r,k),相当于在[l,r]内各位分别加 ...
- Curious Array CodeForces - 407C (高阶差分)
高阶差分板子题 const int N = 1e5+111; int a[N], n, m, k; int C[N][111], d[N][111]; signed main() { scanf(&q ...
- codeforces 86D : Powerful array
Description An array of positive integers a1, a2, ..., an is given. Let us consider its arbitrary su ...
随机推荐
- Ibatis SqlMap映射关系总结
一.一对一关系一对一关系即一对单个对象,下面举例说明:一对单个对象例如:<resultMap id="loadAResult" class="A"> ...
- Linux du查询文件大小
#查询磁盘当前容量信息 $df -h #查询当前目录下所有文件的大小 $du -m . #两种方式查询 仅当前目录下的子文件(文件夹)大小 $du -sh /cloud/* $du -h ...
- Node.js模块封装及使用
Node.js中也有一些功能的封装,类似C#的类库,封装成模块这样方便使用,安装之后用require()就能引入调用. 一.Node.js模块封装 1.创建一个名为censorify的文件夹 2.在c ...
- postgresql 备份与恢复
备份 C:\PostgreSQL\\bin>pg_dump -h localhost -p -U postgres Mes > d:/.bak 恢复 C:\PostgreSQL\\bin& ...
- [转]Upgrading to Async with Entity Framework, MVC, OData AsyncEntitySetController, Kendo UI, Glimpse & Generic Unit of Work Repository Framework v2.0
本文转自:http://www.tuicool.com/articles/BBVr6z Thanks to everyone for allowing us to give back to the . ...
- [编程] C语言的二级指针
用C语言指针作为函数返回值:C语言允许函数的返回值是一个指针(地址),我们将这样的函数称为指针函数函数运行结束后会销毁在它内部定义的所有局部数据 #include<stdio.h> #in ...
- Spring Boot学习笔记(五)整合mybatis
pom文件里添加依赖 <!-- 数据库需要的依赖 --> <dependency> <groupId>org.mybatis.spring.boot</gro ...
- BZOJ1968 [Ahoi2005] 约数研究
Description Input 只有一行一个整数 N(0 < N < 1000000). Output 只有一行输出,为整数M,即f(1)到f(N)的累加和. Sample Input ...
- 4.5&4.7联考题解
本来想加个密码的,后来一想全HE就咱们这几个人,外省的dalao愿看也没事儿,就公开算了,省得加密码各种麻烦. 先补这两天的题解吧……如果有空的话我可能会把上次联考的题解补上= =(中午没睡觉,现在困 ...
- GIS 地理坐标分类
wgs84 GPS系统直接通过卫星定位获得的坐标.(最基础的坐标.) gcj02 兲朝已安全原因为由,要求在中国使用的地图产品使用的都必须是加密后的坐标.这套加密后的坐标就是gcj02 google的 ...