$ >Codeforces \space 408 E.\ Curious Array<$

题目大意 :

有一个长度为 \(n\) 的序列 \(a\) ,\(m\) 次操作,每一次操作给出 \(l, r, k\) ,使得 \(i \in[l, r]\) 加上 \(i-l+k\choose k\) ,求 \(m\) 次操作后的序列

\(1 \leq n, m \leq 10^5, 0 \leq k \leq 100\)

解题思路 :

观察发现这个操作是加上 \(C_{k+i}^{k}\) 这样的东西,根据组合数的递推公式 $C_{n}^{m} = C_{n-1}^{m} + C_{n-1}^{m-1} $ 可以得知,操作的本质是加上对 \((1,1,1...1) (r-l+1)\) 个 \(1\) 这个序列做 \(k\) 次前缀和后的结果。

所以可以把序列分成 \(k\) 层来处理,每一次操作在第 \(k\) 层的 \(l\) 位置加上 \(1\) ,全部做完之后对从高到低对每一层做前缀和,下一层加上上一层对应位置的前缀和即可。但是还要在 \(r+1\) 处减去贡献,考虑 \(k\) 次前缀和的贡献会对其下面所有层产生影响,不难发现此时第 \(k-i\) 层要被减掉的贡献是做 \(i\) 次前缀和前 \(r-l+1\) 项的和,对应回原来的组合数减去即可。

/*program by mangoyang*/
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include<bits/stdc++.h>
#define inf (0x7f7f7f7f)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long ll;
using namespace std;
template <class T>
inline void read(T &x){
int f = 0, ch = 0; x = 0;
for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = 1;
for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
if(f) x = -x;
}
#define int ll
const int N = 200005, Mod = 1e9+7;
int js[N], inv[N], a[N][105], n, m;
inline int Pow(int a, int b){
int ans = 1;
for(; b; b >>= 1, a = 1ll * a * a % Mod)
if(b & 1) ans = 1ll * ans * a % Mod;
return ans;
}
inline int C(int x, int y){ return js[x] * inv[y] % Mod * inv[x-y] % Mod; }
signed main(){
js[0] = inv[0] = 1;
for(int i = 1; i < N; i++)
js[i] = 1ll * js[i-1] * i % Mod, inv[i] = Pow(js[i], Mod - 2);
read(n), read(m);
for(int i = 1; i <= n; i++) read(a[i][0]);
for(int i = 1, l, r, k; i <= m; i++){
read(l), read(r), read(k), a[l][k+1]++;
for(int j = 1; j <= k + 1; j++)
(a[r+1][j] -= C(r - l + k - j + 1, k - j + 1)) %= Mod;
}
for(int i = 101; i >= 0; i--){
int s = 0;
for(int j = 1; j <= n; j++){
(s += a[j][i+1]) %= Mod;
(a[j][i] += s) %= Mod;
}
}
for(int i = 1; i <= n; i++)
printf("%lld ", (a[i][0] % Mod + Mod) % Mod);
return 0;
}

Codeforces 408 E. Curious Array的更多相关文章

  1. codeforces 407C Curious Array

    codeforces 407C Curious Array UPD: 我觉得这个做法比较好理解啊 参考题解:https://www.cnblogs.com/ChopsticksAN/p/4908377 ...

  2. Codeforces 442C Artem and Array(stack+贪婪)

    题目连接:Codeforces 442C Artem and Array 题目大意:给出一个数组,每次删除一个数.删除一个数的得分为两边数的最小值,假设左右有一边不存在则算作0分. 问最大得分是多少. ...

  3. Codeforces Round #504 D. Array Restoration

    Codeforces Round #504 D. Array Restoration 题目描述:有一个长度为\(n\)的序列\(a\),有\(q\)次操作,第\(i\)次选择一个区间,将区间里的数全部 ...

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

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

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

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

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

  7. Educational Codeforces Round 21 D.Array Division(二分)

    D. Array Division time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...

  8. Codeforces 754A Lesha and array splitting(简单贪心)

    A. Lesha and array splitting time limit per test:2 seconds memory limit per test:256 megabytes input ...

  9. Educational Codeforces Round 11A. Co-prime Array 数学

    地址:http://codeforces.com/contest/660/problem/A 题目: A. Co-prime Array time limit per test 1 second me ...

随机推荐

  1. R1(下)—数据挖掘—关联规则理论介绍与R实现

    Apriori algorithm是关联规则里一项基本算法.是由Rakesh Agrawal和Ramakrishnan Srikant两位博士在1994年提出的关联规则挖掘算法.关联规则的目的就是在一 ...

  2. 【CodeForces】576 B. Invariance of Tree

    [题目]B. Invariance of Tree [题意]给定n个数的置换,要求使n个点连成1棵树,满足u,v有边当且仅当a[u],a[v]有边,求一种方案或无解.n<=10^5. [算法]数 ...

  3. hihoCoder #1175 : 拓扑排序·二

    题目链接:http://hihocoder.com/problemset/problem/1175 代码实现如下: #include <queue> #include <cstdio ...

  4. php简单文件管理器——php经典实例

    <html> <head> <title>文件管理</title> <meta charset='utf-8' /> </head&g ...

  5. docker之构建redis-cluster集群

    下载和编译redis安装包 参考:https://www.cnblogs.com/cwp-bg/p/8094914.html # 从官方网站下载安装包,注意,当前在哪个目录下执行命令,下载的包将在哪个 ...

  6. WebClient vs HttpClient vs HttpWebRequest

    转载:http://www.diogonunes.com/blog/webclient-vs-httpclient-vs-httpwebrequest/ Just when I was startin ...

  7. ansible安装配置及最佳实践roles

    ansible是什么? ansible是一款轻量级配置管理工具,用于远程批量部署.安装.配置.类似的还有puppet.saltstack,各有所长,任君自选. 官方文档:http://docs.ans ...

  8. TCP的状态兼谈Close_Wait和Time_Wait的状态

    原文链接: http://www.2cto.com/net/201208/147485.html TCP的状态兼谈Close_Wait和Time_Wait的状态   一 TCP的状态: 1).LIST ...

  9. 设计模式--工厂模式 caffe_layer注册

    来源:http://www.cnblogs.com/zhouqiang/archive/2012/07/20/2601365.html 来源:http://blog.luoyetx.com/2016/ ...

  10. 数学中的Sin和Cos是什么意思?(转)

    数学中的Sin和Cos是什么意思? 作者:admin 分类:生活随笔 发表于 2012年03月21日 16:48 问:数学中的Sin和Cos是什么意思? 答:sin, cos, tan 都是三角函数, ...