传送门

\(\color{green}{solution}\)

\(fhq \_treap\)模板题.
对于 \(+\) 操作,如果当前人不存在,那么直接加入;如果存在,那么先将他删除,再加入.复杂度\(O(n \log n)\)
对于 \(?\) 操作,如果问人,直接查找名次;如果问名次,先将它前面的\(split\)出去,再把它后面\(10\)个\(split\)
出去,然后输出即可.复杂度均为\(O(n \log n)\).
所以总复杂度是\(O(n \log n)\) 的.具体细节请参见代码.

#include <bits/stdc++.h>
using namespace std;

#define pii pair<int, int>
#define mp make_pair

const int maxn = 250010;

bool operator < (const pii &a, const pii &b) {
    return a.first == b.first ? a.second < b.second : a.first > b.first;
}

struct node {node *ls, *rs; pii a; int sz, ky, id;};
node *root, pool[maxn], *pis = pool, *nul, *Bc[maxn];
int bc_top;
inline void init() {
    nul = pis; nul->ls = nul->rs = nul; nul->sz = 0; root = nul;
}
node *newnode(int val, int tim, int opt) {
    node *k = bc_top ? Bc[bc_top --] : ++ pis;
    k->ls = k->rs = nul; k->sz = 1; k->ky = rand(); k->id = opt;
    k->a = mp(val, tim); return k;
}
inline void up(node *&x) { x->sz = x->ls->sz + x->rs->sz + 1;}
inline void mrg(node *&c, node *x, node *y) {
    if( x == nul || y == nul) {c = x == nul ? y : x; return;}
    if( x->ky < y->ky) c = x, mrg(c->rs, x->rs, y);
    else c = y, mrg(c->ls, x, y->ls); up(c);
}
inline void spl(node *c, node *&x, node *&y, int ret) {
    if( c == nul) { x = y = nul; return;}
    if( c->ls->sz+1 <= ret) x = c, spl(c->rs, x->rs, y, ret-c->ls->sz-1);
    else y = c, spl(c->ls, x, y->ls, ret); up(c);
}
int find(node *c, pii x) {
    if( c->a == x) return c->ls->sz + 1;
    if( c->a < x) return c->ls->sz + 1 + find(c->rs, x);
    return find(c->ls, x);
}
inline void erase(pii val) {
    int rk = find(root, val);
    node *x, *y, *z; spl(root, x, y, rk); spl(x, x, z, rk-1);
    mrg(root, x, y); Bc[++ bc_top] = z;
}
inline void sp_spl(node *c, node *&x, node *&y, int ret) {
    if( c == nul) { x = y = nul; return;}
    if( c->a.first >= ret) x = c, sp_spl(c->rs, x->rs, y, ret);
    else y = c, sp_spl(c->ls, x, y->ls, ret); up(c);
}
pii Rank[maxn];
int Idc;
inline void insert(int val, int tim, int &id) {
    if( id) erase(Rank[id]); else id = ++ Idc;
    node *x, *y; Rank[id] = mp(val, tim);
    sp_spl(root, x, y, val);
    mrg(x, x, newnode(val, tim, id)); mrg(root, x, y);
}
map<string, int> Id;
char buf[maxn][20], ss[20], *tt;
int getnum(char *s) {
    int x = 0; for ( ; !isdigit(*s); ++ s);
    for ( ; isdigit(*s); ++ s) x = (x << 1) + (x << 3) + (*s & 15);
    return x;
}
inline void out(node *x) {
    if(x == nul) return; out(x->ls); printf("%s ", buf[x->id]); out(x->rs);
}
int n;
inline void sol1(int rk) {
    node *x, *y, *z;
    spl(root, x, y, rk-1); spl(y, z, y, 10);
    out(z); puts("");
    mrg(y, z, y); mrg(root, x, y);
}

int main() {
#ifndef ONLINE_JUDGE
//  freopen("1.in","r",stdin);
#endif
    init();
    scanf("%d", &n);
    for ( register int i = 1, x; i <= n; ++ i) {
        scanf("%s", ss); tt = ss;
        if( *ss == '+') {
            ++ tt; scanf("%d", &x); insert(x, i, Id[tt]);
            int k = Id[tt];
            if( k == Idc) memcpy(buf[k], tt, sizeof(buf[k]));
        }
        else {
            ++ tt;
            if( isdigit(*tt)) sol1(getnum(tt));
            else printf("%d\n", find(root, Rank[Id[tt]]));
        }
    }
    return 0;
}

[BZOJ 1056][HAOI2008]排名系统的更多相关文章

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

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

  2. bzoj 1862: [Zjoi2006]GameZ游戏排名系统 & bzoj 1056: [HAOI2008]排名系统

    傻叉了一晚上,把t打成x,然后这题神奇在于输出一段数,不足的不用输出,一开始我的是直接找没有后面就退,然后这样会格式错误囧……然后最后zj的还卡了下空间,于是不用string就过了……string毁一 ...

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

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

  4. 1056: [HAOI2008]排名系统 - BZOJ

    Description 排名系统通常要应付三种请求:上传一条新的得分记录.查询某个玩家的当前排名以及返回某个区段内的排名记录.当某个玩家上传自己最新的得分记录时,他原有的得分记录会被删除.为了减轻服务 ...

  5. bzoj 1862/1056 [HAOI2008]排名系统

    原题链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1862 很恶心的 一道题,我也不晓得自己是第几次写这题了%>_<%. 写了两种方 ...

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

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

  7. 【BZOJ1056】[HAOI2008]排名系统(Splay)

    [BZOJ1056][HAOI2008]排名系统(Splay) 题面 BZOJ 洛谷 题解 \(Splay\)随便维护一下就好了,至于名字什么的,我懒得手写哈希表了,直接哈希之后拿\(map\)压. ...

  8. 数据结构(Splay平衡树):HAOI2008 排名系统

    [HAOI2008] 排名系统 [题目描述] 排名系统通常要应付三种请求:上传一条新的得分记录.查询某个玩家的当前排名以及返回某个区段内的排名记录.当某个玩家上传自己最新的得分记录时,他原有的得分记录 ...

  9. BZOJ_1862_[Zjoi2006]GameZ游戏排名系统&&BZOJ_1056_[HAOI2008]排名系统_Splay

    BZOJ_1862_[Zjoi2006]GameZ游戏排名系统&&BZOJ_1056_[HAOI2008]排名系统_Splay Description 排名系统通常要应付三种请求:上传 ...

随机推荐

  1. pyspider示例代码二:解析JSON数据

    本系列文章主要记录和讲解pyspider的示例代码,希望能抛砖引玉.pyspider示例代码官方网站是http://demo.pyspider.org/.上面的示例代码太多,无从下手.因此本人找出一下 ...

  2. 04 Python入门学习-流程控制(if else elif while for)

    一:流程控制if 语法一: if 条件: code1 code2 code3 ... age = 20 height = 170 weight = 60 sex = 'female' is_beaut ...

  3. 实战:MySQL Sending data导致查询很慢的问题详细分析(转)

    出处:http://blog.csdn.net/yunhua_lee/article/details/8573621 这两天帮忙定位一个MySQL查询很慢的问题,定位过程综合各种方法.理论.工具,很有 ...

  4. 8-5 Navicat工具与pymysql模块

    一 Navicat 在生产环境中操作MySQL数据库还是推荐使用命令行工具mysql,但在我们自己开发测试时,可以使用可视化工具Navicat,以图形界面的形式操作MySQL数据库 需要掌握的基本操作 ...

  5. live kalilinux能保存文件和设置

    win32diskimager写入kalilinux镜像,建议用parrot sec os gparted /dev/sdb,新建分区sdb3,Lable输入persistence 挂载/dev/sd ...

  6. MFC中的主窗口修改标题

    MFC中的主窗口修改标题 如何去掉“无标题”1.在主程序中的InitInstance(): m_pMainWnd->SetWindowText("你要显示的东西如果不想显示置空就行&q ...

  7. ubuntu 安装 zend studio

    hi,everyone!2014 年到了,是20你死还是爱你一世,世人不得而知.夜观天象,道德依旧在沦丧,经济依然在滑坡.行了,就整这几句.最近在折腾linux,这篇文章,没有什么意义.只是找找写bl ...

  8. long polling

    Regular http: client 发出请求到server server 计算 response server 响应 response 给 client Polling: A client re ...

  9. Open XML操作Excel导入数据

    项目中发现使用OleDb(using System.Data.OleDb)相关对象处理Excel导入功能,不是很稳定经常出问题,需要把这个问题解决掉.项目组提出使用OpenXML来处理Excel的导入 ...

  10. IIS服务器添加网站

    1.添加IIS服务:对“我的电脑”右键,管理,点击服务和应用程序,如果下面没有”Internet Information Services(IIS)管理器“,打开控制面板,点击程序,启用或者关闭Win ...