题目链接:戳我

要注意因为数可能会对应很多人,但是输出的时候要按照添加的顺序输出。所以我们不能将相同值的节点合并,用set维护。就算值相同也只能新开节点。

然后就没有什么了。。。懒得写哈希表。。直接上map了。。开了O2之后也不是很慢qwq

代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#define ll long long
#define MAXN 6400010
#define ls (t[x].ch[0])
#define rs (t[x].ch[1])
using namespace std;
int rt,n,tot;
map<string,int> M;
string kkk,name[250010];
struct Node{int ch[2],ff,v,size;}t[MAXN]; void push_up(int x){t[x].size=t[ls].size+t[rs].size+1;} inline void rotate(int x)
{
int y=t[x].ff;
int z=t[y].ff;
int k=t[y].ch[1]==x;
t[z].ch[t[z].ch[1]==y]=x; t[x].ff=z;
t[y].ch[k]=t[x].ch[k^1]; t[t[x].ch[k^1]].ff=y;
t[x].ch[k^1]=y; t[y].ff=x;
push_up(y),push_up(x);
} void splay(int x,int goal)
{
while(t[x].ff!=goal)
{
int y=t[x].ff,z=t[y].ff;
if(z!=goal)
(t[y].ch[0]==x)^(t[z].ch[0]==y)?rotate(x):rotate(y);
rotate(x);
}
if(!goal)rt=x;
} void insert(int u,int id)
{
int x=rt;
for(;;)
{
if(!t[x].ch[u>t[x].v])
{
t[id].ff=x;t[id].v=u;t[id].size=1;
t[x].ch[u>t[x].v]=id;
splay(id,0);
break;
}
else x=t[x].ch[u>t[x].v];
}
} int _th(int K)
{
int x=rt;
for(;;)
{
if(t[ls].size+1==K) return x;
else if(t[ls].size>=K) x=ls;
else K-=t[ls].size+1,x=rs;
}
} void Del(int x)
{
splay(x,0);
int rk=t[ls].size;
int l=_th(rk),r=_th(rk+2);
splay(l,0);splay(r,l);t[r].ch[0]=0;
t[x].ff=t[x].size=t[x].v=0;
push_up(r);
push_up(l);
} void print(int x,int &sum)
{
if(!sum)return;
if(rs)print(rs,sum);
if(!sum)return;
if(x>2)
sum--,cout<<name[x]<<" ";
if(ls)print(ls,sum);
} int main()
{
#ifndef ONLINE_JUDGE
freopen("ce.in","r",stdin);
#endif
scanf("%d",&n);
insert(-2147483647,++tot);insert(2147483647,++tot);
while(n--)
{
char op;
cin>>op;
cin>>kkk;
if(op=='+')
{
int sco,id;
scanf("%d",&sco);
if(M[kkk])id=M[kkk],Del(id),insert(sco,id);
else
{
insert(sco,M[kkk]=++tot);
name[tot]=kkk;
}
}
else if(kkk[0]>='0'&&kkk[0]<='9')
{
int rk=0,l=kkk.length();
for(int i=0;i<l;++i) rk=rk*10+kkk[i]-'0';
l=_th(tot-rk+1);
splay(l,0);
int sum=10;
print(t[l].ch[0],sum);puts("");
}
else
{
int x=M[kkk];splay(x,0);
printf("%d\n",t[rs].size);
}
if(n%200==0) splay(rand()%tot+1,0);
}
return 0;
}

这道题过一段时间之后还要重写。。。实在是奇葩qwq

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

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

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

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

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

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

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

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

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

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

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

  6. 2021.12.07 P4291 [HAOI2008]排名系统(Treap)

    2021.12.07 P4291 [HAOI2008]排名系统(Treap) https://www.luogu.com.cn/problem/P4291 双倍经验: https://www.luog ...

  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. 1056: [HAOI2008]排名系统 - BZOJ

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

  9. P4291 [HAOI2008]排名系统

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

  10. COGS 197 [HAOI2008] 排名系统

    ★★★☆   输入文件:rank.in   输出文件:rank.out   简单对比 时间限制:1 s   内存限制:128 MB [题目描述] 排名系统通常要应付三种请求:上传一条新的得分记录.查询 ...

随机推荐

  1. slf4j日志框架

  2. ubuntu系统中出现mysql数据库无法启动报错2002该怎么处理,具体报错信息如正文所示

    python@ubuntu:~$ mysql -uroot -pmysqlmysql: [Warning] Using a password on the command line interface ...

  3. Nginx源码完全注释(9)nginx.c: ngx_get_options

    本文分析 ngxin.c 中的 ngx_get_options 函数,其影响: nginx.c 中的: static ngx_uint_t ngx_show_help; static ngx_uint ...

  4. SpringBoot Actuator & SpringBoot Admin

    SpringBoot Actuator提供了很多监控和管理你的spring boot应用的HTTP或者JMX端点,并且你可以有选择地开启和关闭部分功能. 当你的spring boot应用中引入依赖之后 ...

  5. 对比Nginx配置文件差异

    一.概要: Python2 官方文档:https://docs.python.org/2/library/difflib.html Python2 官方文档:https://docs.python.o ...

  6. VMware Workstation 虚拟机暂停后无法启动 出现Exception 0xc0000006 (disk error while paging) has occurred.错误

    虚拟机暂停了,突然停电,再开机后无法启动暂停的虚拟机,出现下面的错误 VMware Workstation unrecoverable error: (vmx)Exception 0xc0000006 ...

  7. [Plan]计划

    1. scala 2. kafka 1. lua 2. openResty 1. 日志收集 - python 2. 代码生成 3. 权限系统

  8. vmware centos7 静态ip设置

    最近在学习linux环境部署~~~~ 首先,将网络适配设置成为桥接模式 查看本机IP地址,ipconfig,记住ipv4地址和默认网关地址,等会配置的时候要用 启动Centos,进入终端模式,设置IP ...

  9. python excel 文件合并

    Combining Data From Multiple Excel Files Introduction A common task for python and pandas is to auto ...

  10. Auth模块

    文本目录 1 扩展默认的auth_user表 2 auth模块是什么 3 auth模块的常用方法 1 扩展默认的auth_user 表 在开始写项目之前,我们要创建表,同事内置的认证系统又很好用,但是 ...