[HAOI2008]排名系统 & [Zjoi2006]GameZ游戏排名系统 BZOJ1862&BZOJ1056
分析:
平衡树裸题,(学完LCT感觉自己不会普通的Splay了...),维护每个节点的权值大小顺序,和时间戳顺序,之后map维护一下是否存在过,(懒得写字符串hash了)。
附上代码:
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <map>
using namespace std;
#define N 300055
#define ls ch[rt][0]
#define rs ch[rt][1]
#define get(rt) (ch[f[rt]][0]!=rt)
int ch[N][2],f[N],siz[N],val[N],rot,cnt,n;
map<string ,int >mp1;map<int ,string >mp2;
char s[205];
void PushUp(int rt){siz[rt]=siz[ls]+siz[rs]+1;}
void rotate(int rt)
{
int x=f[rt],y=f[x],k=get(rt);
ch[x][k]=ch[rt][!k];f[ch[x][k]]=x;
ch[rt][!k]=x;f[x]=rt;f[rt]=y;
if(x!=rot)ch[y][ch[y][0]!=x]=rt;
PushUp(x);PushUp(rt);if(x==rot)rot=rt;
}
void Splay(int rt,int y)
{
for(int fa;(fa=f[rt])!=y;rotate(rt))
if(f[fa]!=y)
rotate((get(rt)==get(fa))?fa:rt);
}
void insert(int v,int x)
{
int l,r,rt=rot;
while(rt){if(val[rt]>=v)r=rt,rt=ls;else l=rt,rt=rs;}
Splay(l,0);Splay(r,rot);ch[r][0]=x;f[x]=r,val[x]=v,siz[x]=1;PushUp(r);PushUp(l);
}
void del(int rt)
{
Splay(rt,0);
int l=ch[rt][0],r=ch[rt][1];while(ch[l][1])l=ch[l][1];while(ch[r][0])r=ch[r][0];
Splay(l,0);Splay(r,rot);ch[r][0]=0;f[rt]=0;siz[rt]=0;PushUp(r);PushUp(l);
}
int find(int x){int rt=rot;while(1){if(siz[ls]>=x)rt=ls;else{x-=siz[ls]+1;if(!x)return rt;rt=rs;}}}
int get_rank(int rt){Splay(rt,0);return siz[ls];}
void print(int rt)
{
if(rs)print(rs);
printf("%s ",mp2[rt].c_str());
if(ls)print(ls);
}
void out_put(int x,int y)
{
x=cnt-x-1;y=cnt-y-1;swap(x,y);
//printf("%d %d\n",x,y);
x=find(x),y=find(y+2);Splay(x,0);Splay(y,rot);print(ch[y][0]);
}
int main()
{
char opt1=getchar();
while(opt1>='0'&&opt1<='9')n=((n<<3)+(n<<1))+opt1-'0',opt1=getchar();
val[1]=-1<<30;val[2]=2147483647;ch[1][1]=2;f[2]=1;rot=1;siz[1]=2;siz[2]=1;cnt=2;
while(n--)
{
memset(s,0,sizeof(s));
int num=0,x=0;
opt1=getchar();while(opt1!='+'&&opt1!='?') opt1=getchar();
if(opt1=='+')
{
opt1=getchar();
while(opt1>='A'&&opt1<='Z')s[num++]=opt1,opt1=getchar();
opt1=getchar();
while(opt1<'0'||opt1>'9')opt1=getchar();
while(opt1>='0'&&opt1<='9')x=((x<<3)+(x<<1))+opt1-'0',opt1=getchar();
//printf("%d\n",mp1.count(s));
if(mp1.count(s))
{
int y=mp1[s];
del(y);
insert(x,y);
}else
{
cnt++;insert(x,cnt);mp1[s]=cnt;mp2[cnt]=s;
//printf("%d\n",cnt);
}
}else
{
opt1=getchar();
if(opt1>='0'&&opt1<='9')
{
while(opt1>='0'&&opt1<='9')x=((x<<3)+(x<<1))+opt1-'0',opt1=getchar();
out_put(x,min(x+9,cnt-2));
puts("");
}else
{
while(opt1>='A'&&opt1<='Z')s[num++]=opt1,opt1=getchar();
//Splay(5,0);printf("%d\n",siz[5]);
printf("%d\n",cnt-get_rank(mp1[s])-1);
}
}
}
return 0;
}
[HAOI2008]排名系统 & [Zjoi2006]GameZ游戏排名系统 BZOJ1862&BZOJ1056的更多相关文章
- [HAOI2008]排名系统& [Zjoi2006]GameZ游戏排名系统
1056: [HAOI2008]排名系统 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2487 Solved: 711[Submit][Statu ...
- BZOJ_1862_[Zjoi2006]GameZ游戏排名系统&&BZOJ_1056_[HAOI2008]排名系统_Splay
BZOJ_1862_[Zjoi2006]GameZ游戏排名系统&&BZOJ_1056_[HAOI2008]排名系统_Splay Description 排名系统通常要应付三种请求:上传 ...
- BZOJ 1862: [Zjoi2006]GameZ游戏排名系统 [treap hash]
1862: [Zjoi2006]GameZ游戏排名系统 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1318 Solved: 498[Submit][ ...
- bzoj 1056 [HAOI2008]排名系统(1862 [Zjoi2006]GameZ游戏排名系统)
1056: [HAOI2008]排名系统 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1854 Solved: 502[Submit][Statu ...
- 【BZOJ】1862: [Zjoi2006]GameZ游戏排名系统 & 1056: [HAOI2008]排名系统(treap+非常小心)
http://www.lydsy.com/JudgeOnline/problem.php?id=1862 http://www.lydsy.com/JudgeOnline/problem.php?id ...
- bzoj1056: [HAOI2008]排名系统 && 1862: [Zjoi2006]GameZ游戏排名系统
hash 加上 平衡树(名次树). 这道题麻烦的地方就在于输入的是一个名字,所以需要hash. 这个hash用的是向后探查避免冲突,如果用类似前向星的方式避免冲突,比较难写,容易挂掉,但也速度快些. ...
- bzoj 1862: [Zjoi2006]GameZ游戏排名系统 & bzoj 1056: [HAOI2008]排名系统
傻叉了一晚上,把t打成x,然后这题神奇在于输出一段数,不足的不用输出,一开始我的是直接找没有后面就退,然后这样会格式错误囧……然后最后zj的还卡了下空间,于是不用string就过了……string毁一 ...
- 【pb_ds】bzoj1056 [HAOI2008]排名系统/bzoj1862 [Zjoi2006]GameZ游戏排名系统
STL裸题,线下AC,bzoj无限RE ing…… #include<cstdio> #include<cctype> #include<iostream> #in ...
- 1056/1862. [ZJOI2006]GameZ游戏排名系统【平衡树-splay】
Description GameZ为他们最新推出的游戏开通了一个网站.世界各地的玩家都可以将自己的游戏得分上传到网站上.这样就可以看到自己在世界上的排名.得分越高,排名就越靠前.当两个玩家的名次相同时 ...
随机推荐
- element-ui Pagination组件源码分析整理笔记(七)
element-ui源码的版本是2.4.9 pagination.js import Pager from './pager.vue'; import ElSelect from 'element-u ...
- Oracle 修改oracle数据库名
Oracle 修改oracle数据库名 by:授客 QQ:1033553122 1.确保你有个可用于数据库恢复的,完整的数据库备份 2.确保数据库处于mount,非open状态,并且在加载前先以imm ...
- Python+Selenium笔记(十六)屏幕截图
(一) 方法 方法 简单说明 save_screenshot(filename) 获取当前屏幕截图并保存为指定文件 filename:路径/文件名 get_screenshot_as_base64 ...
- 《JavaScript面向对象编程指南》
第一章.引言 1.5 面向对象的程序设计常用概念 对象(名词):是指"事物"在程序设计语言中的表现形式. 这里的事物可以是任何东西,我们可以看到它们具有某些明确特征,能执行某些动作 ...
- MD5密码加密
using System; using System.Security.Cryptography; using System.Text; namespace DimoNetwork.Common.DE ...
- NGUI和UGUI图片字 艺术字(Bitmap图片转文字)制作方法
用图片字而不是图片 美术和程序的配合,需要程序能够很快抓住问题重点并提出解决方案.美术出的图片字比我们使用的字体更好好看,那么是否要一个个图片去拼成数字呢? NGUI创建图片字 准备材料 美术提供的数 ...
- CentOS7中部署Showdoc
目录 CentOS7中部署Showdoc 前置环境 部署 配置文件 解压安装包 添加启动服务 设置权限 运行安装 界面 CentOS7中部署Showdoc 文:铁乐与猫 前置环境 因为showdoc其 ...
- Docker容器学习与分享06
Docker容器网络 Docker有三种原生网络:none网络.host网络.bridge网络. 先来学习一下bridge网络. 首先使用ifconfig命令查看一下本机的网络设备: 从图中可以看见多 ...
- November 11th, 2017 Week 45th Saturday
Happiness is a direction, not a place. 快乐是一个方向,不是一个目的. Do you remember those moments in your life wh ...
- 2018.08.31 16:26 调试 Swift 和 Pycharm 与 github 之间的链接
花了一段时间调试Swift和Pycharm的链接,网上查了一下有关信息,再加上自己的摸索,一会就掌握了.