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

将相等的值放到左子树下 自然就维护了先上传排名高的条件

维护名字可以用hash 这里为了省事直接用的map

因为这里的排名是从大到小 所以要选择后序遍历

这题有剧毒 数据跟题目描述不符 我开始inf=0x3f3f3f3f wa了好久 改成2e9就a了

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define lson i<<1
#define rson i<<1|1
using namespace std;
const int N=3e5+5;
const int inf=2e9;
map<string,int>score,number;
map<int,string>name;
int f[N],ch[N][2],sz[N],key[N];
int totplayer,tot,root;
inline void Clear(int x)
{f[x]=ch[x][0]=ch[x][1]=sz[x]=key[x]=0;
}
inline int get(int x)
{return ch[f[x]][1]==x;
}
void update(int x)
{if (x){sz[x]=1;if (ch[x][0]) sz[x]+=sz[ch[x][0]];if (ch[x][1]) sz[x]+=sz[ch[x][1]];}
}
void Rotate(int x)
{int fa=f[x],ff=f[fa],kind=get(x);ch[fa][kind]=ch[x][kind^1];f[ch[x][kind^1]]=fa;ch[x][kind^1]=fa;f[fa]=x;f[x]=ff;if (ff)ch[ff][ch[ff][1]==fa]=x;update(fa);update(x);
}
void splay(int x,int y)
{for(int fa;(fa=f[x])!=y;Rotate(x))if (f[fa]!=y)Rotate((get(fa)==get(x))?fa:x);if (y==0) root=x;
}
int Insert(int x)
{if (root==0){root=++tot;ch[tot][0]=ch[tot][1]=f[tot]=0;key[tot]=x;sz[tot]=1;return tot;}int now=root,fa=0;while(1){fa=now;now=ch[now][key[now]<x];if (now==0){tot++;ch[tot][0]=ch[tot][1]=0;f[tot]=fa;ch[fa][key[fa]<x]=tot;key[tot]=x;sz[tot]=1;update(fa);splay(tot,0);return tot;}}
}
int pre()
{int now=ch[root][0];while(ch[now][1])now=ch[now][1];return now;
}
void del(int x)
{splay(x,0);int leftbig=pre(),oldroot=root;splay(leftbig,0);ch[root][1]=ch[oldroot][1];f[ch[oldroot][1]]=root;Clear(oldroot);update(root);
}
int Find(int x)
{int now=root;while(1){if (ch[now][0]&&x<=sz[ch[now][0]])now=ch[now][0];else{int tem=1;if (ch[now][0])tem+=sz[ch[now][0]];if (x<=tem) return now;x-=tem;now=ch[now][1];}}
}
int st,ed;
void out(int x)
{if (ch[x][1]) out(ch[x][1]);st++;string s=name[x];int len=s.length();for(int i=0;i<len;i++)putchar(s[i]);if (st!=ed) putchar(' ');if (ch[x][0]) out(ch[x][0]);
}
void query(int l,int len)
{int y=totplayer-l+1;int x=totplayer-(l+len-1)+1;// x-1 y+1 还有-inf 所以就是x-1+1 y+1+1int aa=Find(x);int bb=Find(y+2);splay(aa,0);splay(bb,aa);st=0;ed=len;out(ch[ch[root][1]][0]);
}
void init()
{totplayer=tot=root=0;score.clear();number.clear();name.clear();
}
int main()
{int n;while(scanf("%d",&n)!=EOF){init();Insert(-inf);Insert(inf);string s;while(n--){char c;scanf(" %c",&c);if(c=='+'){s="";while(1){c=getchar();if (c==' ') break;s+=c;}int t;scanf("%d",&t);if (number[s]){del(number[s]);score[s]=t;int tem=Insert(t);number[s]=tem;name[tem]=s;}else{++totplayer;score[s]=t;int tem=Insert(t);number[s]=tem;name[tem]=s;}}else{s="";while(1){c=getchar();if (c=='\n') break;s+=c;}if (s[0]>='0'&&s[0]<='9'){int ans=0;int len=s.length();for(int i=0;i<len;i++)ans=ans*10+s[i]-'0';query(ans,min(10,totplayer-ans+1));printf("\n");}else{splay(number[s],0);printf("%d\n",totplayer-sz[ch[root][0]]+1);}}}}return 0;
}

  

转载于:https://www.cnblogs.com/bk-201/p/7401043.html

HYSBZ 1862 GameZ游戏排名系统相关推荐

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  9. bzoj 1056 1862: [Zjoi2006]GameZ游戏排名系统(Treap+Hash)

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

最新文章

  1. ajax工具、框架和库
  2. 要在某一房间中两台计算机之间实现网络通信,大学计算机计算思维导论期末考试综述.doc...
  3. 设计模式系列之----观察者模式
  4. 台式机安装系统时区分BIOS与UEFI
  5. Oracle数据库查看表空间sql语句、查看Oracle数据库表空间剩余 、修改表空间、库备份
  6. Javascript面向对象编程(一):对象的产生
  7. php openssl des ecb,php7.2 des-ede3-ecb加密报错:openssl_encrypt():Unknown cipher algorithm 落叶随风博客...
  8. 2.4 HDFS组成架构
  9. MMUlinux内核开启
  10. 怎么查看和下载高清谷歌卫星地图
  11. [转]如何学好windows c++编程 学习精髓(收集,整理)
  12. 基于Servlet和jsp的小说网站系统
  13. 第一次养狗_如何度过艰难的第一个月
  14. Docker的Pull Digest和Image ID
  15. Java+MySQL+swing学生管理系统
  16. 二进制转化成ascll_如何将二进制文件转换为ASCII
  17. python数据处理2: 拟合数据、整合数据、导出数据
  18. websocket使用springboot实现的详细步骤
  19. 共享单车项目数据可视化+需求策略分析
  20. 简单的基于Tacotron2的中英文混语言合成, 包括code-switch和voice clone. 以及深入结构设计的探讨.

热门文章

  1. RTSP协议视频智能分析平台EasyNVR如何获取云端录像的视频快照截图?
  2. MySQL之char、varchar类型简析
  3. iis7怎么搭建php环境,WIN7下iis7支持php环境搭建
  4. 表单元素的submit()方法和onsubmit事件
  5. gor工具在测试和压测场景的应用
  6. 大漠插件测试工具使用
  7. 记录一次使用jiaThis社会化分享组件遇到的坑!!
  8. Go实现优雅关机与平滑重启
  9. 【场景化解决方案】深度融合钉能力,实现企业级办公费控精细化管理
  10. MFC绘图小实验(1)