[BZOJ 1056][HAOI2008]排名系统
\(\color{green}{solution}\)
\(fhq \_treap\)模板题.
对于 \(+\) 操作,如果当前人不存在,那么直接加入;如果存在,那么先将他删除,再加入.复杂度\(O(n \log n)\)
对于 \(?\) 操作,如果问人,直接查找名次;如果问名次,先将它前面的\(split\)出去,再把它后面\(10\)个\(split\)
出去,然后输出即可.复杂度均为\(O(n \log n)\).
所以总复杂度是\(O(n \log n)\) 的.具体细节请参见代码.
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define mp make_pair
const int maxn = 250010;
bool operator < (const pii &a, const pii &b) {
return a.first == b.first ? a.second < b.second : a.first > b.first;
}
struct node {node *ls, *rs; pii a; int sz, ky, id;};
node *root, pool[maxn], *pis = pool, *nul, *Bc[maxn];
int bc_top;
inline void init() {
nul = pis; nul->ls = nul->rs = nul; nul->sz = 0; root = nul;
}
node *newnode(int val, int tim, int opt) {
node *k = bc_top ? Bc[bc_top --] : ++ pis;
k->ls = k->rs = nul; k->sz = 1; k->ky = rand(); k->id = opt;
k->a = mp(val, tim); return k;
}
inline void up(node *&x) { x->sz = x->ls->sz + x->rs->sz + 1;}
inline void mrg(node *&c, node *x, node *y) {
if( x == nul || y == nul) {c = x == nul ? y : x; return;}
if( x->ky < y->ky) c = x, mrg(c->rs, x->rs, y);
else c = y, mrg(c->ls, x, y->ls); up(c);
}
inline void spl(node *c, node *&x, node *&y, int ret) {
if( c == nul) { x = y = nul; return;}
if( c->ls->sz+1 <= ret) x = c, spl(c->rs, x->rs, y, ret-c->ls->sz-1);
else y = c, spl(c->ls, x, y->ls, ret); up(c);
}
int find(node *c, pii x) {
if( c->a == x) return c->ls->sz + 1;
if( c->a < x) return c->ls->sz + 1 + find(c->rs, x);
return find(c->ls, x);
}
inline void erase(pii val) {
int rk = find(root, val);
node *x, *y, *z; spl(root, x, y, rk); spl(x, x, z, rk-1);
mrg(root, x, y); Bc[++ bc_top] = z;
}
inline void sp_spl(node *c, node *&x, node *&y, int ret) {
if( c == nul) { x = y = nul; return;}
if( c->a.first >= ret) x = c, sp_spl(c->rs, x->rs, y, ret);
else y = c, sp_spl(c->ls, x, y->ls, ret); up(c);
}
pii Rank[maxn];
int Idc;
inline void insert(int val, int tim, int &id) {
if( id) erase(Rank[id]); else id = ++ Idc;
node *x, *y; Rank[id] = mp(val, tim);
sp_spl(root, x, y, val);
mrg(x, x, newnode(val, tim, id)); mrg(root, x, y);
}
map<string, int> Id;
char buf[maxn][20], ss[20], *tt;
int getnum(char *s) {
int x = 0; for ( ; !isdigit(*s); ++ s);
for ( ; isdigit(*s); ++ s) x = (x << 1) + (x << 3) + (*s & 15);
return x;
}
inline void out(node *x) {
if(x == nul) return; out(x->ls); printf("%s ", buf[x->id]); out(x->rs);
}
int n;
inline void sol1(int rk) {
node *x, *y, *z;
spl(root, x, y, rk-1); spl(y, z, y, 10);
out(z); puts("");
mrg(y, z, y); mrg(root, x, y);
}
int main() {
#ifndef ONLINE_JUDGE
// freopen("1.in","r",stdin);
#endif
init();
scanf("%d", &n);
for ( register int i = 1, x; i <= n; ++ i) {
scanf("%s", ss); tt = ss;
if( *ss == '+') {
++ tt; scanf("%d", &x); insert(x, i, Id[tt]);
int k = Id[tt];
if( k == Idc) memcpy(buf[k], tt, sizeof(buf[k]));
}
else {
++ tt;
if( isdigit(*tt)) sol1(getnum(tt));
else printf("%d\n", find(root, Rank[Id[tt]]));
}
}
return 0;
}

[BZOJ 1056][HAOI2008]排名系统的更多相关文章
- bzoj 1056 [HAOI2008]排名系统(1862 [Zjoi2006]GameZ游戏排名系统)
1056: [HAOI2008]排名系统 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1854 Solved: 502[Submit][Statu ...
- bzoj 1862: [Zjoi2006]GameZ游戏排名系统 & bzoj 1056: [HAOI2008]排名系统
傻叉了一晚上,把t打成x,然后这题神奇在于输出一段数,不足的不用输出,一开始我的是直接找没有后面就退,然后这样会格式错误囧……然后最后zj的还卡了下空间,于是不用string就过了……string毁一 ...
- 【BZOJ】1862: [Zjoi2006]GameZ游戏排名系统 & 1056: [HAOI2008]排名系统(treap+非常小心)
http://www.lydsy.com/JudgeOnline/problem.php?id=1862 http://www.lydsy.com/JudgeOnline/problem.php?id ...
- 1056: [HAOI2008]排名系统 - BZOJ
Description 排名系统通常要应付三种请求:上传一条新的得分记录.查询某个玩家的当前排名以及返回某个区段内的排名记录.当某个玩家上传自己最新的得分记录时,他原有的得分记录会被删除.为了减轻服务 ...
- bzoj 1862/1056 [HAOI2008]排名系统
原题链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1862 很恶心的 一道题,我也不晓得自己是第几次写这题了%>_<%. 写了两种方 ...
- [HAOI2008]排名系统& [Zjoi2006]GameZ游戏排名系统
1056: [HAOI2008]排名系统 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2487 Solved: 711[Submit][Statu ...
- 【BZOJ1056】[HAOI2008]排名系统(Splay)
[BZOJ1056][HAOI2008]排名系统(Splay) 题面 BZOJ 洛谷 题解 \(Splay\)随便维护一下就好了,至于名字什么的,我懒得手写哈希表了,直接哈希之后拿\(map\)压. ...
- 数据结构(Splay平衡树):HAOI2008 排名系统
[HAOI2008] 排名系统 [题目描述] 排名系统通常要应付三种请求:上传一条新的得分记录.查询某个玩家的当前排名以及返回某个区段内的排名记录.当某个玩家上传自己最新的得分记录时,他原有的得分记录 ...
- BZOJ_1862_[Zjoi2006]GameZ游戏排名系统&&BZOJ_1056_[HAOI2008]排名系统_Splay
BZOJ_1862_[Zjoi2006]GameZ游戏排名系统&&BZOJ_1056_[HAOI2008]排名系统_Splay Description 排名系统通常要应付三种请求:上传 ...
随机推荐
- UI设计可供性解析:巧用隐藏的设计力提升用户体验
以下内容由Mockplus团队翻译整理,仅供学习交流,Mockplus是更快更简单的原型设计工具. 在实际的Web或App界面设计中,设计师们在学习和实践各种专业知识和技能之外,也会不可避免的遇到到各 ...
- Socket发送文件
.Net.cs using System; using System.Collections.Generic; using System.IO; using System.Linq; using Sy ...
- Hello_Motion_Tracking 任务一:Project Tango采集运动追踪数据
我们来看一下中的几个基本的例子 (区域描述.深度感知.运动追踪.视频4个) 参考:Google Tango初学者教程 1. hello_motion_tracking package com.proj ...
- idea jvm 优化
修改对应配置文件 64位的是idea64.exe.vmoptions -Xms2048m -Xmx2048m -Xmn1024m -XX:PermSize=512m -XX:MaxPermSize=5 ...
- java并发编程实战:第十三章----显示锁
一.Lock与ReentrantLock Lock接口中定义了一种无条件.可轮询的.定时的以及可中断的锁获取操作,所有加锁和解锁的方法都是显式的. 1 public interfece Lock 2 ...
- 如何修改TFS 2013中工作项附件大小限制
默认情况下,TFS工作项的附件大小限制为4MB.我们可以通过调用TFS提供的Web Service将这个限制调整最高到2GB. 调整这个设置的必备条件是你需要拥有TFS应用层管理员的权限.下面来看看如 ...
- #测试框架推荐# test4j,数据库测试
# 背景 后端都是操作DB的,这块的自动化测试校验的话,是需要数据库操作的,当然可以直接封装方法来操作数据,那么有没有开源框架支持数据操作,让我们关注写sql语句?或者帮我们做mysql的断言呢? # ...
- 使用Toolbar + DrawerLayou实现菜单侧滑,改变toolbar左上角图标
侧边栏具体实现可以参照http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0303/2522.html getSupportActio ...
- openstack kolla 部署---不同的节点采用不同的物理接口
在 /etc/kolla/globals.yml 文件中删除 neutron_external_interface tunnel_interface api_interface storage_ ...
- “全栈2019”Java第九十五章:方法中可以定义静态局部内部类吗?
难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...