题目链接:1,2

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游戏排名系统的更多相关文章

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

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

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

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

  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. bzoj 1056 [HAOI2008]排名系统(1862 [Zjoi2006]GameZ游戏排名系统)

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

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

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

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

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

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

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

  8. bzoj1862: [Zjoi2006]GameZ游戏排名系统

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

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

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

随机推荐

  1. vue之cli脚手架项目中组件的使用

    在webpack-simple模板中,包括webpck模板.一个.vue文件就是一个组件. 为什么会这样呢?因为webpack干活了!webpack的将我们所有的资源文件进行打包.同时webpack还 ...

  2. 9.20 session

    2018-9-20 13:14:40 Cookie session 参考 :http://www.cnblogs.com/liwenzhou/p/8343243.html 类视图  cbv 注册 ur ...

  3. R中使用rvest爬取数据小试

    总结R中使用 xpath 和 css selectors 获取标签内容(xpath功能强大,而CSS选择器通常语法比较简洁,运行速度更快些) 例:抓取下面标签的内容: <h3 class=&qu ...

  4. Python:闭包

    闭包(Closure) 在一个函数内部定义另一个函数,然后内部函数用到外部函数的变量,把内部函数以及用到的外部变量,合称闭包. 首先复习一下 命名空间与作用域 我们可以把命名空间看做一个大型的字典类型 ...

  5. 四种数据库随机获取N条数据的方法

    1.SQL Server: SELECT TOP  n  *  FROM  tableName ORDER BY NEWID(); 2.ORACLE: SELECT * FROM (SELECT * ...

  6. 2018/03/19 每日一个Linux命令 之 touch

    touch 英文翻译为 触碰 很形象 touch [文件] 就像我就碰你一下,什么都不干..... 如果没有这个文件则我就新建这个文件 会修改这个文件的最后修改时间 没有的话则会产生一个0字节大小的空 ...

  7. thinkphp 如何查询数据库

    在控制器中使用M(); 数据表: 一.查询方式 1.字符串作为条件 2.使用索引数组作为条件查询条件 //可以更改逻辑关系 $condition['_logic'] = 'OR'; 二.表达式查询 三 ...

  8. 【HTML5】HTML5的自学路线

    HTML5的开发市场已越来越火爆,他已经与我们的生活息息相关,它也成为了我们生活中的一部分,比如我们在网上购物,玩手游等等,都存在html5的影子,也正是因为html5的高度影响力,吸引了许多人开始关 ...

  9. 【Python虫师】多窗口定位

    <注意>iframe框架 iframe也称作嵌入式框架,嵌入式框架和框架网页类似,它可以把一个网页的框架和内容嵌入在现有的网页中. 框架(framework)是一个基本概念上的结构,用于去 ...

  10. python-面向对象-10-单例

    单例 目标 单例设计模式 __new__ 方法 Python 中的单例 01. 单例设计模式 设计模式 设计模式 是 前人工作的总结和提炼,通常,被人们广泛流传的设计模式都是针对 某一特定问题 的成熟 ...