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. 用shell编写一个三角形图案

    第一种方法 #!/bin/bash read -p "请输入层数: " n for (( i=1; i<=$n;i++ ))do   for (( j=n; j>=i; ...

  2. elasticsearch元数据

    _source元数据 put /test_index/test_type/1 { "test_field1": "test field1", "tes ...

  3. Python笔记17---------魔法方法

    魔法方法也为特殊方法,即用两个下划线形成的(__方法__).自己定义的方法最好不要采用这种方式,因为这些方法会在一些特殊的情况下直接被调用. 1.第一个魔法方法:类中常用的__init__()方法:相 ...

  4. Bash 如何取得当前正在执行的脚本的绝对路径?

    转自:http://blogread.cn/it/article/6549?f=wb Bash 如何取得当前正在执行的脚本的绝对路径? 如题,一般我们写Shell脚本的时候,都倾向使用绝对路径,这样无 ...

  5. React传递参数的多种方式

    最常见的就是父子组件之间传递参数 父组件往子组件传值,直接用this.props就可以实现 在父组件中,给需要传递数据的子组件添加一个自定义属性,在子组件中通过this.props就可以获取到父组件传 ...

  6. useradd常用参数介绍

    -c :新账号passwd档的说明栏 -d :新账号每次登录时所使用的home_dir,预设值为default_home内login名称,并当成登录时目录名称 -e :*账号终止日期,日期的指定格式为 ...

  7. Linux初级命令总结

    第1节 查看当前系统版本及内核 cat /etc/redhat-release (查看系统版本) CentOS Linux release 7.4.1708 (Core) uname -r (查看系统 ...

  8. Virtual address cache memory, processor and multiprocessor

    An embodiment provides a virtual address cache memory including: a TLB virtual page memory configure ...

  9. 关于springboot整合的详细过程

    Spring-boot http://tengj.top/2017/04/24/springboot0/

  10. cogs 106. [NOIP2003] 加分二叉树(区间DP)

    106. [NOIP2003] 加分二叉树 ★☆   输入文件:jfecs.in   输出文件:jfecs.out   简单对比时间限制:1 s   内存限制:128 MB [问题描述] 设 一个 n ...