$ >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. IO流-读取写入缓冲区

    例如FileReader和FileWriter在读取的时候是读一次或者写一次就请求磁盘,这样使用的时间非常的长,效率比较低,因此引入BufferedReader和BufferedWriter作为读取和 ...

  2. HDU 1256 画8 (找规律)

    题目链接 Problem Description 谁画8画的好,画的快,今后就发的快,学业发达,事业发达,祝大家发,发,发.   Input 输入的第一行为一个整数N,表示后面有N组数据. 每组数据中 ...

  3. react 修改state某一属性值

    1.state // 筛选框相关数据 searchSelect: { term: { value: '学期', key: '', options: [] }, type_of_personnel: { ...

  4. C - Contest Setting Gym - 101982C dp 补题

    题目链接:https://vjudge.net/contest/273260#problem/C 学习了一下别人的思路,首先去重,然后离散化. dp数组开二维,每一次更新,状态转移方程,dp[ i ] ...

  5. WordPress手机端插件——WPtouch

    戒微博之后,把更多的精力开始转投回网站上来:今天用nexus7访问@Bee君 的博客时,发现博客的界面与电脑上访问的界面不相同,顺藤摸瓜之后发现原来bee君使用的是WPtouch-pro插件来实现移动 ...

  6. 【IDEA】IDEA中配置tomcat虚拟路径的两种方法

    首先要确保使用的是本地的tomcat服务器,而不是maven插件. -------------------------第一种:使用IDEA工具自动配置(推荐这种)------------------- ...

  7. Linux是对用户的密码的复杂度要求设置【转】

    那么Linux是如何实现对用户的密码的复杂度的检查的呢?其实系统对密码的控制是有两部分组成: 1 cracklib 2 /etc/login.defs pam_cracklib.so 才是控制密码复杂 ...

  8. linux系统性能排查命令

    [top] 命令可以动态查看当前系统的资源情况,以及占用资源的命令列表 用法: - ctrl + c / q : 停止此命令运行 - c : 展示完整的命令 - [top -bn1]:可以不动态的展示 ...

  9. HDU 1024 Max Sum Plus Plus(dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1024 题目大意:有多组输入,每组一行整数,开头两个数字m,n,接着有n个数字.要求在这n个数字上,m块 ...

  10. CentOS_Linux服务器系统安装之分区

    在software selection中选择Server with GUI>(Compatibility Libraries.Development Tools和Security Tools) ...