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
  1. 5 1
    0 0 0 0 0
    1 5 0
Output
  1. 1 1 1 1 1
Input
  1. 10 2
    1 2 3 4 5 0 0 0 0 0
    1 6 1
    6 10 2
Output
  1. 2 4 6 8 10 7 3 6 10 15
  2. 题意:给出n个数,m次操作
    每次操作给出liriki
    li-ri的范围里的第j个数加上 
  3. 题解:考虑到上面的ki是在每个操作里是不会变的
    考虑在杨辉三角中找规律

    k=ik=i-1的前缀和
    然后可以考虑差分
    在高维进行好差分后一维一维的降下来
    注意差分的时候要每一层都差分
  4. 代码如下:
  1. #include<map>
  2. #include<cmath>
  3. #include<queue>
  4. #include<cstdio>
  5. #include<string>
  6. #include<vector>
  7. #include<cstring>
  8. #include<iostream>
  9. #include<algorithm>
  10. #define mod 1000000007
  11. using namespace std;
  12. long long fac[],inv[],n,m,a[][],sum[][];
  13. long long kasumi(long long a,long long b)
  14. {
  15. long long ans=1ll;
  16. while(b)
  17. {
  18. if(b&)
  19. {
  20. ans=ans*a%mod;
  21. }
  22. a=a*a%mod;
  23. b>>=;
  24. }
  25. return ans;
  26. }
  27. long long c(long long a,long long b)
  28. {
  29. return fac[a]*inv[b]%mod*inv[a-b]%mod;
  30. }
  31. int main()
  32. {
  33. fac[]=,inv[]=;
  34. for(int i=; i<=; i++)
  35. {
  36. fac[i]=fac[i-]*i*1ll%mod;
  37. }
  38. inv[]=kasumi(fac[],mod-);
  39. for(int i=; i>=; i--)
  40. {
  41. inv[i]=inv[i+]*(i+)*1ll%mod;
  42. }
  43. scanf("%lld%lld",&n,&m);
  44. for(int i=; i<n; i++)
  45. {
  46. scanf("%lld",&a[][i]);
  47. }
  48. long long l,r,k;
  49. while(m--)
  50. {
  51. scanf("%lld%lld%lld",&l,&r,&k);
  52. l--,k++;
  53. a[k][l]++;
  54. for(int i=; i<=k; i++)
  55. {
  56. a[i][r]-=c(k-i+r-l-,k-i);
  57. a[i][r]=(a[i][r]+mod)%mod;
  58. }
  59. }
  60. for(int k=; k>=; k--)
  61. {
  62. for(int i=;i<n;i++)
  63. {
  64. a[k][i]+=sum[k+][i+];
  65. a[k][i]%=mod;
  66. }
  67. for(int i=;i<n;i++)
  68. {
  69. sum[k][i+]+=sum[k][i]+a[k][i];
  70. sum[k][i+]%=mod;
  71. }
  72. }
  73. for(int i=;i<n;i++)
  74. {
  75. printf("%lld ",a[][i]%mod);
  76. }
  77. }
  1.  
  1.  
  1.  

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. Varnish,Nginx搭建缓存服务器

    Varnish,Nginx搭建缓存服务器 一. varnish 1.安装pcre库,兼容正则表达式 # tar -zxvf pcre-8.10.tar.gz # cd pcre-8.10 # ./co ...

  2. 用 Sqlmap 识别 WAF

    命令: ┌─[root@sch01ar]─[~] └──╼ #sqlmap -u "http://www.sch01ar.com/" --identify-waf --batch ...

  3. hadoop性能测试

    一.hadoop自带的性能基准评测工具 (一)TestDFSIO 1.测试写性能 (1)若有必要,先删除历史数据 $hadoop jar /home/hadoop/hadoop/share/hadoo ...

  4. 自然语言处理NLTK

    Python文本分析工具NLTK 情感分析 文本相似度 文本分类 分类预测模型:朴素贝叶斯 实战案例:微博情感分析

  5. **Python的函数参数传递 和 global

    函数的参数到底是传递的一份复制的值,还是对内存的引用? 我们看下面一段代码: a = [] def fun(x): x.append(1) fun(a) print(a) 想想一下:如果传递的是一份复 ...

  6. django -- url 的 默认值

    在urls.py里可以直接向函数传递默认值,看代码: urls.py from django.conf.urls import url from mytest import views urlpatt ...

  7. Python常见字符串处理操作

    Python中字符串处理的方法已经超过37种了,下面是一些常用的字符串处理的方法,以后慢慢添加. >>> s = 'Django is cool' #创建一个字符串 >> ...

  8. 【转】H5+css布局+js+前端和移动端ui+其他汇总

    无意间发现一个博客比较好,由于内容比较多,就把链接转过来,先保存着方便看的时候看. 感谢博主“张果” +++++++++++++++++++++++++++++++++++++++++++++++++ ...

  9. vue的样式绑定

    vue在样式绑定,看这官方的文档,怎么试都不行后来看了一篇文章 <div :class="[rankClass]"></div> <script> ...

  10. JAVA集合中的迭代器的遍历

    JAVA中的迭代器,迭代实质上就是遍历,在JAVA中使用iterator()方法进行迭代.需要注意的是,iterator()方法的返回值是Iterator对象.Iterator对象有三个方法,hasN ...