分析:

平衡树裸题,(学完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的更多相关文章

  1. [HAOI2008]排名系统& [Zjoi2006]GameZ游戏排名系统

    1056: [HAOI2008]排名系统 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2487  Solved: 711[Submit][Statu ...

  2. BZOJ_1862_[Zjoi2006]GameZ游戏排名系统&&BZOJ_1056_[HAOI2008]排名系统_Splay

    BZOJ_1862_[Zjoi2006]GameZ游戏排名系统&&BZOJ_1056_[HAOI2008]排名系统_Splay Description 排名系统通常要应付三种请求:上传 ...

  3. BZOJ 1862: [Zjoi2006]GameZ游戏排名系统 [treap hash]

    1862: [Zjoi2006]GameZ游戏排名系统 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1318  Solved: 498[Submit][ ...

  4. bzoj 1056 [HAOI2008]排名系统(1862 [Zjoi2006]GameZ游戏排名系统)

    1056: [HAOI2008]排名系统 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1854  Solved: 502[Submit][Statu ...

  5. 【BZOJ】1862: [Zjoi2006]GameZ游戏排名系统 & 1056: [HAOI2008]排名系统(treap+非常小心)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1862 http://www.lydsy.com/JudgeOnline/problem.php?id ...

  6. bzoj1056: [HAOI2008]排名系统 && 1862: [Zjoi2006]GameZ游戏排名系统

    hash 加上 平衡树(名次树). 这道题麻烦的地方就在于输入的是一个名字,所以需要hash. 这个hash用的是向后探查避免冲突,如果用类似前向星的方式避免冲突,比较难写,容易挂掉,但也速度快些. ...

  7. bzoj 1862: [Zjoi2006]GameZ游戏排名系统 & bzoj 1056: [HAOI2008]排名系统

    傻叉了一晚上,把t打成x,然后这题神奇在于输出一段数,不足的不用输出,一开始我的是直接找没有后面就退,然后这样会格式错误囧……然后最后zj的还卡了下空间,于是不用string就过了……string毁一 ...

  8. 【pb_ds】bzoj1056 [HAOI2008]排名系统/bzoj1862 [Zjoi2006]GameZ游戏排名系统

    STL裸题,线下AC,bzoj无限RE ing…… #include<cstdio> #include<cctype> #include<iostream> #in ...

  9. 1056/1862. [ZJOI2006]GameZ游戏排名系统【平衡树-splay】

    Description GameZ为他们最新推出的游戏开通了一个网站.世界各地的玩家都可以将自己的游戏得分上传到网站上.这样就可以看到自己在世界上的排名.得分越高,排名就越靠前.当两个玩家的名次相同时 ...

随机推荐

  1. 为什么main方法是public static void?

    Main方法是我们学习Java编程语言时知道的第一个方法,你是否曾经想过为什么main方法是public.static.void的.当然,很多人首先学的是C和C++,但是在Java中main方法与前者 ...

  2. OSGI企业应用开发(二)Eclipse中搭建Felix运行环境

    上篇文章介绍了什么是OSGI以及使用OSGI构建应用的优点,接着介绍了两款常用的OSGI实现,分别为Apache Felix和Equinox,接下来开始介绍如何在Eclipse中使用Apache Fe ...

  3. MyEclipse中搭建Struts2开发环境

    (尊重劳动成果,转载请注明出处:http://blog.csdn.net/qq_25827845/article/details/53205941 冷血之心的博客) 在MyEclipse中如何搭建St ...

  4. [Android] 设置AlertDialog打开后不消失

    最近项目收尾,一堆bug要改,还要对用户操作体验做一些优化,也是忙的不行.周末难得清闲,出去逛逛,看看风景,还好因为习大大要来,南京最近的天气还不错,只是苦了当地的不少农民工,无活可干,无钱可拿.想想 ...

  5. tomcat报错this web application instance has been stopped already问题

    上网搜了下,大部分的报错原因:重启时候 之前的tomcat未正常关闭 ,导致在重启时候 报了这个问题.mac下解决: ps -ef|grep tomcat 找到在进行的tomcat ,kill -9  ...

  6. VMware部署ubuntu后开机提示piix4_smbus: Host SMBus controller not enabled!

    在虚拟机部署ubuntu10.04-server,每次启动完成之后,出现“piix4_smbus0000:00:07.3: Host SMBus controller not enabled!”提示信 ...

  7. 关于 Azure Windows VM 的磁盘和 VHD

    就像其他任何计算机一样,Azure 中的虚拟机将磁盘用作存储操作系统.应用程序和数据的位置. 所有 Azure 虚拟机都至少有两个磁盘,即 Windows 操作系统磁盘和临时磁盘. 操作系统磁盘基于映 ...

  8. Sql server 使用drop database 语句,无法删除正在使用的数据库的解决办法

    使用DROP DATABASE 删除数据库  显示“无法删除数据库 ,因为该数据库当前正在使用. 解决办法:在删除某一个数据库(下例中的“DB1”数据库)前,强制kill掉该数据库上的所有数据库连接. ...

  9. Python学习--Selenium模块学习(2)

    Selenium的基本操作 获取浏览器驱动寻找方式 1. 通过手动指定浏览器驱动路径2. 通过 `$PATH`环境变量找寻浏览器驱动 可参考Python学习--Selenium模块简单介绍(1) 控制 ...

  10. windows注册表

    如何导入与导出注册表 进入注册表编辑器,选择“文件”“导出”命令,打开“导出注册表文件”对话框.选择保存位置并为其取名,单击保存即可完成注册表的备份. 打开注册表编辑器,选择“文件”“导入”命令,打开 ...