并不对劲的bzoj1861: [Zjoi2006]Book 书架
传送门->
这题的正确做法是splay维护这摞书。
但是并不对劲的人选择了暴力(皮这一下很开心)。
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#define rep(i,x,y) for(register int i=(x);i<=(y);++i)
#define dwn(i,x,y) for(register int i=(x);i>=(y);--i)
#define re register
#define maxn 300010
using namespace std;
inline int read()
{
int x=0,f=1;
char ch=getchar();
while(isdigit(ch)==0 && ch!='-')ch=getchar();
if(ch=='-')f=-1,ch=getchar();
while(isdigit(ch))x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
return x*f;
}
inline void write(int x)
{
int f=0;char ch[20];
if(!x){puts("0");return;}
if(x<0){putchar('-');x=-x;}
while(x)ch[++f]=x%10+'0',x/=10;
while(f)putchar(ch[f--]);
putchar('\n');
}
int a[maxn],tr[maxn],pos[maxn],n,m,qx,qy,hd,tl;
char s[20];
int lt(int x){return x&(-x);}
void add(int x,int k){for(;x<=n+m*2;x+=lt(x))tr[x]+=k;}
int ask(int x){int k=0;for(;x;x-=lt(x))k+=tr[x];return k;}
int kth(int k)
{
int l=hd,r=tl,ans=tl+233;
while(l<=r)
{
int mi=(r+l)>>1;
int rank=ask(mi);
if(rank==k)ans=min(ans,mi);
if(rank>=k)r=mi-1;
else l=mi+1;
}
return ans;
}
int main()
{
n=read(),m=read();hd=1+m,tl=n+m;
rep(i,1,n)a[i+m]=read(),pos[a[i+m]]=i+m,add(i+m,1);
rep(k,1,m)
{
scanf("%s",s);qx=read();
if(s[0]=='T')add(pos[qx],-1),hd--,add(hd,1),swap(a[hd],a[pos[qx]]),pos[qx]=hd;
if(s[0]=='B')add(pos[qx],-1),tl++,add(tl,1),swap(a[tl],a[pos[qx]]),pos[qx]=tl;
if(s[0]=='I')
{
qy=read();if(!qy)continue;
int tmp=ask(pos[qx])+qy;
// cout<<"rank:"<<tmp<<endl;
int ans=kth(tmp);
// cout<<"ans&pos:"<<qx<<" "<<a[ans]<<pos[qx]<<" ";
int px=pos[qx];
swap(pos[qx],pos[a[ans]]);swap(a[px],a[ans]);// cout<<pos[qx]<<endl;
}
if(s[0]=='A')write(ask(pos[qx])-1);
if(s[0]=='Q')
{
int ans=kth(qx);
write(a[ans]);
}
//cout<<"a:"<<endl;
//rep(i,1,n+m*2)cout<<a[i]<<" ";cout<<endl;
//cout<<"pos:"<<endl;
//rep(i,1,n)cout<<pos[i]<<" ";cout<<endl;
}
return 0;
}
/*
10 10
1 3 2 7 5 8 10 4 9 6
Query 3
Top 5
Ask 6
Bottom 3
Ask 3
Top 6
Insert 4 -1
Query 5
Query 2
Ask 2
*/
据说照顾了splay的大肠腧的数据为暴力提供了漏洞。

并不对劲的bzoj1861: [Zjoi2006]Book 书架的更多相关文章
- [BZOJ1861][Zjoi2006]Book 书架
[BZOJ1861][Zjoi2006]Book 书架 试题描述 小T有一个很大的书柜.这个书柜的构造有些独特,即书柜里的书是从上至下堆放成一列.她用1到n的正整数给每本书都编了号. 小T在看书的时候 ...
- [bzoj1861][Zjoi2006]Book 书架_非旋转Treap
Book 书架 bzoj-1861 Zjoi-2006 题目大意:给你一个序列,支持:将指定编号的元素抽出,放到序列顶(底):将指定编号元素左右篡位:查询指定编号元素位置:查询指定数量位置元素编号. ...
- fhq_treap || BZOJ1861: [Zjoi2006]Book 书架 || Luogu P2596 [ZJOI2006]书架
题面:P2596 [ZJOI2006]书架 题解:记录每本书对应的节点编号 普通fhq_treap无法查询一个权值的排名,所以在普通fhq_treap上多记录每个节点的父亲(可加在pushup函数中) ...
- BZOJ1861[ZJOI2006]Book书架
Description 小T有一个很大的书柜.这个书柜的构造有些独特,即书柜里的书是从上至下堆放成一列.她用1到n的正整数给每本书都编了号. 小T在看书的时候,每次取出一本书,看完后放回书柜然后再拿下 ...
- 【平衡树】【pb_ds】 bzoj1861 [Zjoi2006]Book 书架
需要用数组记录编号为i的书的位置,和位置i处的书的编号. Code: #include<cstdio> #include<ext/pb_ds/assoc_container.hpp& ...
- 【权值分块】bzoj1861 [Zjoi2006]Book 书架
权值分块……rank3……没什么好说的. #include<cstdio> #include<cmath> #include<algorithm> using na ...
- bzoj1861 [Zjoi2006]Book 书架 splay
小T有一个很大的书柜.这个书柜的构造有些独特,即书柜里的书是从上至下堆放成一列.她用1到n的正整数给每本书都编了号. 小T在看书的时候,每次取出一本书,看完后放回书柜然后再拿下一本.由于这些书太有吸引 ...
- bzoj1861 [Zjoi2006]Book 书架——splay
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1861 发现自己想splay的时候总是纠结那个点权是什么,因为splay原本是二分查找树... ...
- BZOJ 1861: [Zjoi2006]Book 书架
1861: [Zjoi2006]Book 书架 Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 1290 Solved: 740[Submit][Stat ...
随机推荐
- HA架构
HA架构是个什么东西? 阅读文章:浅谈web应用的负载均衡.集群.高可用(HA)解决方案
- SQL2012通用分页存储过程
--提取分页数据,返回总记录数 Createprocedure [dbo].[sp_Common_GetDataPaging_ReturnDataCount] ( @SqlString varchar ...
- 线段上的格点 辗转相除法(GCD)
/*问题描述:线段上的格点给定平面上的两个格点 P1 = (x1, y1) ; P2 = (x2, y2) 线段P1 P2上,除P1 和 P2以外一共有几个格点*//*分析过程在格点上画P1(0,5) ...
- Python基础教程笔记——第4章:字典
字典 字典是Python唯一内建的数学映射类型,字典中的值没有特殊的顺序,键可以是数字,字符串,甚至是元组 字典的创建: 字典由键值对构成,字典中键是唯一的,而值不唯一.>>> a_ ...
- Unique Paths II (dp题)
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- Codeforces Round Edu 36
A.B.C 略 D(dfs+强连通分量) 题意: 给出一个n(n<=500)点m(m<=100000)边的有向图,问能否通过删去一条边使得该图无环. 分析: 最简单的想法就是枚举一条边删去 ...
- vm 安装CentOS7
1.首先需要到CentOS官网下载CentOS7的iso镜像文件,地址http://mirrors.cn99.com/centos/7/isos/x86_64/ 这里我选择的是迅雷种子文件 2.下载完 ...
- Dom对象的经常用法
Dom对象的经常用法: (1)getElementById() 查询给定ID属性值的元素,返回该元素的元素节点 1. 查询给定ID属性值的元素,返回该元素的元素节点.也称为元素对象. ...
- startActivity启动过程分析(转)
基于Android 6.0的源码剖析, 分析android Activity启动流程,相关源码: frameworks/base/services/core/java/com/android/serv ...
- oracle获取字符串长度函数length()和lengthb()
oracle获取字符串长度函数length()和lengthb() lengthb(string)计算string所占的字节长度:返回字符串的长度,单位是字节 length(string)计算st ...