https://codeforces.com/problemset/problem/407/C

(自用,勿看)

手模一下找一找规律,可以发现,对于一个修改(l,r,k),相当于在[l,r]内各位分别加上[1,0,0,0,0,..]做k+1次前缀和得到的数组

比如(l=3,r=6,k=2),[1,0,0,..]做k+1=3次前缀和后为[1,3,6,10,15,..],因此这次修改相当于a[l]+=1,a[l+1]+=3,a[l+2]+=6,a[l+3]+=10

很容易想到k从大到小排序,用差分维护,不断做前缀和“解包”(不展开写了..)

然后我就不会了。。因为每一次是“区间加”,我只能做到从某个位置到末尾全部加,没有办法把多余的消掉

膜了大佬,发现只要每一层差分的时候都在合适位置减去合适值就行了,找规律(例如l=3,r=6,k=2,一开始是1,0,0,0,-1,第一次变成1,1,1,1,0,再变成1,1,1,1,-4,第二次变成1,2,3,4,0,再变成1,2,3,4,-10,第三次变成1,3,6,10,0)(考虑第p次,[1,0,0,0..]做p+1次前缀和得到数组c,那么在r+1位置处减去c[r-l+1],第0次(即第1次开始前)也要减)

然后多个同一阶的差分数列可以直接相加,因此就有了O((n+m)k)的做法

 #include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
const ll md=;
ll n,m;
vector<pll> a1[];
ll an[][];
ll tt[][];//tt[i]是对1,0,0,0,..做i+1次前缀和得到的数组
ll a[];
int main()
{
ll i,j,k,x,y,z;pll t;
scanf("%lld%lld",&n,&m);
for(i=;i<=n;i++)
scanf("%lld",&a[i]);
for(i=;i<=n;i++)
tt[][i]=;
for(i=;i<=;i++)
{
for(j=;j<=n;j++)
{
tt[i][j]=(tt[i][j-]+tt[i-][j]);
(tt[i][j]>=md) && (tt[i][j]-=md);
//printf("at%lld %lld %lld\n",i,j,tt[i][j]);
}
}
for(i=;i<=m;i++)
{
scanf("%lld%lld%lld",&x,&y,&z);
a1[z].pb(mp(x,y));
}
for(i=;i>=;i--)
{
for(j=;j<a1[i].size();j++)
{
x=a1[i][j].fi;y=a1[i][j].se;
++an[i][x];
(an[i][x]>=md) && (an[i][x]-=md);
++y;
for(k=i;k>=;k--)
{
an[k][y]-=tt[i-k][y-x];
//printf("2t%lld %lld %lld\n",i-k,y-x,tt[i-k][y-x]);
//printf("1t%lld %lld %lld\n",k,y,tt[i-k][y-x]);
(an[k][y]<) && (an[k][y]+=md);
}
}
for(k=;k<=n;k++)
{
an[i][k]+=an[i][k-];
(an[i][k]>=md) && (an[i][k]-=md);
}
if(i!=)
{
for(k=;k<=n;k++)
{
an[i-][k]+=an[i][k];
(an[i-][k]>=md) && (an[i-][k]-=md);
}
}
//printf("1t%lld\n",i);
//for(k=1;k<=n;k++)
// printf("%lld ",an[i][k]);
//puts("");
}
for(i=;i<=n;i++)
{
a[i]+=an[][i];
(a[i]>=md) && (a[i]-=md);
}
for(i=;i<=n;i++)
printf("%lld ",a[i]);
return ;
}

http://210.33.19.103/contest/1025

A题(sequence)同此题

Curious Array Codeforces - 407C(高阶差分(?)) || sequence的更多相关文章

  1. 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 ...

  2. codeforces 407C Curious Array

    codeforces 407C Curious Array UPD: 我觉得这个做法比较好理解啊 参考题解:https://www.cnblogs.com/ChopsticksAN/p/4908377 ...

  3. Codeforces 408 E. Curious Array

    $ >Codeforces \space 408 E. Curious Array<$ 题目大意 : 有一个长度为 \(n\) 的序列 \(a\) ,\(m\) 次操作,每一次操作给出 \ ...

  4. Codeforces 601B. Lipshitz Sequence(单调栈)

    Codeforces 601B. Lipshitz Sequence 题意:,q个询问,每次询问给出l,r,求a数组[l,r]中所有子区间的L值的和. 思路:首先要观察到,斜率最大值只会出现在相邻两点 ...

  5. Greg and Array CodeForces 296C 差分数组

    Greg and Array CodeForces 296C 差分数组 题意 是说有n个数,m种操作,这m种操作就是让一段区间内的数增加或则减少,然后有k种控制,这k种控制是说让m种操作中的一段区域内 ...

  6. CodeForces 408E Curious Array(组合数学+差分)

    You've got an array consisting of n integers: a[1], a[2], ..., a[n]. Moreover, there are m queries, ...

  7. Codeforces 626A Robot Sequence(模拟)

    A. Robot Sequence time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...

  8. Petya and Array CodeForces - 1042D (树状数组)

    D. Petya and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. codeforces 622A Infinite Sequence

    A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...

随机推荐

  1. require实现单页应用程序(SPA)

    写了一个测试代码,用require.js配合它的一个插件text.js实现了最简单的单页应用程序,简单的记录一下,方便以后复习, git地址:https://github.com/lily1010/r ...

  2. LightOJ1259 Goldbach`s Conjecture —— 素数表

    题目链接:https://vjudge.net/problem/LightOJ-1259 1259 - Goldbach`s Conjecture    PDF (English) Statistic ...

  3. js正则表达式,密码长度要大于6位,由数字和字母组成

    var pwd = $("#pwd").val(); var reg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,}$/; if(!reg ...

  4. BestCoder7 1002 Little Pony and Alohomora Part I(hdu 4986) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4986 题目意思:有 n 个box(从左到右编号依次为1~n),每个box里面有一个随机的钥匙,有可能这 ...

  5. BestCoder3 1002 BestCoder Sequence(hdu 4908) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4908 题目意思:给出 一个从1~N 的排列你和指定这个排列中的一个中位数m,从这个排列中找出长度为奇数 ...

  6. webrtc 学习资源

    http://www.cnblogs.com/lingyunhu/tag/webrtc%20android%20ios/

  7. hdu-5750 Dertouzos(数论)

    题目链接: Dertouzos Time Limit: 7000/3500 MS (Java/Others)     Memory Limit: 131072/131072 K (Java/Other ...

  8. LSH-局部敏感哈希

    LSH的基本思想是: 将原始数据空间中的两个邻近数据点通过某种映射或变换,使得这两个数据点在变换后的数据空间中仍然相邻的概率很大,而不相邻的数据点被映射到同一个桶的概率很小. 因此,最最重要的就变成了 ...

  9. <编程>比较两种素数表生成算法+计算程序运行时间+通过CMD重定向测试程序

    最近学习加密算法,需要生成素数表,一开始使用简单的循环,从2开始判断.代码如下: #include<iostream> #include<cstdio> #include< ...

  10. [CROATIAN2009] OTOCI

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1180 [算法] 动态树维护森林连通性 时间复杂度 : O(NlogN ^ 2) [代 ...