Description

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

第一行是一个整数n(n>=10)表示请求总数目。接下来n行,每行包含了一个请求。请求的具体格式如下: +Name Score 上传最新得分记录。Name表示玩家名字,由大写英文字母组成,不超过10个字符。Score为最多8位的正整数。 ?Name 查询玩家排名。该玩家的得分记录必定已经在前面上传。 ?Index 返回自第Index名开始的最多10名玩家名字。Index必定合法,即不小于1,也不大于当前有记录的玩家总数。
Output

对于?Name格式的请求,应输出一个整数表示该玩家当前的排名。对于?Index格式的请求,应在一行中依次输出从第Index名开始的最多10名玩家姓名,用一个空格分隔。
Sample Input
20
+ADAM 1000000 加入ADAM的得分记录
+BOB 1000000 加入BOB的得分记录
+TOM 2000000 加入TOM的得分记录
+CATHY 10000000 加入CATHY的得分记录
?TOM 输出TOM目前排名
?1 目前有记录的玩家总数为4,因此应输出第1名到第4名。
+DAM 100000 加入DAM的得分记录
+BOB 1200000 更新BOB的得分记录
+ADAM 900000 更新ADAM的得分记录(即使比原来的差)
+FRANK 12340000 加入FRANK的得分记录
+LEO 9000000 加入LEO的得分记录
+KAINE 9000000 加入KAINE的得分记录
+GRACE 8000000 加入GRACE的得分记录
+WALT 9000000 加入WALT的得分记录
+SANDY 8000000 加入SANDY的得分记录
+MICK 9000000 加入MICK的得分记录
+JACK 7320000 加入JACK的得分记录
?2 目前有记录的玩家总数为12,因此应输出第2名到第11名。
?5 输出第5名到第13名。
?KAINE 输出KAINE的排名
Sample Output
2
CATHY TOM ADAM BOB
CATHY LEO KAINE WALT MICK GRACE SANDY JACK TOM BOB
WALT MICK GRACE SANDY JACK TOM BOB ADAM DAM
4

HINT

20%数据满足N<=100 100%数据满足N<=250000

唉,splay真的不是很熟练啊

又调了一上午,不过还是有一点收获的,每次发现超时都是因为找答案的方法不够好(当你要l到r的答案时,1.把l到r全部旋到一起 2.把l旋到根然后往右边遍历)

 const
maxn=;
type
node=record
son:array[..]of longint;
size,fa,f,t:longint;
str:string;
end;
var
tree:array[..maxn*]of node;
hash,next:array[..maxn*]of longint;
n,tot,time,root,k,num:longint; function hashx(s:string):longint;
var
i:longint;
begin
hashx:=;
for i:= to length(s) do
hashx:=(hashx*+ord(s[i])-ord('A'))mod maxn;
inc(hashx);
end; function get(s:string):longint;
begin
get:=hashx(s);
while (tree[get].str<>s) and (get<>) do
get:=next[get];
end; procedure rotate(x,w:longint);
var
y:longint;
begin
y:=tree[x].fa;
tree[y].son[w]:=tree[x].son[w xor ];
if tree[x].son[w xor ]<> then tree[tree[x].son[w xor ]].fa:=y;
tree[x].son[w xor ]:=y;
if root=y then root:=x
else
if tree[tree[y].fa].son[]=y then tree[tree[y].fa].son[]:=x
else tree[tree[y].fa].son[]:=x;
tree[x].fa:=tree[y].fa;
tree[y].fa:=x;
with tree[y] do
size:=tree[son[]].size++tree[son[]].size;
end; procedure splay(x,z:longint);
var
y:longint;
begin
while tree[x].fa<>z do
begin
y:=tree[x].fa;
if tree[y].fa=z then
if tree[y].son[]=x then rotate(x,)
else rotate(x,)
else
if tree[tree[y].fa].son[]=y then
if tree[y].son[]=x then
begin
rotate(y,);
rotate(x,);
end
else
begin
rotate(x,);
rotate(x,);
end
else
if tree[y].son[]=x then
begin
rotate(x,);
rotate(x,);
end
else
begin
rotate(y,);
rotate(x,);
end;
end;
with tree[x] do
size:=tree[son[]].size++tree[son[]].size;
end; procedure delete(x:longint);
var
l,r:longint;
begin
splay(x,);
l:=tree[x].son[];
r:=tree[x].son[];
if (l=) or (r=) then
begin
root:=l+r;
tree[l+r].fa:=;
tree[x].son[]:=;
tree[x].son[]:=;
end
else
begin
while tree[l].son[]<> do
l:=tree[l].son[];
while tree[r].son[]<> do
r:=tree[r].son[];
splay(l,);
splay(r,l);
tree[r].son[]:=;
dec(tree[r].size);
dec(tree[l].size);
tree[x].fa:=;
end;
end; procedure add(x:longint);
var
now:longint;
begin
if root= then
begin
root:=x;
tree[x].fa:=;
tree[x].size:=;
end
else
begin
now:=root;
while true do
begin
inc(tree[now].size);
if (tree[x].f>tree[now].f) or ((tree[x].f=tree[now].f) and (tree[x].t<tree[now].t)) then
if tree[now].son[]= then break
else now:=tree[now].son[]
else
if tree[now].son[]= then break
else now:=tree[now].son[];
end;
if (tree[x].f>tree[now].f) or ((tree[x].f=tree[now].f) and (tree[x].t<tree[now].t)) then tree[now].son[]:=x
else tree[now].son[]:=x;
tree[x].size:=;
tree[x].fa:=now;
end;
splay(x,);
end; procedure insert(s:string;x:longint);
var
z:longint;
begin
z:=get(s);
if z> then
begin
delete(z);
tree[z].t:=time;
tree[z].f:=x;
add(z);
end
else
begin
z:=hashx(s);
inc(num);
if tree[z].str='' then
begin
tree[z].str:=s;
tree[z].t:=time;
tree[z].f:=x;
add(z);
end
else
begin
while next[z]<> do
z:=next[z];
inc(tot);
next[z]:=tot;
tree[tot].str:=s;
tree[tot].t:=time;
tree[tot].f:=x;
add(tot);
end;
end;
end; function find(x:longint):longint;
var
now:longint;
begin
now:=root;
while true do
begin
if x<=tree[tree[now].son[]].size then now:=tree[now].son[]
else
if x=tree[tree[now].son[]].size+ then exit(now)
else
begin
dec(x,tree[tree[now].son[]].size+);
now:=tree[now].son[];
end;
end;
end; procedure dfs(now:longint);
begin
if k= then exit;
if tree[now].son[]<> then dfs(tree[now].son[]);
if k= then exit;
inc(k);
write(' ',tree[now].str);
if k= then exit;
if tree[now].son[]<> then dfs(tree[now].son[]);
end; function min(x,y:longint):longint;
begin
if x<y then exit(x);
exit(y);
end; procedure main;
var
x:longint;
c:char;
s:string;
begin
readln(n);
tot:=maxn;
for time:= to n do
begin
read(c);
if c='+' then
begin
read(c);
s:='';
while c<>' ' do
begin
s:=s+c;
read(c);
end;
readln(x);
insert(s,x);
end
else
if c='?' then
begin
readln(s);
if (ord(s[])>=ord('A')) and (ord(s[])<=ord('Z')) then
begin
splay(get(s),);
writeln(tree[tree[root].son[]].size+);
end
else
begin
val(s,x);
splay(find(x),);
write(tree[root].str);
if num>x then splay(find(min(num,x+)),root);
k:=;
if tree[root].son[]<> then dfs(tree[root].son[]);
writeln;
end;
end;
end;
end; begin
main;
end.

1056: [HAOI2008]排名系统 - BZOJ的更多相关文章

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

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

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

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

  3. bzoj 1862/1056 [HAOI2008]排名系统

    原题链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1862 很恶心的 一道题,我也不晓得自己是第几次写这题了%>_<%. 写了两种方 ...

  4. [BZOJ 1056][HAOI2008]排名系统

    传送门 \(\color{green}{solution}\) \(fhq \_treap\)模板题. 对于 \(+\) 操作,如果当前人不存在,那么直接加入;如果存在,那么先将他删除,再加入.复杂度 ...

  5. bzoj 1862: [Zjoi2006]GameZ游戏排名系统 & bzoj 1056: [HAOI2008]排名系统

    傻叉了一晚上,把t打成x,然后这题神奇在于输出一段数,不足的不用输出,一开始我的是直接找没有后面就退,然后这样会格式错误囧……然后最后zj的还卡了下空间,于是不用string就过了……string毁一 ...

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

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

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

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

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

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

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

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

随机推荐

  1. ActiveMQ(5.10.0) - Destination-level authorization

    To build upon authentication, consider a use case requiring more fine-grained control over clients t ...

  2. JavaScript之模拟评星打分

    <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312&qu ...

  3. kettle列转行

  4. sql server日期时间转字符串(转)

    一.sql server日期时间函数Sql Server中的日期与时间函数 1.  当前系统日期.时间     select getdate()  2. dateadd  在向指定日期加上一段时间的基 ...

  5. Stored Procedures with Multiple Result Sets

    Stored Procedures with Multiple Result Sets https://msdn.microsoft.com/en-us/data/jj691402.aspx

  6. NodeJS安全设计:好吃的草莓味糖果,只给好朋友小红

    上一篇文章中,我们已经建立了一个有缓冲机制的文件服务器,能给客户端响应附件类型的文件,其实,就爱莲(iLinkIT)而言,NodeJS的模块做到这样也就已经可以了,因为使用的场景就是电脑和手机之间,与 ...

  7. 【转载】应读者强烈要求给出《超容易的Linux系统管理入门书》一书的主要知识点

    刚开始了一篇连载,收到广大Linux爱好者的反馈,非常欣慰.大家对Linux学习感到很迷茫,不知道学哪些内容,如何学习? <超容易的Linux系统管理入门书>一书是腾讯Linux专家在腾讯 ...

  8. CAF(C++ actor framework)使用随笔(延迟发送,消息转发,消息优先级)(四)

    e). 消息延迟发送(和前面没太大区别直接上代码) #include <iostream> #include "caf/all.hpp" #include " ...

  9. 《java编程思想》--多线程基础--Runnable

    一.简单说下Runnable是什么 1.它是一个接口 2.只提供了run方法 3.这个接口提供了一个协议:实现这个接口的类是active的(不必成为Thread的子类) 4.run方法没有返回值 /* ...

  10. c#中的枚举

    1.枚举概念:枚举是用户定义的整型类型,在声明一个枚举时,要指定该枚举的实例可以包含的一组可接受的值,还可以给值指定易于记忆的名称.如果在代码的某个地方,要试图把一个不可接受范围内的值赋予枚举的一个实 ...