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 ...
随机推荐
- JAVA长连接demo
http://blog.csdn.net/caomiao2006/article/details/38830475 JAVA长连接demo 2014-08-25 23:20 4767人阅读 评论(2) ...
- HTML<label> 标签的 for 属性
定义和用法 for 属性规定 label 与哪个表单元素绑定. 隐式和显式的联系 标记通常以下面两种方式中的一种来和表单控件相联系:将表单控件作为标记标签的内容,这样的就是隐式形式,或者为 <l ...
- CustomEditor的文件要放在Assets/Editor目录下
using UnityEditor; using UnityEngine; [CustomEditor(typeof(test))] public class testEditor : Editor ...
- OI路上-NOIP100天冲刺计划
学OI已经9个月了,可是自己水平还是那样的弱QWQ. 现在离NOIP还有差不多100天的时间. 晚上辗转反侧发现了自己的一些问题: (1)DP还经常没思路. (2)搜索恶心题还不想写. (3)有时候也 ...
- PhoneGap与WAP站静态化
最近在参与的WAP站项目,决定将所有页面都静态化处理,登录验证.价格数据等都通ajax动态的方式实现.开始这么规划的目前是为了页面提高网站加载速度及SEO,最近看到了一篇报道phonegap buil ...
- HTML 多媒体
1.多媒体简介 Web 上的多媒体指的是音效.音乐.视频和动画,多媒体有多种不同的格式,它可以是听到或看到的任何内容,文字.图片.音乐.音效.录音.电影.动画等等.在互联网上,几乎在所有网站都能发现嵌 ...
- mysql 清空表 Truncate及delete区别
1.delete from 表名[where]; 2.truncate table 表名; 3.delete将mysql表中所有记录一条一条删除到删完 4.truncate保留mysql表的结构,重新 ...
- TDirectory.Move移动或更名目录
使用函数: System.IOUtils.TDirectory.Move 定义: class procedure Move(const SourceDirName, DestDirName: stri ...
- linq any()方法实现sql in()方法的效果
public IQueryable<Vsec009ComSecComp> QueryList(Sec009ComSecCompQueryCondition condition) { var ...
- 服务器慢 mysql-bin.000001文件占满磁盘的原因与解决
发现 VPS 服务器上的网站反应超级慢,简单的重启.重启各主要服务,发现mysql 的反应极其不正常. 一方面是问题,这与站点访问量有关.开始时从mysql 的配置文件 my.cnf 考虑,但志文工作 ...