HNOI2008 and ZJOI2006 排名系统
1056: [HAOI2008]排名系统
Time Limit: 10 Sec Memory Limit: 162 MB
Submit: 1311 Solved: 337
[Submit][Status]
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
+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
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为什么跑得这么慢?????
先是WA,然后是TLE,后来有MLE。。。我已经彻底无语了。。。
是我写跪了,还是怎么的。。。不得已只好上lyd的代码了。。。
代码:
1.mine
- {$inline on}
- const maxn=+;inf=maxlongint;
- var s,fa,v,next:array[..maxn] of longint;
- ss:array[..maxn] of string[];
- head:array[..] of longint;
- c:array[..maxn,..] of longint;
- i,j,n,x,y,rank,rt,tot,cnt:longint;
- st,name:ansistring;
- first:boolean;
- ch:char;
- function hash(s:ansistring):int64;inline;
- var i,x:longint;
- begin
- x:=;
- for i:= to length(s) do x:=(x*+ord(s[i])-ord('A')+) mod ;
- i:=head[x];
- while i<> do
- begin
- if ss[i]=s then exit(i);
- i:=next[i];
- end;
- inc(tot);ss[tot]:=s;v[tot]:=y;next[tot]:=head[x];head[x]:=tot;
- exit();
- end;
- procedure pushup(x:longint);inline;
- begin
- s[x]:=s[c[x,]]+s[c[x,]]+;
- end;
- procedure rotate(x:longint;var k:longint);inline;
- var y,z,l,r:longint;
- begin
- y:=fa[x];z:=fa[y];
- l:=ord(c[y,]=x);r:=l xor ;
- if y=k then k:=x else c[z,ord(c[z,]=y)]:=x;
- fa[x]:=z;fa[y]:=x;fa[c[x,r]]:=y;
- c[y,l]:=c[x,r];c[x,r]:=y;
- pushup(y);pushup(x);
- end;
- procedure splay(x:longint;var k:longint);inline;
- var y,z:longint;
- begin
- while x<>k do
- begin
- y:=fa[x];z:=fa[y];
- if y<>k then
- if (c[z,]=y) xor (c[y,]=x) then rotate(x,k)
- else rotate(y,k);
- rotate(x,k);
- end;
- end;
- function find(x,rank:longint):longint;inline;
- var l,r:longint;
- begin
- l:=c[x,];r:=c[x,];
- if s[l]+=rank then exit(x)
- else if s[l]>=rank then exit(find(l,rank))
- else exit(find(r,rank-s[l]-));
- end;
- procedure insert(var x:longint;f,k:longint);inline;
- begin
- if x= then
- begin
- fa[k]:=f;
- x:=k;
- s[k]:=;
- c[k,]:=;c[k,]:=;
- exit;
- end;
- inc(s[x]);
- if v[k]>v[x] then insert(c[x,],x,k) else insert(c[x,],x,k);
- end;
- procedure del(rank:longint);inline;
- var x,y,z:longint;
- begin
- x:=find(rt,rank-);y:=find(rt,rank+);
- splay(x,rt);splay(y,c[x,]);
- z:=c[y,];fa[z]:=;c[y,]:=;s[z]:=;
- pushup(y);pushup(x);
- end;
- procedure print(x:longint);inline;
- begin
- if x= then exit;
- print(c[x,]);
- if first then begin first:=false;write(ss[x]);end else write(' ',ss[x]);
- print(c[x,]);
- end;
- procedure main;
- begin
- readln(n);
- rt:=n+;fa[n+]:=;v[n+]:=-inf;v[n+]:=inf;
- insert(rt,,n+);
- tot:=;
- for j:= to n do
- begin
- read(ch);
- case ch of
- '+':begin
- readln(st);
- name:=copy(st,,pos(' ',st)-);
- delete(st,,pos(' ',st));
- val(st,y);
- x:=hash(name);
- if x= then insert(rt,,tot)
- else
- begin
- splay(x,rt);del(s[c[rt,]]+);
- v[x]:=y;
- insert(rt,,x);
- end;
- end;
- '?':begin
- readln(st);
- if (ord(st[])>ord('')) and (ord(st[])<=ord('')) then
- begin
- val(st,rank);
- x:=find(rt,rank);
- if rank+<=tot then y:=find(rt,rank+) else y:=find(rt,tot+);
- splay(x,rt);splay(y,c[x,]);
- first:=true;print(c[y,]);writeln;
- end
- else
- begin
- x:=hash(st);
- splay(x,rt);
- writeln(s[c[x,]]);
- end;
- end;
- end;
- end;
- end;
- begin
- assign(input,'input.txt');assign(output,'output.txt');
- reset(input);rewrite(output);
- main;
- close(input);close(output);
- end.
2.lyd
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- using namespace std;
- const int u=,mod=;
- struct splaytree{
- int l,r,dat,size;
- #define l(x) t[x].l
- #define r(x) t[x].r
- #define dat(x) t[x].dat
- #define size(x) t[x].size
- }t[u];
- unsigned long long ver[u],temp;
- int L[u],R[u],head[],sc[u],id[u],next[u];
- char name[u][],str[];
- int n,m,tot,root,i,j,x,y,sco,z,now,rec;
- int hash(int x,int y)
- {
- int i,z;
- for(temp=,i=;i<strlen(str);i++) temp=temp*+str[i]-'A'+;
- z=temp%mod;
- for(i=head[z];i;i=next[i])
- if(ver[i]==temp) return i;
- ver[++m]=temp; sc[m]=x; id[m]=y;
- next[m]=head[z]; head[z]=m;
- for(i=;i<strlen(str);i++) name[m][i-]=str[i]; name[m][i-]='\0';
- return m;
- }
- inline void update(int x)
- {
- size(x)=size(l(x))+size(r(x))+;
- }
- inline void zig(int &x)
- {
- int y=l(x); l(x)=r(y); r(y)=x;
- update(x),update(y),x=y;
- }
- inline void zag(int &x)
- {
- int y=r(x); r(x)=l(y); l(y)=x;
- update(x),update(y),x=y;
- }
- inline int cmp(int x,int p)
- {
- int y=dat(p);
- if(sc[x]==sc[y]&&id[x]==id[y]) return ;
- if(sc[x]>sc[y]||sc[x]==sc[y]&&id[x]<id[y]) return -;
- return ;
- }
- inline void splay(int &x,int y)
- {
- int i; L[]=R[]=;
- while()
- {
- i=cmp(y,x);
- if(!i||!l(x)&&i<||!r(x)&&i>) break;
- if(i<)
- {
- if(cmp(y,l(x))<) {zig(x); if(!l(x)) break;}
- R[++R[]]=x; x=l(x);
- }
- else{
- if(cmp(y,r(x))>) {zag(x); if(!r(x)) break;}
- L[++L[]]=x; x=r(x);
- }
- }
- L[L[]+]=l(x); R[R[]+]=r(x);
- for(i=L[];i;i--) {r(L[i])=L[i+]; update(L[i]);}
- for(i=R[];i;i--) {l(R[i])=R[i+]; update(R[i]);}
- l(x)=L[]; r(x)=R[]; update(x);
- }
- void insert(int x)
- {
- tot++; dat(tot)=x; size(tot)=;
- if(!root) {root=tot; return;}
- splay(root,x);
- if(cmp(x,root)<) l(tot)=l(root),l(root)=tot;
- else r(tot)=r(root),r(root)=tot;
- update(tot),update(root);
- }
- void clear(int x)
- {
- splay(root,x);
- if(!l(root)) {root=r(root); return;}
- splay(l(root),x);
- r(l(root))=r(root); root=l(root);
- update(root);
- }
- void ask(int x)
- {
- splay(root,x);
- printf("%d\n",size(l(root))+);
- }
- void dfs(int x)
- {
- if(l(x)&&now) dfs(l(x));
- if(now) {now--; printf(" %s",name[dat(x)]);}
- if(r(x)&&now) dfs(r(x));
- }
- void print(int rank)
- {
- int x;
- for(x=root;;)
- if(size(l(x))+==rank) break;
- else if(rank<=size(l(x))) x=l(x);
- else rank-=size(l(x))+,x=r(x);
- printf("%s",name[dat(x)]);
- splay(root,dat(x));
- now=; if(r(x)) dfs(r(x));
- puts("");
- }
- int main()
- {
- cin>>n;
- for(i=;i<=n;i++)
- {
- scanf("%s",str);
- if(str[]=='+')
- {
- scanf("%d",&sco);
- rec=m;
- z=hash(sco,i);
- if(rec==m) {clear(z); sc[z]=sco; id[z]=i;}
- insert(z);
- }
- else if(str[]>=''&&str[]<='')
- {
- for(j=,x=;j<strlen(str);j++) x=x*+str[j]-'';
- print(x);
- }
- else ask(hash(,));
- }
- return ;
- }
HNOI2008 and ZJOI2006 排名系统的更多相关文章
- [BZOJ1056][BZOJ1862][HAOI2008][Zjoi2006]排名系统
[BZOJ1056][BZOJ1862][HAOI2008][Zjoi2006]排名系统 试题描述 排名系统通常要应付三种请求:上传一条新的得分记录.查询某个玩家的当前排名以及返回某个区段内的排名记录 ...
- BZOJ 1862: [Zjoi2006]GameZ游戏排名系统 [treap hash]
1862: [Zjoi2006]GameZ游戏排名系统 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1318 Solved: 498[Submit][ ...
- 【洛谷P2584】【ZJOI2006】GameZ游戏排名系统题解
[洛谷P2584][ZJOI2006]GameZ游戏排名系统题解 题目链接 题意: GameZ为他们最新推出的游戏开通了一个网站.世界各地的玩家都可以将自己的游戏得分上传到网站上.这样就可以看到自己在 ...
- 【BZOJ1862】[ZJOI2006]游戏排名系统 (Splay)
[BZOJ1862][ZJOI2006]游戏排名系统 (Splay) 题面 BZOJ 洛谷 题解 双倍经验题
- BZOJ_1862_[Zjoi2006]GameZ游戏排名系统&&BZOJ_1056_[HAOI2008]排名系统_Splay
BZOJ_1862_[Zjoi2006]GameZ游戏排名系统&&BZOJ_1056_[HAOI2008]排名系统_Splay Description 排名系统通常要应付三种请求:上传 ...
- 【BZOJ】1862: [Zjoi2006]GameZ游戏排名系统 & 1056: [HAOI2008]排名系统(treap+非常小心)
http://www.lydsy.com/JudgeOnline/problem.php?id=1862 http://www.lydsy.com/JudgeOnline/problem.php?id ...
- bzoj 1056 [HAOI2008]排名系统(1862 [Zjoi2006]GameZ游戏排名系统)
1056: [HAOI2008]排名系统 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1854 Solved: 502[Submit][Statu ...
- 1056/1862. [ZJOI2006]GameZ游戏排名系统【平衡树-splay】
Description GameZ为他们最新推出的游戏开通了一个网站.世界各地的玩家都可以将自己的游戏得分上传到网站上.这样就可以看到自己在世界上的排名.得分越高,排名就越靠前.当两个玩家的名次相同时 ...
- [HAOI2008]排名系统& [Zjoi2006]GameZ游戏排名系统
1056: [HAOI2008]排名系统 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2487 Solved: 711[Submit][Statu ...
随机推荐
- ThinkPad E40无线网卡驱动安装 FOR CENTOS6.3
1.看一下咱们用的本本的无线是咋子无线网卡,如下: [root@liaohg Downloads]# lspci | grep Wireless 03:00.0 Network controller: ...
- JavaScript之Function类型
1. 创建方式 //1.函数声明 function sum(num1,num2){ return num1+num2; } //2.函数表达式 var sum = function(num1,num2 ...
- 关于tableView的那些坑(一)—— automaticallyAdjustsScrollViewInsets属性
最近用tabbar来切换控制器,用childViewController来实现多控制器管理,多列表切换,在子控制器中设置了automaticallyAdjustsScrollViewInsets属性为 ...
- Xcode中实现ARC和MRC混编
1.在Xcode中打开项目文件 2.选中项目名称 3.在右侧选择build phass 选项卡 4.选择 complite source 选项 5.选择要支持MRC编译的.m文件,双击 6.在弹出的框 ...
- C#语言之“string格式的日期时间字符串转为DateTime类型”的方法(转)
原文链接:http://www.cnblogs.com/Pickuper/articles/2058880.html 方法一:Convert.ToDateTime(string) string格式有要 ...
- ASP.NET一些常用的东西
三层架构的命名: UI: User Interface (数据显示层 用户界面)BLL:Business Logic Layer (业务逻辑层)DAL:Data Access Layer (数据访问层 ...
- linux中python环境搭建及升级后yum不可用解决方案
1.1 LinuxCentOS 为例.1.1.1 升级 Python(1) 下载 Python 版本$ wget https://www.python.org/ftp/python/2.7.11/Py ...
- jbpm4.4 spring整合
jBPM-4.4与Spring集成配置比较容易,这里我使用的是Spring-2.5.6,数据库连接池使用C3P0,将相关的两个jar文件加入到CLASSPATH中. jBPM-4.4与Spring集成 ...
- 《C和指针》章节后编程练习解答参考——第9章
9.1 #include <stdio.h> #include <ctype.h> #include <string.h> #define N 100 int ma ...
- POJ 1416 Shredding Company
题目: http://poj.org/problem?id=1416 又16ms 1A了,这人品... #include <stdio.h> #include <string.h&g ...