BZOJ3188: [Coci 2011]Upit
3188: [Coci 2011]Upit
Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 72 Solved: 24
[Submit][Status]
Description

你需要维护一个序列,支持以下4种操作。一,将区间(u,v)的数覆盖为C;二,
将区间(u,v)的数依次加上一个以C为首项、C为公差的等差数列;三,将数C插入
第i个位置;四,查询区间(u,v)的数的和。序列最初有n个数,一共会有Q次操
作。保证结果在longlong范围内。
Input
Output
Sample Input
1 2 3 4 5
1 5 5 0
4 4 5
4 5 5
2 1 5 1
4 1 5
Sample Output
0
25
HINT
n, Q <= 100,000.
Source
问题主要在操作2
如果我们给l-r加上一个以x为首项,y为公差的等差数列,v[k]和sum[k]都很容易计算。
我们发现两次的操作是可以合并的 加上以x1为首项,y1为公差,再加上x2为首项,y2为公差,相当于加上了一个以x1+x2为首项,以y1+y2为公差的等差数列,这样我们就可以打lazy了!
然后剩下的就是注意两个lazy的下传顺序了。
代码:
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 500000+5
#define maxm 500+100
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define mod 1000000007
using namespace std;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
int n,q,rt,t1,t2,tot,fa[maxn],c[maxn][];
ll s[maxn],sum[maxn],v[maxn],tag[maxn][];
inline void pushup(int x)
{
int l=c[x][],r=c[x][];
s[x]=s[l]+s[r]+;
sum[x]=sum[l]+sum[r]+v[x];
}
inline void rotate(int x,int &k)
{
int y=fa[x],z=fa[y],l=c[y][]==x,r=l^;
if(y!=k)c[z][c[z][]==y]=x;else k=x;
fa[x]=z;fa[y]=x;fa[c[x][r]]=y;
c[y][l]=c[x][r];c[x][r]=y;
pushup(y);pushup(x);
}
inline void splay(int x,int &k)
{
while(x!=k)
{
int y=fa[x],z=fa[y];
if(y!=k)
{
if(c[z][]==y^c[y][]==x)rotate(x,k);else rotate(y,k);
}
rotate(x,k);
}
}
inline void change(int x,ll z)
{
sum[x]=s[x]*z;v[x]=z;
tag[x][]=;tag[x][]=z;
tag[x][]=tag[x][]=;
}
inline void update(int x,ll y,ll z)
{
int l=c[x][],r=c[x][];
v[x]+=y+s[l]*z;
sum[x]+=s[x]*y+s[x]*(s[x]-)/(ll)*z;
tag[x][]+=y;tag[x][]+=z;
}
inline void pushdown(int x)
{
int l=c[x][],r=c[x][];
if(tag[x][]){change(l,tag[x][]);change(r,tag[x][]);tag[x][]=;}
if(tag[x][]||tag[x][])
{
update(l,tag[x][],tag[x][]);
update(r,tag[x][]+(s[l]+)*tag[x][],tag[x][]);
tag[x][]=tag[x][]=;
}
}
inline int find(int x,int k)
{
pushdown(x);
int l=c[x][],r=c[x][];
if(s[l]+==k)return x;
else if(s[l]>=k)return find(l,k);
else return find(r,k-s[l]-);
}
inline void split(int l,int r)
{
t1=find(rt,l);t2=find(rt,r);
splay(t1,rt);splay(t2,c[t1][]);
}
inline void build(int l,int r,int f)
{
if(l>r)return;
int x=(l+r)>>;
fa[x]=f;c[f][x>f]=x;
if(l==r){s[x]=;sum[x]=v[x];return;}
build(l,x-,x);build(x+,r,x);
pushup(x);
}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();q=read();
for2(i,,n+)v[i]=read();tot=n+;rt=(+n+)>>;
build(,n+,);
while(q--)
{
int ch=read();
if(ch==){int x=read();split(x,x+);fa[c[t2][]=++tot]=t2;sum[tot]=v[tot]=read();s[tot]=;}
else
{
int x=read(),y=read();
split(x,y+);
if(ch==)change(c[t2][],read());
else if(ch==)printf("%lld\n",sum[c[t2][]]);
else
{
ll z=read();update(c[t2][],z,z);
}
}
pushup(t2);pushup(t1);
}
return ;
}
BZOJ3188: [Coci 2011]Upit的更多相关文章
- bzoj3188 [Coci 2011]Upit(分块)
Time Limit: 10 Sec Memory Limit: 128 MB Description 你需要维护一个序列,支持以下4种操作.一,将区间(u,v)的数覆盖为C:二,将区间(u,v)的 ...
- Dbzoj#3188. [Coci 2011]Upit
写道数据结构练练手哈哈哈 // It is made by XZZ #include<cstdio> #include<algorithm> #include<cstdl ...
- [SinGuLaRiTy] COCI 2011~2012 #2
[SinGuLaRiTy-1008] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. 测试题目 对于所有的题目:Time Limit:1s ...
- 【BZOJ 3188】【Coci 2011】Upit Splay模板题
转啊转终于转出来了,然而我的模板跟陈竞潇学长的模板一模一样,还是太弱啊,第一次用指针. #include<cstdio> #include<cstring> #include& ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- 【vijos】1791 骑士的旅行(特殊的技巧)
https://vijos.org/p/1791 暴力的话只想到bfs,然后估计是状态超了才得20分. 噗,为啥暴力就不能想得简单点QAQ.....这种思想很好啊. 这一题我看了题解后不得不说我竟然没 ...
- TOJ4505: KOSARE
TOJ4505: KOSARE Time Limit(Common/Java):10000MS/30000MS Memory Limit:65536KByteTotal Submit: 11 ...
- [C#项目开源] MongoDB 可视化管理工具 (2011年10月-至今)
正文 该项目从2011年10月开始开发,知道现在已经有整整5年了.MongoDB也从一开始的大红大紫到现在趋于平淡. MongoCola这个工具在一开始定位的时候只是一个Windows版本的工具,期间 ...
- BZOJ 2440: [中山市选2011]完全平方数 [容斥原理 莫比乌斯函数]
2440: [中山市选2011]完全平方数 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 3028 Solved: 1460[Submit][Sta ...
随机推荐
- 学习XAML中的一些基本语法
1:slider 控件 2:x:名称空间的使用 3:事件处理器 event handler { <Button x:Name="button1" Click=" ...
- Apache配置命令
Apache的主配置文件: 1.DocumentRoot——指定网站的根目录 提示:该目录必须存在.目录上不能有汉字或空格. 2.DirectoryIndex (1)描述:设置网站的默认首页文件.访问 ...
- iOS NSNumber语法糖
BOOL equal; NSNumber * num1 = [NSNumber numberWithInteger:]; NSNumber * num2 = @; equal = [num1 isEq ...
- java新手笔记3 运算符&循环
1.包 2.运算符 public class Operator { public static void main(String[] args) { int a = 5; System.out.pri ...
- Codevs 3729 飞扬的小鸟
飞扬的小鸟 标签 动态规划 NOIp提高组 2014 难度 提高+/省选- 题目描述 Flappy Bird 是一款风靡一时的休闲手机游戏.玩家需要不断控制点击手机屏幕的频率来调节小鸟的飞行高度,让小 ...
- cocos2dx如何添加popScene的场景动画
说明 我们很容易在pushScene中添加动画 Director::getInstance()->pushScene(TransitionSlideInB::create(SCENE_TIME, ...
- centOS 6.4 vsftpd 500 illegal port command
原先配置好的vsftpd突然不行了,不知为啥,感觉跟网络有关,这个网络总是有dns拦截的现象,..小公司.真烦人,用联通线路就没问题, 但同事就是连不上,我的笔记本却可以连接上..我的ubuntn,同 ...
- mac 下 sublime text 运行c++/c 不能使用scanf/cin
{ "cmd": ["g++", "${file}", "-o", "${file_path}/${file_ ...
- 网站开发常用jQuery插件总结(11)折叠插件Akordeon
实现折叠菜单,可以完全不使用插件.如果使用jquery的话,实现起来也比较简单,我们只需要定义折叠菜单的样式,然后使用jquery中的渐隐渐现就可以了.如果我们自己写折叠菜单,可以方便的使用我们自己的 ...
- Google Map 自定义 infowindow
最近做的东西用到了infowindow,不过google提供的样式太难看了,于是想改变一下样式.看了一下好像infowindow的样式不太好改. 查了半天资料,看到一个infobox,感觉真的挺好用. ...