分析:

平衡树裸题,(学完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. SD从零开始38-40

    [原创]SD从零开始38 创建Billing Document 根据需要BillingBilling On Request 你可以通过手工输入凭证的号码(订单号码和Delivery note,依赖于你 ...

  2. PostGIS安装

    PostGIS安装 1.软件下载 postgresql-9.6.1-1-windows-x64-binaries.zip https://www.postgresql.org/download/win ...

  3. 表id关联数据获取至页面,制作下拉框多选进行数据多项获取(字段处理)

     这周完成了一张表单,重点碰到以下问题: 1.freemaker获取年份的type值取year,类型直接为Long,传至后台和获取数据不需要转换: 2.freemaker获取日期type值为date, ...

  4. 犀牛Rhino教程合集37部

    犀牛Rhino教程合集37部 教程说明:英文视频教程,部分有中文字幕,大部分有工程文件 教程格式:Flv.MP4格式,大部分高清,确保能看清软件上的文字 发货方式:百度网盘下载链接(教程较多,可转存到 ...

  5. Java的8种基本数据类型和3种引用数据类型

    背景 最近被一个问题难倒:问到Java的基本数据类型有8种,具体是哪几个?一起复习下: Java数据类型概述 变量就是申请内存来存储值,即当创建变量的时候,需要在内存中申请空间. 内存管理系统根据变量 ...

  6. c#List数组移除元素

    ; i >= ; i--) //移除已经订阅的患者 { if (AllPatientsEntities[i].姓名 == item.患者姓名) AllPatientsEntities.Remov ...

  7. 用 Windows Live Writer 写blog,This is Test……..

    1.下载  Windows Live Writer,百度一下下载地址,不在这里提供下载了. 2.选择安装,其它微软应用不需要就不要安装. 3.里面有很多用的插件很好玩的,点击添加插件.

  8. Oracle EBS OPM 发放生产批

    --发放生产批 --created by jenrry DECLARE x_return_status VARCHAR2 (1); l_exception_material_tbl gme_commo ...

  9. 【MySQL运维实践】

    什么是日志 日志(log)是一种顺序记录事件流水的文件 记录计算机程序运行过程中发生了什么 多种多样的用途  帮助分析程序问题 分析服务请求的特征.流量等 判断工作是否成功执行 等等…… MySQL日 ...

  10. 关于QT的QCombox的掉坑出坑

    最近项目中开发在用到QCombox,然而在开发中,踩到了一个坑,花了一个晚上,一直在想,好在最后找到问题所在了. 这是业务的流程.直接说重点:QCombox在下拉窗更新数据的时候,会默认把下拉窗的第一 ...