#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define maxn 400005
#define p1 63
#define p2 103
#define mod1 1000007
#define mod2 2000007
int n,tot,len,need,fact,fa[maxn],son[maxn][],val[maxn],size[maxn];
char Name[maxn][],name[];
void read(int &x){
x=; int f=; char ch;
for (ch=getchar();!isdigit(ch);ch=getchar()) if (ch=='-') f=-;
for (;isdigit(ch);ch=getchar()) x=x*+ch-''; x*=f;
}
struct S{
int root;
void prepare(){root=,memset(son,,sizeof(son));}
int which(int x){
return son[fa[x]][]==x;
}
void updata(int x){
size[x]=;
if (son[x][]) size[x]+=size[son[x][]];
if (son[x][]) size[x]+=size[son[x][]];
}
void rotata(int x){
int y=fa[x],d=which(x),dd=which(y);
if (fa[y]) son[fa[y]][dd]=x; fa[x]=fa[y];
fa[son[x][d^]]=y,son[y][d]=son[x][d^];
fa[y]=x,son[x][d^]=y,updata(y);
}
void splay(int x,int goal){
while (fa[x]!=goal){
if (fa[fa[x]]==goal) rotata(x);
else if (which(x)==which(fa[x])) rotata(fa[x]),rotata(x);
else rotata(x),rotata(x);
}
updata(x); if (goal==) root=x;
}
void insert(int x){
int y=root; bool bo;
if (root==){
root=x; updata(x);
return;
}
for (;;){
bo=;
if (val[x]<=val[y]){
if (!son[y][]) son[y][]=x,fa[x]=y,updata(x),updata(y),bo=,splay(x,);
else y=son[y][];
}else{
if (son[y][]==) son[y][]=x,fa[x]=y,updata(x),updata(y),bo=,splay(x,);
else y=son[y][];
}
if (bo==) break;
}
}
int prep(int x){
splay(x,);
int y=son[x][];
while (son[y][]) y=son[y][];
return y;
}
void Delete(int x){
int y=prep(x),z;
if (y==){
splay(x,); z=son[x][];
root=z,son[x][]=son[x][]=fa[x]=size[x]=fa[z]=;
}else{
splay(y,),splay(x,y); z=son[x][];
fa[z]=y,son[y][]=z,updata(y);
fa[x]=son[x][]=son[x][]=size[x]=;
}
}
int rank(int x){
splay(x,);
return size[son[x][]]+;
}
int kth(int x){
int y=root; bool bo;
for (;;){
if (size[son[y][]]+==x) return y;
else if (size[son[y][]]>=x) y=son[y][];
else x-=size[son[y][]]+,y=son[y][];
}
}
void print(int x){
if (son[x][]) print(son[x][]);
fact++;
for (int i=;i<=Name[x][];i++) printf("%c",Name[x][i]);
if (fact<need) printf(" ");
if (son[x][]) print(son[x][]);
}
void query(int u,int v){
int x=kth(u-),y=kth(v+),z; fact=;
splay(x,),splay(y,x); z=son[y][];
print(z); puts("");
}
}Splay;
struct hash{
int now[mod1+],prep[maxn],Ha[maxn][];
int ha1(){
int x=;
for (int i=;i<len;i++){
x=(x+(int)name[i])%mod1*p1%mod1;
}
return x;
}
int ha2(){
int x=;
for (int i=;i<len;i++){
x=(x+(int)name[i])%mod2*p2%mod2;
}
return x;
}
bool exist(){
int x1=ha1(),x2=ha2(); bool bo=;
for (int i=now[x1];i;i=prep[i]){
if (Ha[i][]==x2){
bo=; break;
}
}
return bo;
}
int number(){
int x1=ha1(),x2=ha2();
for (int i=now[x1];i;i=prep[i]){
if (Ha[i][]==x2) return Ha[i][];
}
}
void insert(){
int x1=ha1(),x2=ha2();
prep[++tot]=now[x1],now[x1]=tot;
Ha[tot][]=x2,Ha[tot][]=tot;
for (int i=;i<len;i++) Name[tot][]++,Name[tot][Name[tot][]]=name[i];
}
}Hash;
int main(){
char op[];
memset(size,,sizeof(size));
read(n),tot=; Splay.prepare();
val[n+]=-,val[n+]=;
Splay.insert(n+),Splay.insert(n+);
for (int w,u,i=;i<=n;i++){
scanf("%s",op+);
if (op[]=='+'){
len=strlen(op+); read(w);
for (int j=;j<=len;j++) name[j-]=op[j];
if (!Hash.exist()) Hash.insert(),u=Hash.number(),val[u]=w,Splay.insert(u);
else{
u=Hash.number();
Splay.Delete(u),val[u]=w,Splay.insert(u);
}
}else if (op[]=='?'&&!isdigit(op[])){
len=strlen(op+);
for (int j=;j<=len;j++) name[j-]=op[j];
w=Hash.number();
printf("%d\n",tot-Splay.rank(w)+);
}else{
len=strlen(op+); w=;
for (int j=;j<=len;j++) w=w*+op[j]-'';
w=tot-w+;
u=max(,w-+); need=w-u+;
Splay.query(u+,w+);
}
}
return ;
}

题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1862

题意参照题面。

做法:Splay+Hash。

裸的splay,支持插入删除查询排名即可,为什么要用Hash呢,因为如果某玩家上传过记录就得把之前的记录清空,所以我们需要用字符串Hash来判重,字符串我们使用双hash值,一个用来确定地址,第一个来作为val,这样就能降低在哈希表中查找的复杂度,再记录该玩家在Splay树中的标号即可。

splay+Hash。

Hash_bzoj1862: [Zjoi2006]GameZ游戏排名系统的更多相关文章

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

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

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

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

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

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

  4. bzoj1862: [Zjoi2006]GameZ游戏排名系统

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

  5. [ZJOI2006]GameZ游戏排名系统

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

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

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

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

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

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

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

  9. [洛谷P2584][ZJOI2006]GameZ游戏排名系统

    题目大意:同[洛谷P4291][HAOI2008]排名系统(双倍经验) 题解:略 卡点:无 C++ Code: #include <cstdio> #include <map> ...

随机推荐

  1. html post和get的区别

    一直以来,都对这两个概念有一个感性的认识,今天总结一下: 1.Get是用来从服务器上获得数据,而Post是用来向服务器上传递数据. 2.Get将表单中数据的按照variable=value的形式,添加 ...

  2. Meet Python: little notes

    Source: http://www.liaoxuefeng.com/ ❤ Escape character: '\' - '\n': newline; - '\t': tab; - '\\': \; ...

  3. Generate Parentheses

    Generate Parentheses Given n pairs of parentheses, write a function to generate all combinations of ...

  4. React Native 中组件的生命周期

    概述 就像 Android 开发中的 View 一样,React Native(RN) 中的组件也有生命周期(Lifecycle).所谓生命周期,就是一个对象从开始生成到最后消亡所经历的状态,理解生命 ...

  5. 数据挖掘系列(9)——BP神经网络算法与实践

    神经网络曾经很火,有过一段低迷期,现在因为深度学习的原因继续火起来了.神经网络有很多种:前向传输网络.反向传输网络.递归神经网络.卷积神经网络等.本文介绍基本的反向传输神经网络(Backpropaga ...

  6. lecture5-对象识别与卷积神经网络

    Hinton第五课 突然不知道object recognition 该翻译成对象识别好,还是目标识别好,还是物体识别好,但是鉴于范围性,还是翻译成对象识别吧.这一课附带了两个论文<Convolu ...

  7. 简单高效的nodejs爬虫模型

    这篇文章讲解一下yunshare项目的爬虫模型. 使用nodejs开发爬虫很简单,不需要类似python的scrapy这样的爬虫框架,只需要用request或者superagent这样的http库就能 ...

  8. Orchard搜索与索引

    Orchard提供了索引与搜索的功能.开启Indexing属性可实现索引功能,伴随着一个特定的索引执行(默认包含基础搜索引擎).除了Indexing和Search提供查询索引的功能外(通过关键字或使用 ...

  9. [BZOJ2768][JLOI2010]冠军调查(最小割)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=2768 分析: 如果一个点i认为是0,则连一条S->i,如果认为是1,则i-> ...

  10. JavaWeb之jsp编译为java源码的文件地址

    ..\..\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\project_ ...