You've got an array consisting of n integers: a[1], a[2], ..., a[n]. Moreover, there are m queries, each query can be described by three integers li, ri, ki. Query li, ri, ki means that we should add  to each element a[j], where li ≤ j ≤ ri.

Record  means the binomial coefficient, or the number of combinations from yelements into groups of x elements.

You need to fulfil consecutively all queries and then print the final array.

Input

The first line contains integers nm (1 ≤ n, m ≤ 105).

The second line contains n integers a[1], a[2], ..., a[n] (0 ≤ ai ≤ 109) — the initial array.

Next m lines contain queries in the format li, ri, ki — to all elements of the segment li... ri add number  (1 ≤ li ≤ ri ≤ n; 0 ≤ k ≤ 100).

Output

Print n integers: the i-th number is the value of element a[i] after all the queries. As the values can be rather large, print them modulo 1000000007 (109 + 7).

Examples

Input
5 1
0 0 0 0 0
1 5 0
Output
1 1 1 1 1
Input
10 2
1 2 3 4 5 0 0 0 0 0
1 6 1
6 10 2
Output
2 4 6 8 10 7 3 6 10 15

题意:给出n个数,m次操作
每次操作给出li,ri,ki
将li-ri的范围里的第j个数加上  题解:考虑到上面的ki是在每个操作里是不会变的
考虑在杨辉三角中找规律

k=i是k=i-1的前缀和
然后可以考虑差分
在高维进行好差分后一维一维的降下来
注意差分的时候要每一层都差分 代码如下:
#include<map>
#include<cmath>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define mod 1000000007
using namespace std; long long fac[],inv[],n,m,a[][],sum[][]; long long kasumi(long long a,long long b)
{
long long ans=1ll;
while(b)
{
if(b&)
{
ans=ans*a%mod;
}
a=a*a%mod;
b>>=;
}
return ans;
} long long c(long long a,long long b)
{
return fac[a]*inv[b]%mod*inv[a-b]%mod;
} int main()
{
fac[]=,inv[]=;
for(int i=; i<=; i++)
{
fac[i]=fac[i-]*i*1ll%mod;
}
inv[]=kasumi(fac[],mod-);
for(int i=; i>=; i--)
{
inv[i]=inv[i+]*(i+)*1ll%mod;
}
scanf("%lld%lld",&n,&m);
for(int i=; i<n; i++)
{
scanf("%lld",&a[][i]);
}
long long l,r,k;
while(m--)
{
scanf("%lld%lld%lld",&l,&r,&k);
l--,k++;
a[k][l]++;
for(int i=; i<=k; i++)
{
a[i][r]-=c(k-i+r-l-,k-i);
a[i][r]=(a[i][r]+mod)%mod;
}
}
for(int k=; k>=; k--)
{
for(int i=;i<n;i++)
{
a[k][i]+=sum[k+][i+];
a[k][i]%=mod;
}
for(int i=;i<n;i++)
{
sum[k][i+]+=sum[k][i]+a[k][i];
sum[k][i+]%=mod;
}
}
for(int i=;i<n;i++)
{
printf("%lld ",a[][i]%mod);
}
}

 
 

CodeForces 408E Curious Array(组合数学+差分)的更多相关文章

  1. codeforces 407C Curious Array

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

  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. Linux 为FTP 服务器添加iptables规则--案例分析

    一.故障描述 由于开发提出需求,为他们搭建内部ftp服务器,搭建好后,提交给他们,测试可以正常使用.后来过了一段时间后,有一天无法登陆了.于是去ftp主机上检查问题,ftp的配置文件没有改动,端口监听 ...

  2. MySQL--产品的起源和状态

    MySQL这个名字,起源不是很明确.一个比较有影响的说法是,基本指南和大量的库和工具带有前缀“my”已经有10年以上,而且不管怎样,MySQL AB创始人之一的Monty Widenius的女儿也叫M ...

  3. 100.64.0.0/10运营商级(Carrier-grade)NAT保留IP地址

    在一次跟踪路由的网络操作时发现自己路由器下一跳路由节点的IP地址比较奇怪,是100.64.0.1.好奇促使我查询了这个IP地址的归属,结果是保留地址,到这里觉得比较奇怪了,按照常理以IPv4为例保留的 ...

  4. 小酌Jmeter4.0新版本特性

    1.  首先下载打开jmeter4.0,说一个能感受到的视觉变化,如图, 黑色界面,不少朋友认为做技术黑色的东西看起来高上大一点,虽然这个观念有点肤浅,但似乎也有点道理,毕竟还是有不少朋友热衷于lin ...

  5. sublime text 怎么浏览包

    点击到设置里 里面有个包浏览.

  6. npm 全局环境变量配置

      我们要先配置npm的全局模块的存放路径以及cache的路径,例如我希望将以上两个文件夹放在NodeJS的主目录下,便在NodeJs下建立”node_global”及”node_cache”两个文件 ...

  7. git如何处理别人的pull request及解决冲突 (转)

    原贴地址 出过两次了,每次都查很多资料,太蛋疼,记录在此. 当你的项目比较牛逼的时候,有人给你贡献代码,但他修改的地方恰恰你前阵子也修改了,这样在github中就不能够自动merge了. 因此你需要手 ...

  8. 通过devtools在centos系统中启用高版本的gcc

    C++11出来好久了,现在还是使用c++03的,需要在centos6.6的系统上实现gcc的升级,又不想自己编译代码. 于是选用了devtoolsset系列,安装脚本如下 安装脚本如下 functio ...

  9. iOS学习之Xcode 的Debug技巧

    在Xcode中,Debug时,不能像eclipse ,或VS那些集成开发那样,能直接查看变量的值.那怎么在调试的时候查看XCode的变量呢? 有一些方法的. 1.新建一个Single View App ...

  10. Renderer.materials 和sharedMaterials一些用法上的区别

    Not allowed to access Renderer.materials on prefab object. Use Renderer.sharedMaterials insteadUnity ...