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. POJ1006 Biorhythms —— 中国剩余定理

    题目链接:https://vjudge.net/problem/POJ-1006 Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total ...

  2. 基于BASYS2的VHDL程序——交通灯(状态机版)

    请尊重作者版权,转载注明源地址:http://www.cnblogs.com/connorzx/p/3694618.html 使用了状态机,增加了可读性和用户体验. library IEEE; use ...

  3. 理解HTML解析过程

    浏览器解析html的过程是:接受网络数据->将二进制码变成字符->将字符变为unicode code points.->tokenizer ->tree constructor ...

  4. HDFS副本设置——默认3

    首先 dfs.replication这个参数是个client参数,即node level参数.需要在每台datanode上设置. 其实默认为3个副本已经够用了,设置太多也没什么用. 一个文件,上传到h ...

  5. http://www.cnblogs.com/yaozhenfa/archive/2015/06/14/4574898.html

    笔者这里采用的是mongoDB官网推荐使用.net驱动: http://mongodb.github.io/mongo-csharp-driver/2.0/getting_started/quick_ ...

  6. php封装数据库mysql, mysqli

    <?php header("content-type:text/html;charset=utf-8"); class db{    //私有的静态属性    private ...

  7. Chkrootkit安装配置教程 – Linux后门入侵检测

    rootkit从浅显的层面来讲即一种具有自我隐蔽性的后门程序,它往往被入侵者作为一种入侵工具.通过rootkit,入侵者可以偷偷控制被入侵的电脑,因此危害巨大.chkrootkit是一个Linux系统 ...

  8. XML 解析中 SelectSingleNode 与 SelectNodes 使用通配符介绍

    俺是 XML XPath的新手,最近因为项目需要,研究了一下基本的两个函数 SelectSingleNode和SelectNodes 是如何实用通配符的,分享以下基本经验: 假设有段XML 如下所示: ...

  9. Google 马来西亚主页被黑

    互联网并没有想象中安全,Google 马来西亚主页被黑 | TheVerge 消… 查阅全文 ›

  10. Asset Catalog Help (三)---Adding Image Sets

    Adding Image Sets Organize versions of your images in image sets, which you can add to an asset cata ...