题目大意:[洛谷P4291][HAOI2008]排名系统(双倍经验)

解:

卡点:

C++ Code:

#include <cstdio>
#include <map>
#include <iostream>
#define maxn 250010
std::map<std::string, int> name;
int n, namenum;
struct node {
int v, p;
inline node(int __v = 0, int __p = 0) {v = __v, p = __p;}
inline friend bool operator > (const node &lhs, const node &rhs) {
if (lhs.v == rhs.v) return lhs.p < rhs.p;
return lhs.v > rhs.v;
}
inline friend bool operator == (const node &lhs, const node &rhs) {return lhs.v == rhs.v && lhs.p == rhs.p;}
inline friend bool operator >= (const node &lhs, const node &rhs) {return lhs > rhs || lhs == rhs;}
}; namespace Treap {
int lc[maxn], rc[maxn], num[maxn], sz[maxn];
node val[maxn];
int root, idx;
int ta, tb, tmp, res;
int seed = 20040826;
inline int rand() {return seed *= 48271;} inline int update(int rt) {
sz[rt] = sz[lc[rt]] + sz[rc[rt]] + 1;
return rt;
}
inline int nw(node x) {
val[++idx] = x;
num[idx] = rand();
sz[idx] = 1;
return idx;
}
void split(int rt, node k, int &x, int &y) {
if (!rt) x = y = 0;
else {
if (val[rt] >= k) split(rc[rt], k, rc[rt], y), x = update(rt);
else split(lc[rt], k, x, lc[rt]), y = update(rt);
}
}
void split(int rt, int k, int &x, int &y) {
if (!rt) x = y = 0;
else {
if (sz[lc[rt]] < k) split(rc[rt], k - sz[lc[rt]] - 1, rc[rt], y), x = update(rt);
else split(lc[rt], k, x, lc[rt]), y = update(rt);
}
}
int merge(int x, int y) {
if (!x || !y) return x | y;
if (num[x] < num[y]) {rc[x] = merge(rc[x], y); return update(x);}
else {lc[y] = merge(x, lc[y]); return update(y);}
} inline int gtrnk(node x) {
split(root, x, ta, tb);
res = sz[ta];
root = merge(ta, tb);
return res;
}
inline node gtkth(int k) {
tmp = root;
while (true) {
if (sz[lc[tmp]] >= k) tmp = lc[tmp];
else {
if (sz[lc[tmp]] + 1 == k) return val[tmp];
else k -= sz[lc[tmp]] + 1, tmp = rc[tmp];
}
}
} void insert(node x) {
if (!root) root = nw(x);
else {
split(root, x, ta, tb);
root = merge(merge(ta, nw(x)), tb);
}
}
void erase(node x) {
split(root, x, ta, tb);
split(ta, sz[ta] - 1, ta, tmp);
root = merge(ta, tb);
}
} int val[maxn];
std::string retname[maxn];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
char op;
std::string s;
std::cin >> op >> s;
if (op == '+') {
int x;
std::cin >> x;
if (name.count(s)) {
int pos = name[s];
Treap::erase(node(val[pos], pos));
namenum--;
}
namenum++;
name[s] = i;
retname[i] = s;
val[i] = x;
Treap::insert(node(x, i));
} else if (isdigit(s[0])) {
int pos = 0, posend;
for (std::string::iterator it = s.begin(); it != s.end(); it++) pos = pos * 10 + (*it & 15);
posend = std::min(pos + 9, namenum);
for (int i = pos; i <= posend; i++) {
std::cout << retname[Treap::gtkth(i).p];
putchar(i == posend ? '\n' : ' ');
}
} else {
int pos = name[s];
std::cout << Treap::gtrnk(node(val[pos], pos)) << std::endl;
} }
return 0;
}

  

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

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

    实在不想调了QAQ... Code: #include <cstdio> #include <algorithm> #include <cstring> #incl ...

  2. BZOJ 1862: [Zjoi2006]GameZ游戏排名系统 [treap hash]

    1862: [Zjoi2006]GameZ游戏排名系统 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1318  Solved: 498[Submit][ ...

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

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

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

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. jquery把数组中年月相同的数组重新组成新的数组

    //原数组var data = { results: [{ id:0, date:'2017-12-12', content:'123' },{ id:0, date:'2017-12-12', co ...

  2. 解决每次运行Xcode,都需要输入密码的问题

    新买的Mac,在安装了 Xcode 7.1的时候,不知道是配置信息哪里手残了一下,导致每次运行Xcode模拟器 后 都需要输入一次密码. 为此在网上也是查阅了不少的资料,当时 所谓的 XCode--- ...

  3. svg在html的使用

    <svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'> <defs&g ...

  4. Nodejs 使用 addons 调用c++ 初体验(一)

    纠结很久,决定写一点遇到的“坑”. 基础环境:win7-64bit  node(v7.5.0)   这些安装实在是太方便了,自行准备吧. 1. 安装 python(2.7.x ),用npm安装 nod ...

  5. Cent OS 下 VI 使用方法

    vi的基本概念  基本上vi可以分为三种状态,分别是命令模式(command mode).插入模式(Insert mode)和底行模式(last line mode),各模式的功能区分如下: 1) 命 ...

  6. python2.7练习小例子(十)

        10):古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少?     程序分析:兔子的规律为数列1,1 ...

  7. 3,jieba gensim 最好别分家之最简单的相似度实现

    简单的问答已经实现了,那么问题也跟着出现了,我不能确定问题一定是"你叫什么名字",也有可能是"你是谁","你叫啥"之类的,这就引出了人工智能 ...

  8. delphi 数据库中Connection与Query连接数量问题思考

    今天闲着没事,测试了一下Connection连接MSSQL,可以承受多少连接.    1.看看ADOConnection的连接数:写了一个代码,动态创建,测试了10000个连接,花了大约5~10分钟创 ...

  9. oracle 11g XE 学习版添加scott用户方法全步骤

    安装企业版的orcale是不是太费时费力了?若只是学习用途的话,不妨试试轻便版的XE版本,同样是官网下载的,但是这个安装起来比完整版简便多了. 首先,你得先安装好orcale 11g XE 版本:(这 ...

  10. Java:static的作用分析

    static表示“静态”或者“全局”的意思,但在Java中不能在所有类之外定义全局变量,只能通过在一个类中定义公用.静态的变量来实现一个全局变量. 一.静态变量 1. Java中存在两种变量,一种是s ...