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

实在不想调了QAQ...

Code:

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <iostream>
#include <map> #define setIO(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
#define maxn 1000000
#define ll long long using namespace std;
int ch[maxn][2],f[maxn],lazy[maxn],siz[maxn];
ll maxv[maxn];
int cnt,root;
char tt[maxn];
map<string,int>P;
string h[maxn];
int newnode(){ return ++cnt;  }
struct Node
{int id;ll val;
}node[maxn];
int cmp(Node a,Node b){ return (a.val==b.val)?a.id<b.id:a.val>b.val;  }
int lson(int x) { return ch[x][0]; }
int rson(int x) { return ch[x][1]; }
struct Splay_Tree{ int get(int x){ return ch[f[x]][1] == x; }void pushup(int x){siz[x]=siz[lson(x)] + siz[rson(x)] + 1; //maxv[x]=max(maxv[lson(x)],maxv[rson(x)]); //maxv[x]=max(maxv[x],node[x].val); }void rotate(int x){int old=f[x],oldf=f[old],which=get(x); ch[old][which]=ch[x][which^1],f[ch[old][which]]=old; ch[x][which^1]=old,f[old]=x,f[x]=oldf; if(oldf) ch[oldf][ch[oldf][1]==old]=x; pushup(old),pushup(x); }void splay(int x,int &tar){int a = f[tar];for(int fa; (fa = f[x]) != a; rotate(x))if(f[fa] != a) rotate(get(x) == get(fa) ? fa : x);tar = x;}int findx(int x,int rk){   if(rk<=siz[lson(x)]) return findx(lson(x),rk); else if(rk-siz[lson(x)]-1 > 0) return findx(rson(x),rk-siz[lson(x)]-1);  else return x;           }void deletex(int x){splay(x,root);int p=findx(lson(x),siz[lson(x)]);         splay(p,ch[x][0]); ch[p][1]=ch[x][1]; //f[ch[x][1]]=ch[x][0];f[ch[x][1]]=p;      f[p]=0; pushup(root=ch[x][0]);        f[x]=siz[x]=0;            ch[x][0]=ch[x][1]=0; }void ins(int fa,int &x,int cur){if(!x) {      x=cur; pushup(cur);                f[cur]=fa; return ; }if(!cmp(node[cur],node[x])) ins(x,ch[x][1],cur); else ins(x,ch[x][0],cur);         pushup(x); }
}tree;
void print(int x){if(!x) return;print(lson(x)); cout<<h[x]<<" "; print(rson(x));
}
int main(){//setIO("game"); int T; cin>>T;  node[maxn-1].val=-12312312300;node[maxn-1].id=123123123;node[maxn-2].val=12312310231231;node[maxn-2].id=0; tree.ins(0,root,maxn-1);  tree.ins(0,root,maxn-2);               for(int i=1;i<=T;++i){  char opt; string str,ss;  cin>>str;   if(str[0]=='+'){  int cur,num,len=str.size(); for(int j=1;j<len;++j) ss+=str[j]; cin>>num;    if(P[ss]) {       cur=P[ss]; tree.deletex(cur);  }  cur=P[ss]=newnode();  h[cur]=ss; node[cur].id=i,node[cur].val=num;   tree.ins(0,root,cur);  }if(str[0]=='?'){if(str[1]>='A' && str[1]<='Z'){int len=str.size(); for(int j=1;j<len;++j) ss+=str[j]; tree.splay(P[ss],root); cout<<siz[lson(P[ss])]<<endl;          }else {           int num=0,r,p; int len=str.size();for(int j=1;j<len;++j) num=num*10+str[j]-'0';                r=min(siz[root],num+11);             int a=tree.findx(root,num);  int b=tree.findx(root,r);                               tree.splay(a,root);   tree.splay(b,ch[root][1]);print(ch[ch[root][1]][0]); cout<<endl; }} }return 0;
}

  

posted @ 2019-03-02 16:36 EM-LGH 阅读(...) 评论(...) 编辑 收藏

luogu P2584 [ZJOI2006]GameZ游戏排名系统 Splay相关推荐

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

最新文章

  1. html调出手机系统设置,手机怎么打开路由器设置界面?
  2. 洛谷——P1059 明明的随机数
  3. anaconda3 win7_重装系统win7
  4. 有人问我:AI这么火,要不要去追赶AI的热潮?
  5. NOI数学之提高级:线性方程组的高斯消元法
  6. 我如何知道Bash脚本中的脚本文件名?
  7. Docker 搭建Spark 依赖singularities/spark:2.2镜像
  8. 6种微服务RPC框架,你知道几个?
  9. java ojdbc7_ojdbc7 / ojdbc8中的charset问题与ojdbc6
  10. 车载以太网测试:以太网测什么
  11. CentOS从零搭建SRS直播服务器
  12. 学会这个小技巧,SSH 会话连接永远不超时!
  13. Micheal Collins nlp课程笔记(二)Tagging Problems and Hidden Markov Models
  14. 计算机语言替换,Zig 0.7.0 发布,想要替换 C的编程语言
  15. dw css定位,css关于position属性的用法详解(绝对定位和相对定位的混淆)
  16. Vue cli项目,使用富文本编辑器WangEditor,8小时摸爬滚打后,弃坑Tinymce、UEditor、Quill
  17. 网站优化tag的正确用途,利用tag页面将事半功倍
  18. 背包问题记忆化函数实现!!(JavaScript可视化页面展示!)
  19. pyhton xlwt库踩坑 最多65535行
  20. java excel 透视_java基于poi导出excel透视表代码实例

热门文章

  1. idea如何设置作者信息
  2. YC创业课之Peter Thiel:追求垄断的创业者才能成功
  3. 阿尔·里斯-市场营销的22条法则(22条商规)-6
  4. HarmonyOS开发19:CommonDialog基本用法
  5. FRDM-KL43开发板驱动段式液晶SLCD的实现方法
  6. 第十部分(VI简介)
  7. 铅笔工具的简单使用方法
  8. Android神技之 使用SVG以及自定义IconFont字体库
  9. Adversarial Decomposition of Text Representation翻译
  10. c语言char*怎么赋值_C语言入门笔记「收藏细细品系列」