当前位置: 首页 > 工具软件 > Curious > 使用案例 >

CF407C Curious Array

陶和歌
2023-12-01

题目

题目描述
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; 
}
 类似资料:

相关阅读

相关文章

相关问答