内个我也不知道哪儿不对,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.

最新文章

  1. Scala 笔记
  2. CentOS6.5 简单配置Nginx + tomcat
  3. MSSQL 2012 拒绝了对对象 &#39;extended_properties&#39; (数据库 &#39;mssqlsystemresource&#39;,架构 &#39;sys&#39;)的 SELECT 权限
  4. unix文件操作函数
  5. SQL语句在数据库中是如何执行的
  6. Joy of Programming: Understanding Bit-fields in C
  7. [转载]关于安装Android Studio的一些问题的解决方法
  8. iOS - 应用程序国际化
  9. SQL Server 添加一条数据获取自动增长列的几种方法
  10. 页面的拼装配置Appache SSI
  11. jQuery + json 实现省市区三级联动
  12. C语言实现的猜数字小游戏(主要是对于自定义函数的运用)
  13. jQuery之animate中的queue
  14. 5.JVM的内存区域划分
  15. 调用微信JS-SDK配置签名
  16. transition多个属性同时渐变(left/top)
  17. sqlserver 2008 r2 下载地址和序列号,可用迅雷下载
  18. mysql 数据字典
  19. 【timeisprecious】【JavaScript 】JavaScript String 对象
  20. 记一发Hive on tez的配置(Hive 3.1.1, Hadoop 3.0.3, Tez 0.9.1)

热门文章

  1. Scala function programming
  2. js学习日记-隐式转换相关的坑及知识
  3. hdu1505City Game(动态规划)
  4. linux ----- Vim进入和退出命令
  5. Could not resolve com.android.support.constraint:constraint-layout:1.1.3.
  6. ssh问题_2
  7. htm,html,xhtml,xml,xsl,dhtml,shtm和shtml的区分
  8. 【历史】- Unix英雄传:图文细数十五位计算机先驱
  9. WCF身份验证一:消息安全模式之&lt;Certificate&gt;身份验证
  10. Linux笔记二