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的更多相关文章

  1. CodeForces 408E Curious Array(组合数学+差分)

    You've got an array consisting of n integers: a[1], a[2], ..., a[n]. Moreover, there are m queries, ...

  2. Codeforces 408 E. Curious Array

    $ >Codeforces \space 408 E. Curious Array<$ 题目大意 : 有一个长度为 \(n\) 的序列 \(a\) ,\(m\) 次操作,每一次操作给出 \ ...

  3. Codeforces 482B Interesting Array(线段树)

    题目链接:Codeforces 482B Interesting Array 题目大意:给定一个长度为N的数组,如今有M个限制,每一个限制有l,r,q,表示从a[l]~a[r]取且后的数一定为q,问是 ...

  4. Codeforces 1077C Good Array 坑 C

    Codeforces 1077C Good Array https://vjudge.net/problem/CodeForces-1077C 题目: Let's call an array good ...

  5. codeforces 482B. Interesting Array【线段树区间更新】

    题目:codeforces 482B. Interesting Array 题意:给你一个值n和m中操作,每种操作就是三个数 l ,r,val. 就是区间l---r上的与的值为val,最后问你原来的数 ...

  6. codeforces 797 E. Array Queries【dp,暴力】

    题目链接:codeforces 797 E. Array Queries   题意:给你一个长度为n的数组a,和q个询问,每次询问为(p,k),相应的把p转换为p+a[p]+k,直到p > n为 ...

  7. Curious Array Codeforces - 407C(高阶差分(?)) || sequence

    https://codeforces.com/problemset/problem/407/C (自用,勿看) 手模一下找一找规律,可以发现,对于一个修改(l,r,k),相当于在[l,r]内各位分别加 ...

  8. 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 ...

  9. codeforces 86D : Powerful array

    Description An array of positive integers a1, a2, ..., an is given. Let us consider its arbitrary su ...

随机推荐

  1. 第十章、vim 程序编辑器

    第十章.vim 程序编辑器   1. vi 与 vim 1.1 为何要学 vim 2. vi 的使用 2.1 简易执行范例 2.2 按键说明 2.3 一个案例的练习 2.4 vim 的暂存档.救援回复 ...

  2. R语言提取字符串的一部分substring函数

    这个函数提取字符串的一部分. 语法 substring()函数的基本语法是: substring(x,first,last) 以下是所使用的参数的说明: x - 是字符向量输入. first - 是第 ...

  3. 【转】Emgu CV on C# (五) —— Emgu CV on 局部自适应阈值二值化

    局部自适应阈值二值化 相对全局阈值二值化,自然就有局部自适应阈值二值化,本文利用Emgu CV实现局部自适应阈值二值化算法,并通过调节block大小,实现图像的边缘检测. 一.理论概述(转载自< ...

  4. SQL:存储过程

    1/什么是存储过程及概念 Transact-SQL中的存储过程,非常类似于.Net语言中的方法,它可以重复调用.当存储过程执行一次后,可以将语句缓存中,这样下次执行的时候直接使用缓存中的语句.这样就可 ...

  5. 超赞的 Go 语言 INI 文件操作

    灵活的数据源 不光光可以从文件读取配置,还支持 []byte 类型的纯数据读取和基于 io.ReadCloser 的流式读取. 多种格式兼容 各种文件种类的广泛支持,包括但不限于 my.cnf..gi ...

  6. Eclipse常用快捷键之技巧篇

    如何让你阅读代码如虎添翼?使用快捷键可以让你快到飞起来~ 显示类的方法和属性:ctrl+o ctrl+o能够看到你的类的层次结构,使你搜索该类某个方法更加的方便 显示类的继承:ctrl+T ctrl+ ...

  7. Java学习--JavaWeb简介

  8. 十一、curator recipes之联锁InterProcessMultiLock

    简介 curator实现了一个类似容器的锁InterProcessMultiLock,它可以把多个锁包含起来像一个锁一样进行操作,简单来说就是对多个锁进行一组操作.当acquire的时候就获得多个锁资 ...

  9. 集群搭建之Hive配置要点

    注意点: 在启动Hive 的时候要先启动Hadoop和MySQL服务. Mysql 和 Hive 搭建在 yan00机器上. part1:MySQL配置相关 安装和配置相关命令: Yum instal ...

  10. 从MySQL到ORM(三):连接、存储过程和用户权限

    一.联结表 数据仍使用前文中的数据. 1.子查询 作为子查询的SELECT语句只能查询单个列.企图检索多个列将返回错误. -- 作为查询条件使用 -- 查看TNT2订单对应的客户ip(order表) ...