bzoj1056/1862 [Zjoi2006]GameZ游戏排名系统
treap恶心题,不多说
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define rre(i,r,l) for(int i=(r);i>=(l);i--)
#define re(i,l,r) for(int i=(l);i<=(r);i++)
#define Clear(a,b) memset(a,b,sizeof(a))
#define inout(x) printf("%d",(x))
#define douin(x) scanf("%lf",&x)
#define strin(x) scanf("%s",(x))
#define LLin(x) scanf("%lld",&x)
#define op operator
#define CSC main
typedef unsigned long long ULL;
typedef const int cint;
typedef long long LL;
using namespace std;
cint mod=;int n,root,sz,tot,head[mod+];
struct data1
{
int v,t,next;
char ch[];
}hash[];
struct data2
{
int l,r,v,s,rr,t;
char ch[];
}tp[];
void maintain(int k){tp[k].s=tp[tp[k].l].s+tp[tp[k].r].s+;}
void rotate2(int &k)
{
int t=tp[k].l;
tp[k].l=tp[t].r;
tp[t].r=k;tp[t].s=tp[k].s;
maintain(k);k=t;
}
void rotate1(int &k)
{
int t=tp[k].r;
tp[k].r=tp[t].l;
tp[t].l=k;
tp[t].s=tp[k].s;
maintain(k);k=t;
}
bool com(char *a,char *b)
{
for(int i=;i<(int)max(strlen(a),strlen(b));i++)
if(a[i]!=b[i])return ;
return ;
}
int HASH(char *ch)
{
int s=;
for(int i=;i<(int)strlen(ch);i++)
{
s*=;s+=(ch[i]-'A'+);
s%=mod;
}
return s;
}
void del(int &k,int x,int t)
{
if(tp[k].v==x)
{
if(tp[k].t==t)
{
if(tp[k].l*tp[k].r==)k=tp[k].l+tp[k].r;
else if(tp[tp[k].l].rr<tp[tp[k].r].rr){rotate2(k);del(k,x,t);}
else {rotate1(k);del(k,x,t);}
}
else if(t>tp[k].t){tp[k].s--;del(tp[k].l,x,t);}
else {tp[k].s--;del(tp[k].r,x,t);}
}
else if(x<tp[k].v){tp[k].s--;del(tp[k].l,x,t);}
else {tp[k].s--;del(tp[k].r,x,t);}
}
void add(int &k,char *ch,int x,int t)
{
if(k==)
{
sz++;k=sz;tp[k].v=x;tp[k].s=;tp[k].rr=rand();
memcpy(tp[k].ch,ch,strlen(ch));tp[k].t=t;
return;
}
tp[k].s++;
if(x<=tp[k].v){add(tp[k].l,ch,x,t);if(tp[tp[k].l].rr<tp[k].rr)rotate2(k);}
else{add(tp[k].r,ch,x,t);if(tp[tp[k].r].rr<tp[k].rr)rotate1(k);}
}
void add(char *ch,int x,int t)
{
int k=HASH(ch);int i=head[k];
while(i)
{
if(com(hash[i].ch,ch))
{
del(root,hash[i].v,hash[i].t);
hash[i].t=t;hash[i].v=x;
add(root,ch,x,t);
return;
}
i=hash[i].next;
}
tot++;
hash[tot].t=t;hash[tot].v=x;
memcpy(hash[tot].ch,ch,strlen(ch));
hash[tot].next=head[k];head[k]=tot;
add(root,ch,x,t);
}
int hh(char *ch)
{
int k=HASH(ch);int i=head[k];
while(i)
{
if(com(hash[i].ch,ch))return i;
i=hash[i].next;
}return ;
}
int findrank(int k,int x,int t)
{
if(k==)return ;
if(tp[k].v==x)
{
if(tp[k].t>t)return findrank(tp[k].r,x,t);
else if(tp[k].t<t)return +tp[tp[k].r].s+findrank(tp[k].l,x,t);
else return tp[tp[k].r].s+;
}
else if(tp[k].v<x)return findrank(tp[k].r,x,t);
else return +tp[tp[k].r].s+findrank(tp[k].l,x,t);
}
void query1(char *ch)
{
int t=hh(ch);
printf("%d\n",findrank(root,hash[t].v,hash[t].t));
}
int findwei(int k,int x)
{
if(tp[tp[k].r].s+==x)return k;
else if(x<=tp[tp[k].r].s)return findwei(tp[k].r,x);
else return findwei(tp[k].l,x-tp[tp[k].r].s-);
}
void query2(char *ch)
{
int s=;
for(int i=;i<(int)strlen(ch);i++){s*=;s+=ch[i]-'';}
for(int i=s;i<=tot&&i<=s+;i++)
{
printf("%s",tp[findwei(root,i)].ch+);
if(i<tot&&i<s+)printf(" ");
}
printf("\n");
}
int CSC()
{
scanf("%d",&n);char ch[];int x;
for(int i=;i<=n;i++)
{
scanf("%s",ch);
if(ch[]=='+'){scanf("%d",&x);add(ch,x,i);}
else if(ch[]>='A'&&ch[]<='Z')query1(ch);
else query2(ch);
}
return ;
}
bzoj1056/1862 [Zjoi2006]GameZ游戏排名系统的更多相关文章
- BZOJ 1862: [Zjoi2006]GameZ游戏排名系统 [treap hash]
1862: [Zjoi2006]GameZ游戏排名系统 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1318 Solved: 498[Submit][ ...
- 1056/1862. [ZJOI2006]GameZ游戏排名系统【平衡树-splay】
Description GameZ为他们最新推出的游戏开通了一个网站.世界各地的玩家都可以将自己的游戏得分上传到网站上.这样就可以看到自己在世界上的排名.得分越高,排名就越靠前.当两个玩家的名次相同时 ...
- 【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 ...
- bzoj1056: [HAOI2008]排名系统 && 1862: [Zjoi2006]GameZ游戏排名系统
hash 加上 平衡树(名次树). 这道题麻烦的地方就在于输入的是一个名字,所以需要hash. 这个hash用的是向后探查避免冲突,如果用类似前向星的方式避免冲突,比较难写,容易挂掉,但也速度快些. ...
- bzoj 1862: [Zjoi2006]GameZ游戏排名系统 & bzoj 1056: [HAOI2008]排名系统
傻叉了一晚上,把t打成x,然后这题神奇在于输出一段数,不足的不用输出,一开始我的是直接找没有后面就退,然后这样会格式错误囧……然后最后zj的还卡了下空间,于是不用string就过了……string毁一 ...
- BZOJ_1862_[Zjoi2006]GameZ游戏排名系统&&BZOJ_1056_[HAOI2008]排名系统_Splay
BZOJ_1862_[Zjoi2006]GameZ游戏排名系统&&BZOJ_1056_[HAOI2008]排名系统_Splay Description 排名系统通常要应付三种请求:上传 ...
- bzoj1862: [Zjoi2006]GameZ游戏排名系统
Description GameZ为他们最新推出的游戏开通了一个网站.世界各地的玩家都可以将自己的游戏得分上传到网站上.这样就可以看到自己在世界上的排名.得分越高,排名就越靠前.当两个玩家的名次相同时 ...
- [ZJOI2006]GameZ游戏排名系统
Description GameZ为他们最新推出的游戏开通了一个网站.世界各地的玩家都可以将自己的游戏得分上传到网站上.这样就可以看到自己在世界上的排名.得分越高,排名就越靠前.当两个玩家的名次相同时 ...
随机推荐
- python中列表排序,字典排序,列表中的字典排序
#-*- encoding=utf-8 -*- # python3代码 import operator 一. 按字典值排序(默认为升序) x = {1:2, 3:4, 4:3, 2:1, 0:0} 1 ...
- Rsync数据同步应用指南
1.软件简介 Rsync 是一个本地或远程数据同步工具,基于RSync算法,这个算法是澳大利亚人Andrew Tridgell发明的:可通过 LAN/WAN 快速同步多台主机间的文件.Rsync 本来 ...
- SPOJ Distinct Substrings【后缀数组】
Given a string, we need to find the total number of its distinct substrings. Input T- number of test ...
- poj3728The merchant 【倍增】【LCA】
There are N cities in a country, and there is one and only one simple path between each pair of citi ...
- TACOTRON:端到端的语音合成
tacotron主要是将文本转化为语音,采用的结构为基于encoder-decoder的Seq2Seq的结构.其中还引入了注意机制(attention mechanism).在对模型的结构进行介绍之前 ...
- Percona Data Recovery Tool 单表恢复
前几天写过update或者delete忘加where条件的数据恢复.今天介绍一款开源的MySQL数据库InnoDB数据恢复工具:innodb-tools,它通过从原始数据文件中提取表的行记录,实现从丢 ...
- Java多线程面试、笔试方向---后续补充
1.ThreadLocal类 线程级别的局部变量,为每个使用该变量的线程提供一个独立的变量副本,每个线程修改副本时不影响其他线程对象的副本. ThreadLocal实例通常作为静态私有字段出 ...
- 001-pro ant design 升级2.0后变更
一.更新点 1.目录调整 2.本地代理服务器调整 roadhog→umi 配置方式 在这个config/config.js配置 "proxy": { "/api" ...
- PHPExcel使用-使用PHPExcel导出文件-导出MySQL数据
现在数据库里面有一组数据,我们将它按照不同的难度进行分sheet. 首先我们需要写一个mysql的配置文件- db.config.php(utf-8编码) : <?php $dbconfig= ...
- vue-router中参数传递 && 编程式导航 && 坑 && beforeRouteEnter
第一部分: vue-router参数传递 通过router-link我们可以向路由到的组件传递参数,这在我们实际使用中时非常重要的. 路由: { path:"/DetailPage" ...