题目大意:[洛谷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. android 自定义图片圆形进度条

    感觉话一个圆形进度条挺简单的 ,但是却偏偏给了几张图片让你话,说实话我没接触过,感觉好难,还好百度有大把的资源,一番努力下终于画出来了. 代码如下. package com.etong.cpms.wi ...

  2. MySQL 清除表空间碎片

    碎片产生的原因 (1)表的存储会出现碎片化,每当删除了一行内容,该段空间就会变为空白.被留空,而在一段时间内的大量删除操作,会使这种留空的空间变得比存储列表内容所使用的空间更大; (2)当执行插入操作 ...

  3. C语言学习记录_2019.02.02

    变量在第一次被使用之前应该赋初值 scanf(“%d”,&price); scanf(“price%d %d”,&price);  scanf中的东西一定是要输入的东西. 定义常量:c ...

  4. stm32+lwip(一):使用STM32CubeMX生成项目

    我是卓波,很高兴你来看我的博客. 系列文章: stm32+lwip(一):使用STM32CubeMX生成项目 stm32+lwip(二):UDP测试 stm32+lwip(三):TCP测试 stm32 ...

  5. ccpc 2018 final G - Pastoral Life in Stardew Valley

    #include <iostream> #include<cstdio> #include<cstring> #include<queue> using ...

  6. docker制作jdk+tomcat镜像

    docker部署TOMCAT项目 一.内核升级 [root@test01 ~]# uname -r   #内核查看确认 2.6.32-696.16.1.el6.x86_64 [root@test01 ...

  7. MapRudecer

    MapReducer基本概念 Mapreduce是一个分布式运算程序的编程框架,是用户开发“基于hadoop的数据分析应用”的核心框架: Mapreduce核心功能是将用户编写的业务逻辑代码和自带默认 ...

  8. python基础——重访类型分类

    python基础--重访类型分类 对象根据分类来共享操作:例如,字符串.列表和元组都共享诸如合并.长度和索引等序列操作. 只有可变对象(列表.字典和集合)可以原处修改:我们不能原处修改数字,字符串.元 ...

  9. android中activity,window,view之间的关系

    activity:控制单元 window:承载模型 view:显示视图 几个小tip: 1.一个 Activity 构造的时候一定会构造一个 Window(PhoneWindow),并且只有一个 2. ...

  10. CSS3 : box-shadow

    box-shadow 用于设置边框阴影,语法: box-shadow: h-shadow v-shadow blur spread color inset; -moz-box-shadow: h-sh ...