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 make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define sz(x) (int)x.size()
#define de(x) cout<< #x<<" = "<<x<<endl
#define dd(x) cout<< #x<<" = "<<x<<" "
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N=101010, P=1e9+7;

int n,m;
int a[N];
ll b[111][N], jc[N], inv[N];

ll kpow(ll a,ll b) {
    ll res=1;
    while(b) {
        if(b&1) res=res*a%P;
        a=a*a%P;
        b>>=1;
    }
    return res;
}

ll upd(ll &a, ll b) {
    a=(a+b)%P;
    if(a<0) a+=P;
}

void init() {
    jc[0]=1;
    rep(i,1,N) jc[i]=jc[i-1]*i%P;
    inv[N-1]=kpow(jc[N-1], P-2);
    for(int i=N-2;~i;--i) inv[i]=inv[i+1]*(i+1)%P;
}

ll C(int n,int m) {
    return jc[n]*inv[m]%P*inv[n-m]%P;
}

int main() {
    init();
    while(~scanf("%d%d",&n,&m)) {
        ///init
        memset(b,0,sizeof(b));
        ///read
        rep(i,1,n+1) scanf("%d",a+i);
        int ma=0;
        rep(i,0,m) {
            int l,r,k;scanf("%d%d%d",&l,&r,&k);
            ma=max(ma, k);
            upd(b[k+1][l], 1);
            rep(j,1,k+2) upd(b[j][r+1], -C(k-j+r-l+1, k+1-j));
        }
        ///solve
        for(int i=ma;~i;--i) {
            ll pre=0;
            rep(j,1,n+1) {
                upd(pre, b[i+1][j]);
                upd(b[i][j], pre);
            }
        }
        rep(i,1,n+1) printf("%lld%c",(a[i]+b[0][i])%P," \n"[i==n]);
    }
    return 0;
}

原文地址:https://www.cnblogs.com/wuyuanyuan/p/8622603.html

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

codeforces 407C Curious Array的相关文章

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}\) 这样的东西

codeforces 482B. Interesting Array【线段树区间更新】

题目:codeforces 482B. Interesting Array 题意:给你一个值n和m中操作,每种操作就是三个数 l ,r,val.就是区间l---r上的与的值为val,最后问你原来的数组是多少?如果不存在输出no 分析:分析发现要满足所有的区间,而一个点上假如有多个区间的话,这个点的值就是所有区间或的值,因为只有这样才能满足所有区间的,把所有位上的1都保存下来了,那么可以发现用线段树来维护,但是那么怎么判断满不满足条件呢?可以也用线段树,更新了之后在整个维护一遍看看满不满足题意,如

Codeforces 482B Interesting Array(线段树)

题目链接:Codeforces 482B Interesting Array 题目大意:给定一个长度为N的数组,现在有M个限制,每个限制有l,r,q,表示从a[l]~a[r]取且后的数一定为q,问是 否有满足的数列. 解题思路:线段树维护,每条限制等于是对l~r之间的数或上q(取且的性质,相应二进制位一定为1),那么处理完所有的 限制,在进行查询,查询对应每个l~r之间的数取且是否还等于q.所以用线段树维护取且和,修改为或操作. #include <cstdio> #include <c

CodeForces E. Lucky Array 幸运数列

CodeForces    E. Lucky Array  幸运数列 Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are n

codeforces 797 E. Array Queries【dp,暴力】

题目链接:codeforces 797 E. Array Queries   题意:给你一个长度为n的数组a,和q个询问,每次询问为(p,k),相应的把p转换为p+a[p]+k,直到p > n为止,求每次询问要转换的次数. 题解:纯暴力会TLE,所以在k为根号100000范围内dp打表 dp[i][j]表示初始p为i, k为j,需要转换几次可以大于n. 状态转移方程:dp[i][j] = dp[i+a[i]+j] + 1 #include <cstdio> #include <al

Codeforces 1054D Changing Array

Codeforces 1054D Changing Array 做法:给定一个序列,每个数可以把在2进制k位下取反,也可以不变,在改变后,这个序列异或和不为0的区间的个数.考虑如何求出尽可能少的异或为0的序列,对序列求前缀之后,就相当与问这个前缀的序列中,有多少对的值相同,注意还有开始的0.那么对于所有数取值为min(a,~a),现在我们需要最小化,更新后同一种数中出现的相同的数对的个数,即\(C(a,2) + C(w-a,2)\),w是这种数的个数,a是取反的数的个数,当\(a = \frac

Codeforces 86D Powerful array(莫队)

题目链接:http://codeforces.com/problemset/problem/86/D 题目: An array of positive integers a1, a2, ..., an is given. Let us consider its arbitrary subarray al, al + 1..., ar, where 1 ≤ l ≤ r ≤ n. For every positive integer s denote by Ks the number of occu

Codeforces 722C Destroying Array(并查集)*

题目链接:http://codeforces.com/problemset/problem/722/C 题意: 有 n 个正整数序列.同时 n 个摧毁序列,从 1 到 n每次把正整数序列里对应下标的数字去掉,成为一个间隔. 问每去掉一个数字,序列中最大的连续子段和. 思路: 倒着想,这道题就变成了:从 n 到 1每次出现一个数字,若数字的两边已经存在集合,则把存在的集合合并为一个, 并更新集合的和,否则单独为一个集合.过程中始终维护序列中目前所有集合里和的最大值. 代码: #include <i

【CodeForces 624D】Array GCD

题 You are given array ai of length n. You may consecutively apply two operations to this array: remove some subsegment (continuous subsequence) of length m < n and pay for it m·a coins; change some elements of the array by at most 1, and pay b coins