题目大意:[洛谷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. 【c语言学习-11】

    /*指针*/ #include void charPointFunction(){ //字符型数组 char *x="I like code",y[10];//使x[]初始化,使y ...

  2. Python正则表达式-基础

    Python正则表达式-基础 本文转载自昔日暖阳,原文地址:http://www.osheep.cn/4806.html python使用正则,需要先引入re模块 import re 匹配符 单个字符 ...

  3. 自己动手编写 Dockerfile 构建自定义的Jenkins

    1.构建jenkins 镜像 vim Dockerfile FROM jenkins  USER root ARG dockerGid=999  RUN echo "docker:x:${d ...

  4. .NET CORE LOG

    .NET CORE LOG 合格的应用程序不仅要求运行的高效和计算的准确,稳定及可靠性也要得到满足,同事,系统的可维护性也相当重要.谈及到可维护性,就必须涉及到系统运行状态的监控和异常的快速定位与跟踪 ...

  5. Windows下使用PHP Xdebug

    首先下载Xdebug的dll:http://xdebug.org/download.php 将dll文件放到php目录下的ext目录里面: 修改php.ini,根据自己的需要增加信息: [Xdebug ...

  6. C++11中std::function的使用

    class template std::function is a general-purpose polymorphic function wrapper. Instances of std::fu ...

  7. Python字符串处理:过滤字符串中的英文与符号,保留汉字

    使用Python 的re模块,re模块提供了re.sub用于替换字符串中的匹配项. re.sub(pattern, repl, string, count=0) 参数说明: pattern:正则重的模 ...

  8. Jquery操作select选项集合!

    Query获取Select选择的Text和Value: 1. $("#select_id").change(function(){//code...}); //为Select添加事 ...

  9. 使用LinqToExcel和EPPlus操作excel

    1.使用LinqToExcel LinqToExcel是一个.net framework平台下开源项目,它主要实现了LINQ的语法查询Excel电子表格.类型之前的LINQToXXX如果你是LINQ语 ...

  10. awk用法介绍

    Awk 程序的结构如下: awk 'BEGIN{ print "start" } pattern { commands } END{ print "end" } ...