bzoj 1500 修改区间 splay
内个我也不知道哪儿不对,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的更多相关文章
- [BZOJ 1500]维修数列 [Splay Tree从进阶到住院]
历尽艰辛终于A掉了这题QwQ 贴COGS评论区几句话=.= 策爷:"splay/块状链表的自虐题.".深刻理解到如果没有M倾向就不要去写这题了.. -Chenyao2333 记得b ...
- BZOJ 1500/Luogu 2042 - 维修数列 - [NOI2005][Splay]
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1500 题目链接:https://www.luogu.org/problemnew/sho ...
- [BZOJ 1500] [NOI2005] 维修数列
题目链接:BZOJ - 1500 题目分析 我要先说一下,这道题我写了一晚上,然后Debug了一整个白天..........再一次被自己的蒟蒻程度震惊= = 这道题是传说中的Splay维护数列的Bos ...
- 少年,想学带修改主席树吗 | BZOJ1901 带修改区间第k小
少年,想学带修改主席树吗 | BZOJ1901 带修改区间第k小 有一道题(BZOJ 1901)是这样的:n个数,m个询问,询问有两种:修改某个数/询问区间第k小. 不带修改的区间第k小用主席树很好写 ...
- [BZOJ 1500] 维护序列
Link: BZOJ 1500 传送门 Solution: 可能平衡树维护序列的所有操作都在这了吧…… 对序列的维护$fhq treap$和$Splay$都能做 有几个注意点: 1.维护序列时始终记得 ...
- 【ZOJ2112】【整体二分+树状数组】带修改区间第k大
The Company Dynamic Rankings has developed a new kind of computer that is no longer satisfied with t ...
- 【树状数组套主席树】带修改区间K大数
P2617 Dynamic Rankings 题目描述给定一个含有n个数的序列a[1],a[2],a[3]……a[n],程序必须回答这样的询问:对于给定的i,j,k,在a[i],a[i+1],a[i+ ...
- HDU 4417.Super Mario-可持久化线段树(无修改区间小于等于H的数的个数)
Super Mario Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- 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 ...
随机推荐
- CCF-NOIP-2018 提高组(复赛) 模拟试题(三)
T1 取球游戏 问题描述 现有\(N\)个小球,依次编号为\(1\)到\(N\),这些小球除了编号以外没有任何区别.从这\(N\)个小球中取出\(M\)个,请问有多少种取球方案使得在取出的\(M\)个 ...
- apollo命令行传入参数
Java apollo客户端运行配置 需要在META-INF中创建app.properties文件,以配置app.id 还需要在/opt/settings/server.properties或C:/o ...
- CCS Font 知识整理总结
总是搞不懂 CCS 中如何正确的使用字体,这下明白了. 1.什么是 font-face font-face 顾名思义,就是文字的脸.字体是文字的外在形式,就是文字的风格,是文字的外衣.比如行书.楷书. ...
- 用JAVA写一个多线程程序,写四个线程,其中二个对一个变量加1,另外二个对一个变量减1
package com.ljn.base; /** * @author lijinnan * @date:2013-9-12 上午9:55:32 */ public class IncDecThrea ...
- css字体图标的制作和使用。
css字体图标的制作和使用. 在项目开发的过程中,我们会经常用到一些图标.但是我们在使用这些图标时,往往会遇到失真的情况,而且图片数量很多的话,页面加载就越慢.所以,我们可以使用字体图标的方式来显示图 ...
- Java 中的异常和处理详解(转载)
原文出处: 代码钢琴家 简介 程序运行时,发生的不被期望的事件,它阻止了程序按照程序员的预期正常执行,这就是异常.异常发生时,是任程序自生自灭,立刻退出终止,还是输出错误给用户?或者用C语言风格:用函 ...
- poi解析excel出现格式不正确
后缀为xlsx的excel做系统导入时出现bug: Strict OOXML isn't currently supported, please see bug #57699 为了同时兼容03.07及 ...
- el-checkbox根据是否被选中执行不同的操作
直接给el-checkbox绑定点击事件是没有效果的,因为它会被解析成其他形式的html,el-checkbox只是一个类名,因此,使用ts和jquery动态绑定事件: mounted() { $(& ...
- [剑指Offer] 13.调整数组顺序使奇数位于偶数前面
题目描述 输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有的奇数位于数组的前半部分,所有的偶数位于位于数组的后半部分,并保证奇数和奇数,偶数和偶数之间的相对位置不变. [思路1]用2n ...
- Hibernate技术入门
ORM原理 ORM(Object Relational Mapping)是对象到关系的映射,它的作用是在关系数据库和对象之间做一个自动映射,将数据库中的数据表映射成对象(持久化类),对关系型数据库以对 ...