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. java反射技术实例

    java反射技术实例​1. [代码][Java]代码     package com.gufengxiachen.java.reflectiontest; public class Person {p ...

  2. IOS开发学习笔记(1)-----UILabel 详解

    1. [代码][C/C++]代码     //创建uilabelUILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(20, 40, ...

  3. linux应用之gcc编译器的安装及使用

    gcc是linux系统下功能十分强大的编译器. 本人使用的是CentOS 6.6 64位系统,由于在安装系统的时候并没有勾选安装gcc编译器,因此需要自行安装gcc编译器. 使用yum安装gcc 对于 ...

  4. UIButton设置为圆形按钮并增加边框

    设置按钮的长和宽尺寸一致(即为正方形),然后将圆角半径设为边长的一半,即形成一个圆形 UIButton *btn = [UIButton buttonWithType:UIButtonTypeSyst ...

  5. ACM2016级新生第三周训练赛

    本次是弱校题解-比赛链接 备用链接 题目还是比较基础,比较简单.认真补题,学会学习. A -人见人爱A^B 题解: 求 A的B次方,我们可以用循环进行累乘操作,进而计算出次方.因为题目要求只需要求出最 ...

  6. 插入排序(InsertionSort)

    位置p上的元素存储于tmp(第一趟p通常取1),而(位置p之前)所有更大的元素都向右移动一个位置. 然后tmp被放在正确的位置上. 代码: public class InsertionSort { p ...

  7. MTK USB 子系统

    一.USB 子系统初始化 1. kernel/drivers/usb/core/usb.c subsys_initcall(usb_init); static int __init usb_init( ...

  8. nohup command > myout.file 2>&1 &

    nohup command > myout.file 2>&1 &

  9. libvirt kvm云主机监控

    libvirt

  10. StarUML中时序图

    StarUML中时序图 在看时序图的例子的时候,发现有些的时序图上有小人的图标,可是一些UML工具却没有找到小人的图标,这让我很闹心,一直没解决,今天终于将该问题给解决了.解决这个问题来自于网上的一个 ...