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. vue定义全局变量和全局方法

    一.全局引入文件 1.先定义共用组件 common.vue <script type="text/javascript"> // 定义一些公共的属性和方法 const ...

  2. Codeforces Round #417 (Div. 2) B. Sagheer, the Hausmeister —— DP

    题目链接:http://codeforces.com/problemset/problem/812/B B. Sagheer, the Hausmeister time limit per test ...

  3. ansible-playbook unarchive模块

    先 进行  pause模块的 记录: pause 在playbook执行的过程中暂停一定时间或者提示用户进行某些操作 常用参数: minutes:暂停多少分钟 seconds:暂停多少秒 prompt ...

  4. Memory Notification: Library Cache Object loaded into SGA

    问题现象: 数据库服务器可以ping通,但SSH连接不了:应用.plsqldeveloper 也都连接不了.事情到了这个地步,只能重启服务器. 服务器环境:oracle10.2.0.1 +rhel5. ...

  5. 洛谷【P839】【NOI导刊】——数页码

    题面 一道找规律好题... 首先,我们肯定只能一位一位的统计答案,考虑从高位向低位统计,显然这样要方便的多. 对于第i位,我们统计从$a[i+1]*10^i+0$到$a[i+1]*10^i+a[i]* ...

  6. observer远程监控服务器

    因为需要监控服务器的状况,所以要使用工具observer.但是observer是采用wxWidget开发的,远程机器没有此环境.于是在windows机器上装了虚拟机ubuntu,又折腾erlang和w ...

  7. SVN与CVS比较-怎度网

    SVN与CVS比较 所有的文档都显示SVN可以取代CVS,同时SVN的问题和缺点都被隐藏了.不幸的是,我们并不认为SVN是CVS的替代品,尽管很多缺陷都被修改了.更有甚者,它甚至让人重回VSS.CVS ...

  8. python multiprocessing多进程应用

    multiprocessing包是Python中的多进程管理包,可以利用multiprocessing.Process对象来创建进程,Process对象拥有is_alive().join([timeo ...

  9. maven目录结构

    groupId的值是项目的包名 artifactId的值是模块名,建议使用项目名

  10. UNP总结 Chapter 12~14 IPv4与IPv6的互操作性、守护进程和inet超级服务器、高级I/O函数

    一.IPv4与IPv6的互操作性 1.IPv4客户与IPv6服务器 拥有双重协议栈的主机的一个基本特性就是:其上运行的IPv6服务器既能应付IPv4客户,又能应付IPv6客户.这是通过使用IPv4映射 ...