Code:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#define N 300002
#define mod 1000000009
#define ll long long
#define lson t[x].ch[0]
#define rson t[x].ch[1]
#define setIO(s) freopen(s".in", "r", stdin)
using namespace std;
map<int, int> id;
char S[N][12];
int sta[N], pos[N], tot , root, cc = 0, splay_cnt;
struct Node
{
int ch[2] , siz, f;
ll val;
}t[N];
inline int decode(char str[])
{
int k = strlen(str + 1), i , j ;
ll h = 1;
for(i = 1; i <= k ; ++i) h = (h * 26 + str[i] - 'A') % mod;
return (int) h ;
}
inline int get(char str[])
{
int k = strlen(str + 1), i , j = 0;
for(i = 1; i <= k ; ++i) j = j * 10 + str[i] - '0';
return j ;
}
inline void pushup(int x)
{
t[x].siz = t[lson].siz + t[rson].siz + 1;
}
inline int get(int x)
{
return t[t[x].f].ch[1] == x;
}
inline void rotate(int x)
{
int old = t[x].f, fold = t[old].f , which = get(x);
t[old].ch[which] = t[x].ch[which ^ 1], t[t[old].ch[which]].f = old;
t[x].ch[which ^ 1] = old, t[old].f = x, t[x].f = fold;
if(fold) t[fold].ch[t[fold].ch[1] == old] = x;
pushup(old), pushup(x);
}
inline void splay(int x, int &tar)
{
int u = t[tar].f;
for(int fa ; (fa = t[x].f) ^ u ; rotate(x))
if(t[fa].f ^ u)
rotate(get(fa) == get(x) ? fa : x);
tar = x;
}
inline void insert(int &x, int ff, ll v)
{
if(!x)
{
x = ++ tot;
t[x].f = ff, t[x].val = v;
pushup(x);
return ;
}
insert(t[x].ch[v <= t[x].val], x , v), pushup(x);
}
inline int get_kth(int k)
{
int x = root;
while(1)
{
if(k > t[lson].siz)
{
k -= (t[lson].siz + 1);
if(!k) return x ;
else x = rson;
}
else x = lson;
}
}
inline void print(int i)
{
int L = strlen(S[i] + 1), j ;
for(j = 1; j <= L; ++j) printf("%c", S[i][j]);
}
inline void dfs(int u)
{
if(!u) return ;
if(t[u].ch[0]) dfs(t[u].ch[0]);
print(pos[u]), printf(" ");
if(t[u].ch[1]) dfs(t[u].ch[1]);
}
inline void del(int x)
{
splay(x, root);
if(!lson) root = rson, t[root].f = 0;
else if(!rson) root = lson, t[root].f = 0;
else
{
int p = lson;
while(t[p].ch[1]) p = t[p].ch[1];
splay(p, t[root].ch[0]), t[p].ch[1] = t[root].ch[1], t[p].f = 0, t[t[root].ch[1]].f = p, pushup(p), root = p;
}
t[x].ch[0] = t[x].ch[1] = 0;
}
int main()
{
// setIO("input");
int T, i , j ;
scanf("%d", &T);
for(int cas = 1; cas <= T; ++cas)
{
char str[20];
scanf("%s", str);
if(str[0] == '+')
{
j = strlen(str + 1);
for(i = 1; i <= j ; ++i) S[cas][i] = str[i];
int h = decode(str);
ll v;
scanf("%lld", &v), ++cc, ++splay_cnt;
if(id[h]) del(id[h]), --cc;
insert(root , 0 , v), id[h] = tot, pos[tot] = cas;
if(splay_cnt % 6 == 0) splay(tot, root);
}
else
{
if(str[1] >= '0' && str[1] <= '9') // (好头疼qaq)
{
int kth = get(str);
int p = get_kth(kth);
int now, c;
splay(p, root), print(pos[p]), printf(" ");
if(kth + 10 - 1 < cc) c = get_kth(kth + 10), splay(c, t[root].ch[1]), now = t[t[root].ch[1]].ch[0];
else now = t[root].ch[1];
dfs(now), printf("\n");
}
else
{
int h = decode(str);
splay(id[h], root), printf("%d\n", t[t[root].ch[0]].siz + 1);
}
}
}
return 0;
}

  

luogu P2584 [ZJOI2006]GameZ游戏排名系统 Splay的更多相关文章

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

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

  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. 1056/1862. [ZJOI2006]GameZ游戏排名系统【平衡树-splay】

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. 完全二叉树(Complete Binary Tree)

    Date:2019-03-25 19:36:45 判断一棵树是否为完全二叉树 #include <queue> using namespace std; void IsComplete(n ...

  2. ApacheBench 测试性能并使用 GnuPlot 绘制图表

    转自:http://blog.csdn.net/fdipzone/article/details/18827069 ApacheBench 测试性能并使用 GnuPlot 绘制图表 Apache Be ...

  3. css3实现滚动手表

    静态html: <!DOCTYPE html><html> <head> <meta charset="utf-8" /> < ...

  4. 记Spring搭建功能完整的个人博客「Oyster」全过程[其一] 整体思路:需求、架构及技术要求

    一两个星期前正在了解Linux内核,看得有点累,突然想趁着五一放假写个博客学学spring. 由于没有在一开始下定决心写这个博客系统,所以我又没记录一开始的分析过程.这都是写了一个星期之后的思路了. ...

  5. [luogu1600 noip2016] 天天爱跑步 (树上差分)

    题目描述 小c同学认为跑步非常有趣,于是决定制作一款叫做<天天爱跑步>的游戏.<天天爱跑步>是一个养成类游戏,需要玩家每天按时上线,完成打卡任务. 这个游戏的地图可以看作一一棵 ...

  6. Linux 基础入门一

    操作系统1.简介OS: Operating System,通用目的的软件程序操作系统的内核(kernel):  操作系统其实也是一组程序.这组程序的重点在于管理计算机的所有活动及驱动系统中的所有硬件: ...

  7. 初步体验libsvm用法1(官方自带工具)

    在机器学习和模式识别领域,svm理论使用得很广泛,其理论基础是统计学习,但是如果我们的研究方向不是svm理论,我们只是利用已有的svm工具来对我们的任务进行分类和回归,那么libsvm是一个不错的选择 ...

  8. Myeclipse中将项目上传到码云

    公司实习之后习惯是代码上传到svn上,最近想起来个人的一些代码上传的到码云上比较方便,根据网上分享的博客内容结合自己的整理记录 其中大多数是参考了https://blog.csdn.net/izzyl ...

  9. Python游戏server开发日记(二)绕过GIL启动多线程Python环境

    说道Python和多线程,非常easy想到GIL,GIL意味着仅仅要是用Python做的多线程程序.就无法利用多个CPU. 经过一些失败的尝试后,我也一度觉得GIL是无解的.我们甚至把注意力转向了Ir ...

  10. maven 创建web项目出错

    错误的信息: .m2/repository/org/apache/maven/archetypes/maven-archetype-webapp/maven-metadata-central.xml ...