$ >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. Mock InjectMocks ( @Mock 和 @InjectMocks )区别

    之前一直对这两个注解的区别不是很明白. 搜到过一篇博客园的文章举例说明了代码行为的区别.后来在stackoverflow上看到一个问答简单明了的解释了这两个注解在定义上的区别: 在此翻译记录一下: / ...

  2. 【BZOJ】1468: Tree(POJ1741) 点分治

    [题意]给定带边权树,求两点距离<=k的点对数.n<=40000. [算法]点分治 [题解]对于一个区域,选择其重心x作为根,则划分出来的每棵子树都是子区域,可以证明至多划分log n次( ...

  3. 在Unity中实现屏幕空间阴影(2)

    参考文章: https://www.imgtec.com/blog/implementing-fast-ray-traced-soft-shadows-in-a-game-engine/ 完成的工程: ...

  4. c++刷题(3/100)数独,栈和队列

    stack的基本操作 • s.size():返回栈中的元素数量 • s.empty():判断栈是否为空,返回true或false • s.push(元素):返回对栈顶部“元素”的可变(可修改)引用 • ...

  5. C语言实现栈(顺序存储方式)

    #include <stdio.h> #include <stdlib.h> //提供malloc()原型 #include <stdbool.h> //提供tru ...

  6. 多维数组的字符依次输出,用python实现

    #-*- coding=utf-8 -*-listm=["s","l","z","x","l",&q ...

  7. python基础之上下文管理器

    前言 关于计算器运行的上下文的概念,我的理解也不是很深:按我的理解就是程序在运行之前,其所需要的资源,运行环境等都会被序列化,然后加入到CPU的任务队列中,等待调度系统分配时间片执行.下面谈谈pyth ...

  8. caffe Python API 之图片预处理

    # 设定图片的shape格式为网络data层格式 transformer = caffe.io.Transformer({'data': net.blobs['data'].data.shape}) ...

  9. Selenium_Page Object设计模式

    Page Object 介绍 Page Object设计模式的优点如下: 减少代码的重复 提高测试用例的可读性 提高测试用例的可维护性,特别是针对UI频繁变化的项目 当Web页面编写测试时,需要操作该 ...

  10. 冒泡法的算法最佳情况下的时间复杂度为什么是O(n)

    我在许多书本上看到冒泡排序的最佳时间复杂度是O(n),即是在序列本来就是正序的情况下. 但我一直不明白这是怎么算出来的,因此通过阅读<算法导论-第2版>的2.2节,使用对插入排序最佳时间复 ...