一杯茶,一包烟,一道水题调一天

题面

这题一眼看上去就是个裸板子对吧

本来以为要两棵splay,读了一下题发现店里只能有一种生物(人/宠物)

所以记录一下当前店里的状态就行了

老年手速20min过编译,

嗯?

检查了30min发现没取mod

嗯?

检查调试对拍了2h+30min重构代码

发现Splay打错了

int nxt()
{
if(cnt[root]>)return root;
int now=son[root][];
while(son[now][])now=son[now][];
return now;
}
//√
int nxt()
{
if(cnt[root]>)return root;
int now=son[root][];
while(son[now][])now=son[now][];
return now;
}
//×

我打的时候在想什么啊啊啊啊啊身败名裂辽

总结:数据结构题如果迟迟调不过 不如检查一下是否在数据结构本身上犯了白痴错误

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
const int N=,mod=1e6,inf=0x3f3f3f3f;
int fa[N],cnt[N],son[N][],size[N],key[N],type,root;
int n,num[];
void clear(int x)
{
fa[x]=cnt[x]=son[x][]=son[x][]=size[x]=key[x]=;
}
bool judge(int x)
{
return son[fa[x]][]==x;
}
void up(int x)
{
if(x)
{
size[x]=cnt[x];
if(son[x][])size[x]+=size[son[x][]];
if(son[x][])size[x]+=size[son[x][]];
}
}
void rotate(int x)
{
int old=fa[x],oldf=fa[old],lr=judge(x);
son[old][lr]=son[x][lr^];
fa[son[old][lr]]=old;
son[x][lr^]=old;
fa[old]=x;
fa[x]=oldf;
if(oldf)son[oldf][son[oldf][]==old]=x;
up(old);up(x);
}
void splay(int x)
{
for(int f;f=fa[x];rotate(x))
if(fa[f])rotate(judge(x)==judge(f)?f:x);
root=x;
}
void ins(int x)
{
if(!root)
{
type++;
key[type]=x;
root=type;
cnt[type]=size[type]=;
fa[type]=son[type][]=son[type][]=;
return ;
}
int now=root,f=;
while()
{
if(x==key[now])
{
cnt[now]++;
up(now);
up(f);
splay(now);
return ;
}
f=now;now=son[now][key[now]<x];
if(!now)
{
type++;
size[type]=cnt[type]=;
son[type][]=son[type][]=;
son[f][x>key[f]]=type;
fa[type]=f;
key[type]=x;
up(f);splay(type);
return ;
}
}
}
int pre()
{
if(cnt[root]>)return root;
int now=son[root][];
while(son[now][])now=son[now][];
return now;
}
int nxt()
{
if(cnt[root]>)return root;
int now=son[root][];
while(son[now][])now=son[now][];
return now;
}
void changeroot(int x)
{
int now=root;
while()
{
if(x<key[now])now=son[now][];
else
{
if(x==key[now])
{
splay(now);
return ;
}
now=son[now][];
}
}
}
void del(int x)
{
changeroot(x);
if(cnt[root]>)
{
cnt[root]--;
up(root);
return ;
}
if(!son[root][]&&!son[root][])
{
clear(root);
root=;
return ;
}
if(!son[root][])
{
int old=root;
root=son[root][];
fa[root]=;
clear(old);
return ;
}
else if(!son[root][])
{
int old=root;
root=son[root][];
fa[root]=;
clear(root);
return ;
}
int old=root,L=pre();
splay(L);
son[root][]=son[old][];
fa[son[old][]]=root;
clear(old);
up(root);
}
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>'')
{if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<='')
{x=(x<<)+(x<<)+ch-'';ch=getchar();}
return x*f;
}
int now_=-;
int ans;
int main()
{
n=read();
ins(inf);ins(-inf);
for(int i=;i<=n;i++)
{
int op=read(),val=read();
//cout<<"root="<<root<<endl;
if(now_==-)
{
now_=op;
ins(val);
num[op]++;
continue;
}
if(now_==op)
{
ins(val);
num[op]++;
continue;
}
ins(val);
int pre_=pre(),nxt_=nxt(),preval=key[pre_],nxtval=key[nxt_];
del(val);
if(val-preval<=nxtval-val)ans+=(val-preval)%mod,del(preval),num[op^]--;
else ans+=(nxtval-val)%mod,del(nxtval),num[op^]--;
if(num[]==&&num[]==)now_=-;
ans%=mod;
}
cout<<ans%mod<<endl;
return ;
}

[HNOI2004]宠物收养所 题解的更多相关文章

  1. BZOJ1208:[HNOI2004]宠物收养所——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=1208 Description 最近,阿Q开了一间宠物收养所.收养所提供两种服务:收养被主人遗弃的宠物 ...

  2. BZOJ 1208: [HNOI2004]宠物收养所 SET的妙用

    1208: [HNOI2004]宠物收养所 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4902  Solved: 1879 题目连接 http:/ ...

  3. BZOJ 1208: [HNOI2004]宠物收养所

    1208: [HNOI2004]宠物收养所 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 7514  Solved: 2982[Submit][Sta ...

  4. bzoj 1208: [HNOI2004]宠物收养所 set

    1208: [HNOI2004]宠物收养所 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 7328  Solved: 2892[Submit][Sta ...

  5. 数据结构(set):COGS 62. [HNOI2004] 宠物收养所

    62. [HNOI2004] 宠物收养所 ★★★   输入文件:pet.in   输出文件:pet.out   简单对比时间限制:1 s   内存限制:128 MB 最近,阿Q开了一间宠物收养所.收养 ...

  6. bzoj1208 [HNOI2004]宠物收养所(STL,Treap)

    1208: [HNOI2004]宠物收养所 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 5956  Solved: 2317[Submit][Sta ...

  7. BZOJ 1208: [HNOI2004]宠物收养所(BST)

    本来想先用set写一遍,再自己写个splay或treap,不过用set过了之后就懒得去写了....以后有空再来写吧..(不会有空的吧= = ------------------------------ ...

  8. BZOJ_1208_[HNOI2004]宠物收养所_SPLAY

    BZOJ_1208_[HNOI2004]宠物收养所_SPLAY Description 最近,阿Q开了一间宠物收养所.收养所提供两种服务:收养被主人遗弃的宠物和让新的主人领养这些宠物.每个领养者都希望 ...

  9. bzoj 1208: [HNOI2004]宠物收养所 (Treap)

    链接:  https://www.lydsy.com/JudgeOnline/problem.php?id=1208 题面: 1208: [HNOI2004]宠物收养所 Time Limit: 10 ...

随机推荐

  1. 配置类Configuration怎样使用

    public class CorsConfiguration { /** * Wildcard representing <em>all</em> origins, metho ...

  2. mybatis表关联彻底理解

    1.多张表关联 三张表,用户表,主播表,关注表. 查询用户已经关注的主播的信息,那就要三张表关联起来啊.分别left join联在一起,通过id相同的连接在一起.最后where查找出最终条件. < ...

  3. 联想S820 MIUI刷机包 MIUI 4.4.30 流畅执行 在线主题破解

    ROM介绍 破解免费使用MIUI全部主题(方法:开机开启Root权限,进入WSM工具箱→安装二进制文件→重新启动→再次进入WSM工具箱→两个工具打上勾→重新启动),然后尽情奔放吧 .加入V4A音效 . ...

  4. [水题]4242 果实计数&&3214 采访对象

    4242 果实计数  时间限制: 1 s  空间限制: 32000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 淘淘家有棵奇怪的苹果树,这棵树共有n+1层 ...

  5. elasticsearch 布尔过滤器 游标查询 Scroll

    组合过滤器 | Elasticsearch: 权威指南 | Elastic https://www.elastic.co/guide/cn/elasticsearch/guide/current/co ...

  6. Redis主节点内存占用过高

    0. 基本情况 Redis采用集群模式,560个主节点,主从比为1:1,单台机器上为16个节点.info memory观察到主节点A单个Redis内存used_memory_rss_human为9.2 ...

  7. android TabHost控件

    (一)TabHost控件,默认是在顶部显示的 TabHost是盛放Tab按钮和Tab内容的首要容器, TabWidget(tabs标签)用于选择页面,是指一组包含文本或图标的 ,FrameLayout ...

  8. 【HDU1530】【ZOJ1492】Maximum Clique

    Position: http://poj.org/problem?id=3241 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCod ...

  9. 46. Ext中namespace的作用(转)

    转自:https://www.cnblogs.com/givemeanorange/p/5569954.html Ext中在每一个页面中添加一个namespace呢,就像下面的代码: // creat ...

  10. 使用display:flex;实现两栏布局和三栏布局

    一.使用display:flex;实现两栏布局 body,div{margin:0px;padding:0px;} .flex-container{display:flex;height:300px; ...