内个我也不知道哪儿不对,TLE了,说说思路吧

其实思路也没什么说的,就是裸的splay,对于最后一个操作

我们记下每个区间的最长前缀,最长后缀,那么最长子序列就是

前缀,后缀,左子树的后缀+右子树的前缀+自己的值,里取max就行了

更新的时候前缀由左子树的前缀,左子树sum+右子树前缀转移

靠!!!!!!到底哪儿错了!!!!!TLE 你妹啊!!!!!

/**************************************************************
Problem:
User: BLADEVIL
Language: Pascal
Result: Time_Limit_Exceed
****************************************************************/ //By BLADEVIL
const
sroot =-; var
n, m :int64;
a :array[-..] of int64;
root :int64;
father, key, size :array[-..] of int64;
son :array[-..,..] of int64;
flag :array[-..] of boolean;
val, sum :array[-..] of int64;
pred, succ :array[-..] of int64; procedure swap(var a,b:int64);
var
c :int64;
begin
c:=a; a:=b; b:=c;
end; function get_max(a,b:int64):int64;
begin
if a>b then exit(a) else exit(b);
end; procedure update(x:int64);
begin
if x=sroot then exit;
size[x]:=size[son[x,]]+size[son[x,]]+;
sum[x]:=sum[son[x,]]+sum[son[x,]]+key[x];
pred[x]:=get_max(pred[son[x,]],sum[son[x,]]+pred[son[x,]]+key[x]);
succ[x]:=get_max(succ[son[x,]],sum[son[x,]]+succ[son[x,]]+key[x]);
end; procedure c_renew(x,y:int64);
begin
key[x]:=y; sum[x]:=size[x]*y;
pred[x]:=get_max(y,sum[x]);
succ[x]:=get_max(y,sum[x]);
val[x]:=y;
end; procedure r_renew(x:int64);
begin
swap(son[x,],son[x,]);
flag[x]:=not flag[x];
end; procedure push_down(x:int64);
var
l, r :int64;
begin
l:=son[x,]; r:=son[x,];
if flag[x] then
begin
if l<>- then r_renew(l);
if r<>- then r_renew(r);
flag[x]:=false;
end;
if val[x]<> then
begin
if l<>- then c_renew(l,val[x]);
if r<>- then c_renew(r,val[x]);
val[x]:=;
end;
end; function build(l,r:int64):int64;
var
mid :int64;
begin
mid:=(l+r) div ;
key[mid]:=a[mid];
build:=mid;
if mid->=l then
begin
son[mid,]:=build(l,mid-);
father[son[mid,]]:=mid;
end;
if mid+<=r then
begin
son[mid,]:=build(mid+,r);
father[son[mid,]]:=mid;
end;
update(mid);
end; procedure rotate(x,y:int64);
var
f :int64;
begin
push_down(x);
f:=father[x];
son[f,y]:=son[x,y xor ];
father[son[x,y xor ]]:=f;
if f=root then root:=x else
if f=son[father[f],] then
son[father[f],]:=x else
son[father[f],]:=x;
father[x]:=father[f];
father[f]:=x;
son[x,y xor ]:=f;
update(f);
update(x);
end; procedure splay(x,y:int64);
var
u, v :int64;
begin
while father[x]<>y do
if father[father[x]]=y then
rotate(x,ord(x=son[father[x],]))
else
begin
if x=son[father[x],] then u:= else u:=-;
if father[x]=son[father[father[x]],] then v:= else v:=-;
if v*u= then
begin
rotate(father[x],ord(x=son[father[x],]));
rotate(x,ord(x=son[father[x],]));
end else
begin
rotate(x,ord(x=son[father[x],]));
rotate(x,ord(x=son[father[x],]));
end;
end;
update(x);
end; function find(k:int64):int64;
var
t :int64;
begin
t:=root;
while true do
begin
push_down(t);
if size[son[t,]]+=k then exit(t);
if size[son[t,]]+>k then t:=son[t,] else
begin
dec(k,size[son[t,]]+);
t:=son[t,];
end;
end;
end; procedure insert;
var
i :longint;
l, s :int64;
p, q :int64;
begin
read(l,s);
for i:=n+ to n+s do read(a[i]);
readln;
q:=build(n+,n+s);
n:=n+s;
p:=find(l+); splay(p,sroot);
p:=find(l+); splay(p,root);
p:=son[root,];
father[q]:=p;
son[p,]:=q;
update(p);
update(root);
end; procedure delete;
var
p :int64;
l, s :int64;
begin
readln(l,s);
p:=find(l); splay(p,sroot);
p:=find(l+s+); splay(p,root);
p:=son[son[root,],];
father[p]:=-;
son[son[root,],]:=-;
update(son[root,]);
update(root);
end; procedure change;
var
l, s, c :int64;
p :int64;
begin
readln(l,s,c);
p:=find(l); splay(p,sroot);
p:=find(l+s+); splay(p,root);
p:=son[son[root,],];
c_renew(p,c);
update(son[root,]);
update(root);
end; procedure reverse;
var
p :int64;
l, s :int64;
begin
readln(l,s);
p:=find(l); splay(p,sroot);
p:=find(l+s+); splay(p,root);
p:=son[son[root,],];
r_renew(p);
//update(son[root,]);
//update(root);
end; procedure get_sum;
var
l, s :int64;
p :int64;
begin
readln(l,s);
p:=find(l); splay(p,sroot);
p:=find(l+s+); splay(p,root);
p:=son[son[root,],];
writeln(sum[p]);
end; procedure max_sum;
var
l, r :int64;
begin
readln;
l:=son[root,]; r:=son[root,];
writeln(get_max(succ[l]+pred[r]+key[root],get_max(pred[l],succ[r])));
end; procedure main;
var
i :longint;
ss :ansistring;
ch :char;
begin
fillchar(son,sizeof(son),);
read(n,m);
for i:= to n do read(a[i]);
inc(n);
root:=build(,n);
father[root]:=sroot;
readln;
for i:= to m do
begin
read(ch);
ss:='';
while ch<>' ' do
begin
ss:=ss+ch;
read(ch);
if ss='MAX-SUM' then break;
end;
if ss='INSERT' then insert else
if ss='DELETE' then delete else
if ss='MAKE-SAME' then change else
if ss='REVERSE' then reverse else
if ss='GET-SUM' then get_sum else
if ss='MAX-SUM' then max_sum;
end;
end; begin
main;
end.

bzoj 1500 修改区间 splay的更多相关文章

  1. [BZOJ 1500]维修数列 [Splay Tree从进阶到住院]

    历尽艰辛终于A掉了这题QwQ 贴COGS评论区几句话=.= 策爷:"splay/块状链表的自虐题.".深刻理解到如果没有M倾向就不要去写这题了.. -Chenyao2333 记得b ...

  2. BZOJ 1500/Luogu 2042 - 维修数列 - [NOI2005][Splay]

    题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1500 题目链接:https://www.luogu.org/problemnew/sho ...

  3. [BZOJ 1500] [NOI2005] 维修数列

    题目链接:BZOJ - 1500 题目分析 我要先说一下,这道题我写了一晚上,然后Debug了一整个白天..........再一次被自己的蒟蒻程度震惊= = 这道题是传说中的Splay维护数列的Bos ...

  4. 少年,想学带修改主席树吗 | BZOJ1901 带修改区间第k小

    少年,想学带修改主席树吗 | BZOJ1901 带修改区间第k小 有一道题(BZOJ 1901)是这样的:n个数,m个询问,询问有两种:修改某个数/询问区间第k小. 不带修改的区间第k小用主席树很好写 ...

  5. [BZOJ 1500] 维护序列

    Link: BZOJ 1500 传送门 Solution: 可能平衡树维护序列的所有操作都在这了吧…… 对序列的维护$fhq treap$和$Splay$都能做 有几个注意点: 1.维护序列时始终记得 ...

  6. 【ZOJ2112】【整体二分+树状数组】带修改区间第k大

    The Company Dynamic Rankings has developed a new kind of computer that is no longer satisfied with t ...

  7. 【树状数组套主席树】带修改区间K大数

    P2617 Dynamic Rankings 题目描述给定一个含有n个数的序列a[1],a[2],a[3]……a[n],程序必须回答这样的询问:对于给定的i,j,k,在a[i],a[i+1],a[i+ ...

  8. HDU 4417.Super Mario-可持久化线段树(无修改区间小于等于H的数的个数)

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  9. HDU 2665.Kth number-可持久化线段树(无修改区间第K小)模板 (POJ 2104.K-th Number 、洛谷 P3834 【模板】可持久化线段树 1(主席树)只是输入格式不一样,其他几乎都一样的)

    Kth number Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

随机推荐

  1. CodeForces-1132F Clear the String

    题目链接 https://vjudge.net/problem/CodeForces-1132F 题面 Description You are given a string \(s\) of leng ...

  2. 拉普拉斯矩阵(Laplacian Matrix) 及半正定性证明

    摘自 https://blog.csdn.net/beiyangdashu/article/details/49300479 和 https://en.wikipedia.org/wiki/Lapla ...

  3. truffle的调用nodeJs的问题

    Truffle3.0集成NodeJS并完全跑通(附详细实例,可能的错误) 升级到Truffle3.0 如果之前安装的是Truffle2.0版本,需要主动升级到Truffle3.0,两者的语法变化有点大 ...

  4. 【tips】【词频统计】中可能用到的资源,以C++为例

    前言 我不知道C#什么情况,不过C++里面,什么参数都不传时,argc=1,argv里面是当前程序名.当你传入dir时,argc=2,当你传入-e dir时,argc=3. 这个文章十分适合有一点C语 ...

  5. 【转】Virtual DOM

    前言 React 好像已经火了很久很久,以致于我们对于 Virtual DOM 这个词都已经很熟悉了,网上也有非常多的介绍 React.Virtual DOM 的文章.但是直到前不久我专门花时间去学习 ...

  6. asp.net Forms登录核心方法

    登录核心方法: private void Signin(string curUserId) { System.Web.Security.FormsAuthenticationTicket tk = , ...

  7. tar 加密压缩和解密解压

    加密压缩 tar -czvf - file | openssl des3 -salt -k password -out /path/to/file.tar.gz 解密解压 openssl des3 - ...

  8. el-input为数字时验证问题

    el-input为数字时,初始有值,怎么还会验证不能为空? html: <el-form-item label="审核数量:" prop="checkNum&quo ...

  9. springboot ueditor 使用心得

    1.将ueditor引入项目中会发现,图片不能上传,返回值意思是因配置文件错误,导致图片无法上传 默认情况是使用jsp初始配置文件,这就需要项目支持jsp解析 在maven中引入 <!--添加对 ...

  10. c# 调用 matlab 引发初始化错误 异常

    1. 除了matlab 编译的DLL 意外还需要引用 MWArray.dll 这个dill 在安装了  MCRInstaller.exe(matlab运行环境之后就会有了): 2. 最重要的一点.ne ...