分析:

平衡树裸题,(学完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;
}

  

转载于:https://www.cnblogs.com/Winniechen/p/9144126.html

[HAOI2008]排名系统 [Zjoi2006]GameZ游戏排名系统 BZOJ1862BZOJ1056相关推荐

  1. BZOJ1862[Zjoi2006]GameZ游戏排名系统【splay+hash】

    [Zjoi2006]GameZ游戏排名系统[Zjoi2006]GameZ游戏排名系统[Zjoi2006]GameZ游戏排名系统 Description: GameZ为他们最新推出的游戏开通了一个网站. ...

  2. 【BZOJ 1862】 [Zjoi2006]GameZ游戏排名系统

    1862: [Zjoi2006]GameZ游戏排名系统 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 695  Solved: 265 [Submit] ...

  3. luogu P2584 [ZJOI2006]GameZ游戏排名系统 Splay

    luogu P2584 [ZJOI2006]GameZ游戏排名系统 Splay 实在不想调了QAQ... Code: #include <cstdio> #include <algo ...

  4. bzoj 1862 [Zjoi2006]GameZ游戏排名系统

    1862: [Zjoi2006]GameZ游戏排名系统 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 1134  Solved: 429 [Submit ...

  5. BZOJ 1862: [Zjoi2006]GameZ游戏排名系统 Splay

    Splay的基本操作,比较繁琐..... 有个一坑点,sorce会超int 1862: [Zjoi2006]GameZ游戏排名系统 Time Limit: 5 Sec  Memory Limit: 6 ...

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

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

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

    http://www.elijahqi.win/archives/3043 Description GameZ为他们最新推出的游戏开通了一个网站.世界各地的玩家都可以将自己的游戏得分上传到网站上.这样 ...

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

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

  9. 1862: [Zjoi2006]GameZ游戏排名系统(Splay)

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

最新文章

  1. bootstrap的日期选择器 完整源码demo附效果图
  2. 是否注意过isEmpty 和 isBlank 区别?
  3. div 不受父级标签影响_前端H5开发中常用的标签
  4. 个人成长:2021年7月记
  5. root目录空间不够的问题
  6. Leetcode--221.最大正方形
  7. Java多线程学习二十六:原子类是如何利用 CAS 保证线程安全的?
  8. Linux中tty、pty、pts的概念区别
  9. 详解微软 ALUM:当语言模型遇到对抗训练
  10. LSB最低有效位算法实现
  11. 18650锂电池保护板接线图_12v锂电池保护板电路图 - 全文
  12. oracle启动pmon,oracle 11g pmon工作内容系列三
  13. 当驾校学员遇上微信小程序
  14. SQL SERVER数据库三种数据插入方式
  15. sublime Boxy Theme安装方法
  16. 黑鲨能换鸿蒙系统吗,黑鲨告诉你重装系统对电脑的好坏处
  17. jQuery淡入浅出
  18. winform Control与UserControl的区别
  19. 百分制成绩转换五分制F
  20. 计算机ram和rom的特点的是,什么是ROM和RAM?它们各有什么特点?

热门文章

  1. 哈尔滨华夏计算机专业学院怎么样,哈尔滨华夏计算机职业技术学院怎么样啊.有没有在那里的介绍下. 爱问知识人...
  2. 基于python+ffmpeg的视频并发直播压力测试
  3. mysql设置varchar_MySql中varchar长度的设置问题
  4. 关于eclipse运行maven项目报错的解决方法
  5. 忆联携手中国移动,企业级NVME SSD评测及生态推进计划发布仪式圆满成功
  6. Nginx 502错误: Failed to load resource: the server responded with a status of 502 (Bad Gateway)
  7. read函数的返回值问题
  8. 泛型(Generic)理解
  9. 大学四年学习路线(以下纯属个人意见)适合上大学的人看
  10. FPGA数字信号处理(26)加扰器与解扰器设计