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

const
maxn=;
mm=;
var
hash,size,left,right,fix,value,time,num,shi,cost:array[..maxn]of longint;
who:array[..maxn,..]of longint;
trie:array[..maxn,'A'..'Z']of longint;
n,tot,total,peo,u,i,j,k,ii,t:longint;
s:string;
ch:char; procedure lt(var t:longint);
var
k:longint;
begin
k:=right[t];
right[t]:=left[k];
left[k]:=t;
size[k]:=size[t];
size[t]:=size[left[t]]+size[right[t]]+;
t:=k;
end; procedure rt(var t:longint);
var
k:longint;
begin
k:=left[t];
left[t]:=right[k];
right[k]:=t;
size[k]:=size[t];
size[t]:=size[left[t]]+size[right[t]]+;
t:=k;
end; procedure insert(var t:longint;y,z,l:longint);
begin
if t= then begin
inc(total);
t:=total;
value[t]:=y;
fix[t]:=random(mm);
time[t]:=z;
hash[t]:=l;
left[t]:=;
right[t]:=;
size[t]:=;
exit;
end;
inc(size[t]);
if y<=value[t] then begin
insert(right[t],y,z,l);
if fix[right[t]]<fix[t] then lt(t);
end
else begin
insert(left[t],y,z,l);
if fix[left[t]]<fix[t] then rt(t);
end;
end; procedure delete(var t:longint;y,z:longint);
begin
if t= then exit;
dec(size[t]);
if (value[t]=y) and (time[t]=z) then begin
if left[t]= then t:=right[t]
else
if right[t]= then t:=left[t]
else
if fix[right[t]]<fix[left[t]] then begin
lt(t);
delete(left[t],y,z);
end
else begin
rt(t);
delete(right[t],y,z);
end;
exit;
end;
if (y>value[t]) or (y=value[t]) and (z<time[t])
then delete(left[t],y,z)
else delete(right[t],y,z);
end; function rank(t,y,z:longint):longint;
begin
if t= then exit();
if (y=value[t]) and (z=time[t]) then exit(size[left[t]]+);
if (y>value[t]) or (y=value[t]) and (z<time[t]) then exit(rank(left[t],y,z));
exit(size[left[t]]++rank(right[t],y,z));
end; procedure outs(x:longint);
var
i:longint;
begin
for i:= to who[x][] do
write(chr(who[x][i]));
end; procedure find(t,x:longint;var y:longint);
begin
if (t=) or (y=) then exit;
if x<=size[left[t]] then begin
find(left[t],x,y);
if y> then begin
dec(y);
if y= then begin
outs(hash[t]);
writeln;
exit;
end;
outs(hash[t]);
write(' ');
find(right[t],,y);
end;
end
else begin
if x=size[left[t]]+ then begin
dec(y);
if y= then begin
outs(hash[t]);
writeln;
exit;
end;
outs(hash[t]);
write(' ');
inc(x);
end;
find(right[t],x-size[left[t]]-,y);
end;
end; begin
readln(n);
randomize;
peo:=;
total:=;
tot:=;
for ii:= to n do begin
read(ch);
if ch='+' then begin
u:=;
s:='';
read(ch);
repeat
s:=s+ch;
if trie[u][ch]= then begin
inc(tot);
trie[u][ch]:=tot;
end;
u:=trie[u][ch];
read(ch);
until ch=' ';
readln(j);
if num[u]= then begin
inc(peo);
num[u]:=peo;
cost[peo]:=j;
shi[peo]:=ii;
who[peo][]:=length(s);
for i:= to who[peo][] do who[peo][i]:=ord(s[i]);
insert(t,j,ii,peo);
end
else begin
delete(t,cost[num[u]],shi[num[u]]);
cost[num[u]]:=j;
shi[num[u]]:=ii;
insert(t,j,ii,num[u]);
end;
end
else
if ch='?' then begin
readln(s);
if (ord(s[])>=) and (ord(s[])<=) then begin
u:=;
for i:= to length(s) do u:=trie[u][s[i]];
writeln(rank(t,cost[num[u]],shi[num[u]]));
end
else begin
val(s,i);
j:=;
if i+j>peo then j:=peo-i+;
find(t,i,j);
end;
end;
end;
end.

bzoj 1862: [Zjoi2006]GameZ游戏排名系统 & bzoj 1056: [HAOI2008]排名系统的更多相关文章

  1. BZOJ 1862: [Zjoi2006]GameZ游戏排名系统 [treap hash]

    1862: [Zjoi2006]GameZ游戏排名系统 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1318  Solved: 498[Submit][ ...

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

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

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

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

  4. 1056/1862. [ZJOI2006]GameZ游戏排名系统【平衡树-splay】

    Description GameZ为他们最新推出的游戏开通了一个网站.世界各地的玩家都可以将自己的游戏得分上传到网站上.这样就可以看到自己在世界上的排名.得分越高,排名就越靠前.当两个玩家的名次相同时 ...

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

    hash 加上 平衡树(名次树). 这道题麻烦的地方就在于输入的是一个名字,所以需要hash. 这个hash用的是向后探查避免冲突,如果用类似前向星的方式避免冲突,比较难写,容易挂掉,但也速度快些. ...

  6. bzoj1056/1862 [Zjoi2006]GameZ游戏排名系统

    题目链接:1,2 treap恶心题,不多说 #include<algorithm> #include<iostream> #include<cstdlib> #in ...

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

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

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

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

  9. [洛谷P2584][ZJOI2006]GameZ游戏排名系统

    题目大意:同[洛谷P4291][HAOI2008]排名系统(双倍经验) 题解:略 卡点:无 C++ Code: #include <cstdio> #include <map> ...

随机推荐

  1. Git学习系列 (二)

    #克隆目录并重命名为newname,默认目录名是使用.git前的grit git clone git://github.com/schacon/grit.git newname #将所有已经跟踪过的文 ...

  2. CakePHP Model中( 获取Session)使用Component的方法

    有时候我们需要在Model中使用Session,大家知道CakePHP把操作Session的方法封装为了一个Component, 在Model中正常读取Session的方法: 在 "app_ ...

  3. cc2541测试SimpleBLEPeripheral例程

    1. 修改工程选项,去掉CC2540_MINIDK,烧写CC2541代码 2. 打开手机软件TruthBlue2_7 3. 准备看下特征值4的通信,在周期处理里面,一直读取特征值3的值,然后由特征值4 ...

  4. MySQL高级-慢查询日志

    一.慢查询日志是什么 1. 2. 3. 2.开启了慢查询日志后,什么样的SQL才会记录到慢查询日志里面呢? 3.案例 1.查看当前多少秒算慢 2.设置慢的阙值时间 3.为什么设置后看不出变化? 4.记 ...

  5. gitlab改root密码

    1. ~$ sudo gitlab-rails console production 2.查询要改的用户 irb(main)::> u = User.where().first => #& ...

  6. js 去掉下划线,后首个字母变大写

    1.驼峰转连字符: var s = "fooStyleCss";  s = s.replace(/([A-Z])/g,"-$1").toLowerCase(); ...

  7. django1.11+xadmin的搭建

    1.git clone https://github.com/sshwsfc/xadmin.git或者直接下载zip包 2..在项目根目录下建一个extra_apps的包,将xadmin源码包存放在里 ...

  8. cf#512 C. Vasya and Golden Ticket

    题目链接 http://codeforces.com/contest/1058/problem/C 这题还是暴力最方便,和的情况最多有n*a[i]  900种把每种都试一遍 #include<b ...

  9. 小球下落 (Dropping Balls,UVA 679)

    题目描述: 题目思路: 1.直接用数组模拟二叉树下落过程 //超时 #include <iostream> #include <cstring> using namespace ...

  10. 【shell 练习4】编写Shell用户管理脚本(二)

    一.创建.删除.查看用户,随机生成八位数密码 #!/bin/bash #Author:yanglt #!/bin/bash #Author:yanglt #Blog:https://www.cnblo ...