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 Web项目整合开发(PDF)
实战突击: Java Web项目整合开发(PDF)
- 3.redis.3.2 下载,安装、配置、使用、集群主从创建 - 3
当然,集群最主要的就是配置文件: 简单配置如下, port 7001 bind 127.0.0.1 databases 16 appendonly yes appendfilename "a ...
- Solr4.8.1与Tomcat7整合
Solr4.8.1和Tomcat7都可以到官方网站去下载,我这里就不多说了,如下图. 这里我们首先解压Solr-4.8.1.zip,再解压Tomcat,解压后,再在当前文件夹下建2个文件夹,一个用来放 ...
- Ext.Net学习笔记05:Ext.Net DirectEvents用法详解
Ext.Net通过DirectEvents进行服务器端异步的事件处理.我们在 Ext.Net用法概览 这篇中已经简单的介绍了DirectEvents,今天我们将详细的介绍一下DirectEvents. ...
- O-C相关06:self和super关键字介绍——self关键字
self关键字介绍 1.self和super OC 版权声明:本文为博主原创文章,未经博主允许不得转载. posted @ 2015-08-04 12:46 王刚韧(wanghy_iOS) 阅读(.. ...
- javascript——四种函数调用形式
此文的目的是分析函数的四种调用形式,弄清楚函数中this的意义,明确构造函对象的过程,学会使用上下文调用函数. 在JavaScript中,函数是一等公民,函数在JavaScript中是一个数据类型,而 ...
- 设计模式之开篇(C#语法)
很长时间没有写文章了,前段时间写的C#语法糖分享得到有很多朋友支持,这个也使得我有信心继续分享下去,在这里非常感谢大家!这次开始给大家分享一下设计模式,我个人觉得设计模式也对于我们提高个人技术水平来说 ...
- IOS视图旋转可放大缩小
- (IBAction)hideBut:(id)sender { if (self.flg) { [UIView animateWithDuration:0.3 animations:^{ self. ...
- python 自动化之路 logging日志模块
logging 日志模块 http://python.usyiyi.cn/python_278/library/logging.html 中文官方http://blog.csdn.net/zyz511 ...
- html5写的一个时钟
看到的一个html5写的时钟 <!doctype> <html> <head> <script> window.onload=function(){ v ...