Curious Array Codeforces - 407C(高阶差分(?)) || sequence
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的更多相关文章
- 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 ...
- codeforces 407C Curious Array
codeforces 407C Curious Array UPD: 我觉得这个做法比较好理解啊 参考题解:https://www.cnblogs.com/ChopsticksAN/p/4908377 ...
- Codeforces 408 E. Curious Array
$ >Codeforces \space 408 E. Curious Array<$ 题目大意 : 有一个长度为 \(n\) 的序列 \(a\) ,\(m\) 次操作,每一次操作给出 \ ...
- Codeforces 601B. Lipshitz Sequence(单调栈)
Codeforces 601B. Lipshitz Sequence 题意:,q个询问,每次询问给出l,r,求a数组[l,r]中所有子区间的L值的和. 思路:首先要观察到,斜率最大值只会出现在相邻两点 ...
- Greg and Array CodeForces 296C 差分数组
Greg and Array CodeForces 296C 差分数组 题意 是说有n个数,m种操作,这m种操作就是让一段区间内的数增加或则减少,然后有k种控制,这k种控制是说让m种操作中的一段区域内 ...
- CodeForces 408E Curious Array(组合数学+差分)
You've got an array consisting of n integers: a[1], a[2], ..., a[n]. Moreover, there are m queries, ...
- Codeforces 626A Robot Sequence(模拟)
A. Robot Sequence time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
- Petya and Array CodeForces - 1042D (树状数组)
D. Petya and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- codeforces 622A Infinite Sequence
A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...
随机推荐
- Codeforces Round #376 (Div. 2) A. Night at the Museum —— 循环轴
题目链接: http://codeforces.com/contest/731/problem/A A. Night at the Museum time limit per test 1 secon ...
- python:将字典转化为数据框
my_dict = {,,} import pandas as pd pd.Series(my_dict) fuck i you dtype: int64 一个key只有一个value的字典如果直接转 ...
- HTML标签深入学习系列(1)——注释标签 <!-- -->
一.HTML注释的语法 <!--注释内容--> 二.HTML注释的用处 1.普通注释(增强代码的可读性) 方便别人:方便其它程序员了解你的代码 方便自己:方便以后对自己代码的理解与修改等等 ...
- 002-Fatal error in launcher: Unable to create process using '""
这个问题出在先安装Python3之后再安装python2, 使用pip安装的时候出现的故障 原因是python3的环境变量写入在了用户的环境变量上 但是一旦安装python2之后, Python会把信 ...
- 【UVA12779占位】Largest Circle
几何题,希望有时间回来解决掉.
- HDU3065(AC自动机入门题)
病毒侵袭持续中 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- 896C
ODT/珂朵莉树 原来这个东西很咸鱼,只能数据随机情况下nloglogn,不过作为卡常还是很好的 大概就是维护区间,值相同的并且连续当成一个区间存在set里,每次区间操作强行分裂就行了. 复杂度因为是 ...
- PHP 时间戳
<?php php 获取今日.昨日.上周.本月的起始时间戳和结束时间戳的方法,主要使用到了 php 的时间函数 mktime.下面首先还是直奔主题以示例说明如何使用 mktime 获取今日.昨日 ...
- tomcat的bin文件夹下的.bat和.sh文件
tomcat的bin文件夹中存在一份.bat文件和相对应的.sh文件,一个是为了在window系统上执行的文件,另一个是linux下的批处理文件.例如:startup.bat和startup.sh. ...
- Swift3.0 轮播图
使用三个UIButton实现无限轮播:https://github.com/LXfeiYu/LXCarouselImages.git 喜欢的朋友给个星!!! 功能: 1.可以选择开启和关闭定时器 2. ...