题目链接:戳我

要注意因为数可能会对应很多人,但是输出的时候要按照添加的顺序输出。所以我们不能将相同值的节点合并,用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. C++虚函数表理解

    一,思维模式图 二,代码验证 class A { public: A(int x) { fProtected = x; } float GetFProtected() { return fProtec ...

  2. 【298】◀▶ IDL 系统过程&函数

    参考: Programming and Control 序号 类名称   功能说明   语法 & 举例 01 DEFSYSV   ====<<<< Descriptio ...

  3. 通过devtools在centos系统中启用高版本的gcc

    C++11出来好久了,现在还是使用c++03的,需要在centos6.6的系统上实现gcc的升级,又不想自己编译代码. 于是选用了devtoolsset系列,安装脚本如下 安装脚本如下 functio ...

  4. [iOS]UIScrollView嵌套内容在左右拨动的时候自动被顶上问题

    遇到的问题是这样的: 适配6+没问题,但是5s就出问题.我UIScrollView嵌套了左侧UIScrollView,右侧UITableView,左右拨动切换,结果5s下拨动之后两边的View都会自动 ...

  5. 第2章地址Address(WCF全面解析3)

    WCF顾明思义,就是在Windows平台下解决通信(C,Communication)的基础框架(F,Foundation)问题. 终结点是WCF最为核心的对象,因为它承载了所有通信功能.服务通过相应的 ...

  6. FastDFS 分布式文件系统

    1       学习目标 了解项目中使用FastDFS的原因和意义. 掌握FastDFS的架构组成部分,能说出tracker和storage的作用. 了解FastDFS+nginx上传和下载的执行流程 ...

  7. Solo and Mute

    [Solo and Mute ] Muting means a transition will be disabled. Soloed transtions are enabled and with ...

  8. 欲望都市游戏设计 背景图层和UI图层的设计

  9. 【LA3211 训练指南】飞机调度 【2-sat】

    题意 有n嫁飞机需要着陆.每架飞机都可以选择“早着陆”和“晚着陆”两种方式之一,且必须选择一种.第i架飞机的早着陆时间为Ei,晚着陆时间为Li,不得在其他时间着陆.你的任务是为这些飞机安排着陆方式,使 ...

  10. Codeforces 667C DP

    题意:给你一个字符串,这个字符串的构造方法如下:先选择一个长度大于4的前缀,然后每次向字符串尾部添加一个长度为2或者长度为3的后缀,不能添加连续的相同的后缀,问可能的后缀有哪些?并按字典序输出去. 思 ...