CF407C Curious Array

题目

题目描述
You’ve got an array consisting of nn integers: a[1],a[2],…,a[n]a[1],a[2],…,a[n] . Moreover, there are mm queries, each query can be described by three integers l_{i},r_{i},k_{i}l
i

,r
i

,k
i

. Query l_{i},r_{i},k_{i}l
i

,r
i

,k
i

means that we should add to each element a[j]a[j] , where l_{i}<=j<=r_{i}l
i

<=j<=r
i

.

Record means the binomial coefficient, or the number of combinations from yy elements into groups of xx elements.

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

输入格式
The first line contains integers nn , mm ( 1<=n,m<=10^{5}1<=n,m<=10
5
).

The second line contains nn integers a[1],a[2],…,a[n]a[1],a[2],…,a[n] ( 0<=a_{i}<=10^{9}0<=a
i

<=10
9
) — the initial array.

Next mm lines contain queries in the format l_{i},r_{i},k_{i}l
i

,r
i

,k
i

— to all elements of the segment l_{i}…\ r_{i}l
i

… r
i

add number ( 1<=l_{i}<=r_{i}<=n1<=l
i

<=r
i

<=n ; 0<=k<=1000<=k<=100 ).

输出格式
Print nn integers: the ii -th number is the value of element a[i]a[i] after all the queries. As the values can be rather large, print them modulo 10000000071000000007 (10^{9}+7)(10
9
+7) .

题意翻译
给出nn个数,有mm个操作.

每个操作是将[L,R][L,R]之间的数加上C(j-L+k,k)C(j−L+k,k),L<=j<=RL<=j<=R.

最后输出这nn个数的值。

输入输出样例
输入 #1复制
5 1
0 0 0 0 0
1 5 0
输出 #1复制
1 1 1 1 1
输入 #2复制
10 2
1 2 3 4 5 0 0 0 0 0
1 6 1
6 10 2
输出 #2复制
2 4 6 8 10 7 3 6 10 15

思路

n阶差分
维护一下即可

代码


int n,m; 
LL a[maxn]; 
LL c[maxn][maxm],ans[maxn][maxm]; 

void init() {
    c[0][0] = 1; 
    for (int i = 1; i < maxn; ++i) {
        c[i][0] = 1; 
        for (int j = 1; j <= i && j < maxm; ++j) {
            c[i][j] = (c[i-1][j-1] + c[i-1][j]) % mod; 
        }
    }
}

int main() {
    init(); 
    scanf("%d%d",&n,&m); 
    for (int i = 1; i <= n; ++i) 
        scanf("%d",&a[i]);  
    int l,r,k; 
    while (m--) { 
        scanf("%d %d %d",&l,&r,&k); 
        for (int i = 0; i <= k; ++i) 
            ans[l][i] = (ans[l][i] + c[k][k-i]) % mod; 
        for (int i = 0; i <= k; ++i)
            ans[r+1][i] = (ans[r+1][i] - c[r-l+k+1][k-i]) % mod; 
    }
    for (int i = 1; i < n; ++i) {
        for (int j = 101; j >= 1; --j) {
            ans[i+1][j-1] = (ans[i+1][j-1] + ans[i][j] + ans[i][j-1]) % mod; 
        }
    }
    for (int i = 1; i <= n; ++i) {
        printf("%lld ",((ans[i][0] + a[i]) % mod + mod) % mod); 
    }
    return 0; 
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值