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

题面

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

本来以为要两棵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. Nginx源码分析:3张图看懂启动及进程工作原理

    编者按:高可用架构分享及传播在架构领域具有典型意义的文章,本文由陈科在高可用架构群分享.转载请注明来自高可用架构公众号「ArchNotes」.   导读:很多工程师及架构师都希望了解及掌握高性能服务器 ...

  2. js的jsonp

    window.ajaxJsonp=function(params) { params = params || {}; params.data = params.data || {}; var json ...

  3. Animations动画和Keyframes关键帧

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. Qt移动应用开发(二):使用动画框架

    Qt移动应用开发(二):使用动画框架 上一篇博客介绍了怎样使用Qt的QML来对屏幕分辨率大小进行适应,其实,不同分辨率的适应是一个很棘手的问题,除了分辨率不同外,宽高比(aspect ratio)也不 ...

  5. 第16章 ASP.NET MVC 日志篇

    本章主要介绍MVC中内置的错误处理.日志以及用来提升性能的监控工具 一.错误处理 当该网站忙于处理HTTP请求时,很多内容都会出错.幸运的是,MVC让错误处理工作变得相对简单了很多,因为MVC应用是运 ...

  6. Java课程设计——人事管理系统

    主界面代码: package PersonSystem; import java.awt.*; import java.awt.event.*; import javax.swing.*; impor ...

  7. [Berkeley]弹性分布式数据集RDD的介绍(RDD: A Fault-Tolerant Abstraction for In-Memory Cluster Computing 论文翻译)

    摘要:     本文提出了分布式内存抽象的概念--弹性分布式数据集(RDD,Resilient Distributed Datasets).它同意开发者在大型集群上运行基于内存的计算.RDD适用于两种 ...

  8. Java异常&&RuntimeException异常

    Java异常可分为3种: (1)编译时异常:Java.lang.Exception (2)运行期异常:Java.lang.RuntimeException (3)错误:Java.lang.Error ...

  9. [python基础] celery beat/task/flower解析

    一.Celery 介绍 Celery 是一个强大的分布式任务队列,它可以让任务的执行完全脱离主程序,甚至可以被分配到其他主机上运行.我们通常使用它来实现异步任务( async task )和定时任务( ...

  10. RegisterAttached 两种绑定方式

    RegisterAttached 含义:使用指定的属性名称.属性类型和所有者类型注册附加属性 绑定方式:C#绑定.WPF绑定 例:需求DataViewModel为DataView的VM层,在DataV ...