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. js如何判断一个数组中是否有重复的值

    引自:http://bbs.tianya.cn/post-414-38497-1.shtml 方法一: var ary = new Array("111","22&quo ...

  2. 7 个基本的 JS 函数【译】

    本文由 伯乐在线 - 刘健超-J.c 翻译,进林 校稿.未经许可,禁止转载!英文出处:davidwalsh.name.欢迎加入翻译组. 我记得早期的 JavaScript ,要完成任何事情几乎都绕不开 ...

  3. Slickflow.NET 开源工作流引擎基础介绍(四) -- 多数据库支持实现

    前言:引擎作为中间件集成到用户的项目里面去,针对用户的数据库类型,需要作出SQL部分的分别实现.引擎默认数据库为MS SQLSERVER,同时也支持ORACLE, MYSQL, KINGBASE等不同 ...

  4. .net中判断该应用程序是否已经启动,防止重复启动,监控程序启动是否正常

    //获取配置文件中的需要监控项 private static string MonitorServe = ConfigurationSettings.AppSettings["Monitor ...

  5. Android之线程终止

    Hanlder是线程与Activity通信的桥梁,利用handler接收到任务线程,放到任务队列里面派对执行. 1.初始化的时候,定义启动的线程为一个守护线程,这样当主线程消亡掉的时候,其他线程也会被 ...

  6. MySQL之经典语句

    数据库的创建:(例如创建名为ConstructionDB的数据库) --创建SelfStudy数据库 CREATE DATABASE ConstructionDB ON PRIMARY --创建主数据 ...

  7. 个人常用jq方法复习

    $("#elem").on({ mouseover:function(){}, mouseout:function(){}, }); $(ele).closest("di ...

  8. phpwind wap功能添加百度wap统计

    百度推出wap统计功能后,及大的方便了个站长对wap网站的统计.PHPWIND自带的wap功能虽然说功能不是太强,但是对百度来说是非常友好的,如果再进一不优化一下页面模板,这样会对网友访问网站信息有非 ...

  9. oracle视图索引

    reate table fleet_header(  day date,name varchar2(20),  route_id number(5),fleet_id number(5)); crea ...

  10. echarts标准饼图解读(一)——提示框(tooltip)配置

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...