Codeforces 408 E. Curious Array

$ >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;
}

原文地址:https://www.cnblogs.com/mangoyang/p/9838273.html

时间: 2024-07-30 23:10:12

Codeforces 408 E. Curious Array的相关文章

codeforces 407C Curious Array

codeforces 407C Curious Array 参考题解:https://www.cnblogs.com/ChopsticksAN/p/4908377.html 1.杨辉三角可以由多维前缀和求得. 2."搭顺风车"的思想. 3.// 右端点减去的那个数可以用组合数学的方法思考. #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define mp ma

[2016-04-09][codeforces][660][A][ Co-prime Array]

时间:2016-04-09 22:50:56 星期六 题目编号:[2016-04-09][codeforces][660][A][ Co-prime Array] 题目大意:给定一个数列,问至少需要插入多少个1 1091 109中的任一数字,才能使得相邻两个数字是互质的,输出最少次数和最后的数列 分析:直接扫一遍,相邻元素不互质的,中间插个1, #include<cstdio> #include<vector> using namespace std; const int maxn

Codeforces 442C Artem and Array(stack+贪心)

题目连接:Codeforces 442C Artem and Array 题目大意:给出一个数组,每次删除一个数,删除一个数的得分为两边数的最小值,如果左右有一边不存在则算作0分.问最大得分是多少. 解题思路:首先将连续的a,b,c,a > b && c > b的情况将c掉,获得min(a,b)分,这样处理后数组变成一个递増再递减的序列,除了最大和第二大的取不到,其他数字均可以得分. 样例:4 10 2 2 8 #include <cstdio> #include

Educational Codeforces Round 21 D. Array Division

题目链接:Educational Codeforces Round 21 D. Array Division 题意: 给你n个数,现在你可以改变1<=个数的位置,然后问你是否存在有一个k,使得sum(a[i])(1<=i<=k)==sum(a[j])(k+1<=j<=n) 题解: 分析: 如果需要将一个数移动,无非就是将这个数从第一部分移到第二部分,或者从第二部分移到第一部分. 所以,我们只需要开两个map来记录一下两部分有哪些数. 当两部分的差值/2等于其中一部分的一个数时

CodeForces 451B Sort the Array

Description Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of n distinct integers. Unfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you a b

Codeforces Round #504 D. Array Restoration

Codeforces Round #504 D. Array Restoration 题目描述:有一个长度为\(n\)的序列\(a\),有\(q\)次操作,第\(i\)次选择一个区间,将区间里的数全部改为\(i\),序列\(a\)的每个位置至少被改一次.得到最终的序列,然后将序列里的某些位置变成\(0\),输出一种可能的置零之前的最终序列,或无解. solution 求出每种数字最长的染色区间,按这个区间染色,记下没出现的数字.染色后如果存在\(0\)联通块,则用没出现的数字从大到小染色(一个联

codeforces 86D D. Powerful array(莫队算法)

题目链接: D. Powerful array time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output An array of positive integers a1, a2, ..., an is given. Let us consider its arbitrary subarray al, al + 1..., ar, wh

【Codeforces 722C】Destroying Array (数据结构、set)

题意 输入一个含有 n(1≤n≤100000) 个非负整数的 a 数组和一个 1-n 的排列 p 数组,求每次删除 a[p[i]] 后,最大连续子段和(不能跨越被删除的)是多少? 分析 因为都是非负整数,答案一定是尽量长的区间和. s[i] 表示 a 的前缀和,区间(l,r]的和就是s[r]-s[l]. 我们用 STL 里的 set 存区间,一开始只有(0,n]区间,删去第一个数后,就要去掉(0,n]区间,加上(0,p[1]-1]和(p[1],n]区间,类似地每次删除一个数,就要去掉包含它的区间

CodeForces 442C Artem and Array(贪心)

E - Artem and Array Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Appoint description:  System Crawler  (2014-08-21) Description Artem has an array of n positive integers. Artem decided to play with it. T