BZOJ4415: [Shoi2013]发牌
显然可以线段树或树状数组上二分。
然而直接写splay在bzoj上并不会T。
然而发这题的目的只是因为我又忘了return了啊啊啊啊(TдT)
内心十分崩溃。关键是在本地还能过。
#include<cstdio>
#include<algorithm>
#define L(t) t->c[0]
#define R(t) t->c[1]
#define Z(t) (L(t)->s+1)
#define N 700005
#define M (s+t>>1)
using std::swap;
struct node{
int v,s;
node *c[2];
}e[N],*back=e+1,
*null=e,*root;
node* update(node* t){
t->s=R(t)->s+Z(t);
return t;
}
void link(bool i,
node*& t,node*& s){
node* d=t->c[i];
t->c[i]=s;
s=update(t),t=d;
}
node* splay(int v,
node*& t=root){
node* d[]={null,null};
while(v!=Z(t)){
bool i=v>Z(t);
v-=i*Z(t);
if(v!=Z(t->c[i])
&&i==v>Z(t->c[i])){
v-=i*Z(t->c[i]);
link(i,t,
t->c[i]->c[i^1]);
}
link(i,t,d[i]);
}
for(int i=0;i!=2;++i){
node* s=t->c[i^1];
while(d[i]!=null)
link(i,d[i],s);
t->c[i^1]=s;
}
return update(t);
}
node* build(int s,int t){
if(s<=t){
node* a=back++;
a->v=M;
L(a)=build(s,M-1);
R(a)=build(M+1,t);
return update(a);
}
return null;
}
node*& splay(int s,int t){
splay(s);
return L(splay(
t-s+2,R(root)));
}
struct io_t{
char p[1<<25],*s;
char e[1<<25],*t;
int a[24];
io_t():s(p),t(e){
fread(s,1,
sizeof p,stdin);
}
~io_t(){
fwrite(e,1,
t-e-1,stdout);
}
operator int(){
static int v;
v=0;
while(*s<48)
++s;
do
v=v*10+*s++-48;
while(*s>32);
return v;
}
void print(int v){
static int* q=a;
if(!v)*t++=48;
else{
if(v<0)
*t++=45,
v*=-1;
while(v)
*q++=v%10+48,
v/=10;
while(q!=a)
*t++=*--q;
}
*t++=10;
}
}ip;
int n=ip,s=1;
int main(){
root=build(0,n+1);
for(;n;--n){
s=(s+ip-1)%n+1;
ip.print(
splay(s,s)->v);
L(R(root))=null;
}
}
BZOJ4415: [Shoi2013]发牌的更多相关文章
- BZOJ4415: [Shoi2013]发牌 树状数组+二分
Description 假设一开始,荷官拿出了一副新牌,这副牌有N张不同的牌,编号依次为1到N.由于是新牌,所以牌是按照顺序排好的,从牌库顶开始,依次为1, 2,……直到N,N号牌在牌库底.为了发完所 ...
- BZOJ4415:[SHOI2013]发牌(线段树)
Description 假设一开始,荷官拿出了一副新牌,这副牌有N张不同的牌,编号依次为1到N.由于是新牌,所以牌是按照顺序排好的,从牌库顶开始,依次为1, 2,……直到N,N号牌在牌库底.为了发完所 ...
- BZOJ4415 SHOI2013发牌(线段树)
似乎是noip2017d2t3的一个部分分.用splay的话当然非常裸,但说不定会被卡常.可以发现序列中数的(环上)相对位置是不变的,考虑造一棵权值线段树维护权值区间内还有多少个数留在序列中,每次在线 ...
- bzoj 4415: [Shoi2013]发牌
4415: [Shoi2013]发牌 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 173 Solved: 124[Submit][Status][ ...
- [SHOI2013]发牌 解题报告
[SHOI2013]发牌 题意 对一个\(1\sim n(n\le 7\times 10^5)\)的环,指标最开始在\(1\),每次删去顺时针往后第\(d_i\)个元素,指标移到下一个位置.要求输出每 ...
- P3988 [SHOI2013]发牌
题目 P3988 [SHOI2013]发牌 做法 我们切牌时的状态: 手玩几次后我们发现切\(K\)次牌就是求堆顶一下的\(K+1\)大值,套上主席树就好了 My complete code #inc ...
- BZOJ 4415 洛谷 3988 [Shoi2013]发牌
[题解] 权值线段树.查询当前牌堆顶的牌并且删掉就好了. #include<cstdio> #include<algorithm> #define N 3000010 #def ...
- [暑假的bzoj刷水记录]
(这篇我就不信有网站来扣) 这个暑假打算刷刷题啥的 但是写博客好累啊 堆一起算了 隔一段更新一下. 7月27号之前刷的的就不写了 , 写的累 代码不贴了,可以找我要啊.. 2017.8.27upd ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
随机推荐
- Centos下编译JDK
因为OpenJDK是开源的,这里使用openJDK进行编译联系 环境要求 Centos6.7 64位 openjdk-7u40-fcs-src-b43-26_aug_2013.zip bootstra ...
- MVC————扩展方法MvcHtmlString
使用前: public static class MyHtmlHelper { public static string GroupPage(this HtmlHelper helper) { str ...
- android开发------编写用户界面之相对布局
今天要说的是RelativeLayout.RelativeLayout相对于LinearLayout的主要不同点在于它需要一个参照物. 我们先来看一下官方对这个布局的解释: RelativeLayou ...
- 类似掌盟的Tab页 Android 开源框架ViewPageIndicator 和 ViewPager 仿网易新闻客户端Tab标签 (转)
原博客地址 :http://blog.csdn.net/xiaanming/article/details/10766053 本文转载,记录学习用,如有需要,请到原作者网站查看(上面这个网址) 之前 ...
- Shell脚本_判断根分区使用率
vim gen_fen_qu_shi_yong_lv.sh chmod 755 gen_fen_qu_shi_yong_lv.sh 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ...
- 【BZOJ 1051】【HAOI 2006】受欢迎的牛
tarjan缩点模板 #include<cstdio> #include<cstring> #include<algorithm> using namespace ...
- IOS APP开发中View的几种实现方式
xib文件有以下几个重要的属性: xib文件名 File’s Owner xib文件中的视图的Class xib文件中的视图的Outlet指向 File’s Owner 可以关联到某类,然后通过IBO ...
- 平行四边形面积 light 1305
double 不一定是与x y轴平平行 所以要正弦定理和余弦定理 似乎一定要printf输出 错了好几次 #include<iostream> #include<math.h> ...
- poj3694 缩点边双连通分量
Network Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 8669 Accepted: 3175 Descripti ...
- JSP导入EXCEL样式
http://demo.gcpowertools.com.cn/spreadjs/exceliosample/exceliosample/ Java实现导入Excel: 1.做一个jsp页面,页面包括 ...