内个我也不知道哪儿不对,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. js学习日记-new Object和Object.create到底干了啥

    function Car () { this.color = "red"; } Car.prototype.sayHi=function(){ console.log('你好') ...

  2. zabbix 2.2 调小监控值

    zabbix_agent默认disk下小于0%告警 调小到5% 组态 > 模板 选择需要的模板的触发器 例如 Template OS Windows 选择触发器 - 探索规则 - 触发器类型  ...

  3. SQL 语句中 exists和not exists的用法

    exists       (sql       返回结果集,为真)   not       exists       (sql       不返回结果集,为真) 如下: 表A ID   NAME    ...

  4. react实现网站换肤功能

    一.目标   提供几种主题色给用户选择,然后根据用户的选择改变应用的主题色: 二.实现原理   1.准备不同主题色的样式文件:   2.将用户的选择记录在本地缓存中:   3.每次进入应用时,读取缓存 ...

  5. 【Linux运维】LNMP环境配置

    安装准备: Centos7.3 MYSQL5.6 PHP5.6 NGINX1.10.3 一.安装Mysql mysql:[root@host129 src]#cd /usr/local/src/ [r ...

  6. 测试理论-selenium的工作原理

  7. elementUI中的el-form怎么使用正则进行验证

    http://element.eleme.io/#/zh-CN/component/form里给出了一个form验证的例子,但是都是使用el-form带有的验证规则,怎么使用自己定义的规则进行验证呢? ...

  8. Java面试题-字符串操作

    题目:输入一行字符,分别统计出其中英文字母,空格,数字和其他字符个数 //创建一个容器,用来保存结果,英文字母空格数组和其他字符做key,个数为value Map<String,Integer& ...

  9. 【bzoj4813】[Cqoi2017]小Q的棋盘 树上dfs+贪心

    题目描述 小Q正在设计一种棋类游戏.在小Q设计的游戏中,棋子可以放在棋盘上的格点中.某些格点之间有连线,棋子只能在有连线的格点之间移动.整个棋盘上共有V个格点,编号为0,1,2…,V-1,它们是连通的 ...

  10. LeetCode -- Merge Two Sorted Linked List

    Question: Merge two sorted linked lists and return it as a new list. The new list should be made by ...