Chino的数列

题解:

一道练代码能力的题目。。

首先很显然他是一道平衡树裸题

第5个操作是势能分析维护最大值最小值就可以了

另外设置虚点和noip2017队列那题一样(不过我只写过线段树)

具体细节:

1.内存池,要直接判断(!x) 因为可能进去就是0

2.输出的时候有重复的要都输出

3.search的时候要down

4.为了简单我写的down是更新自己的,而这个标记会对updata产生影响,所以updata的时候要down两个儿子

5.splay虚点变变三个点要判断点数,分三种情况 1个点,2个点,>2个点

这个洛谷评测是什么鬼。。数据测出来是对的显示wa

另外本题也可以用分块做。。以后写下试试

代码:

 

#include <bits/stdc++.h>
using namespace std;
#define rint register int
#define IL inline
#define rep(i,h,t) for (rint i=h;i<=t;i++)
#define dep(i,t,h) for (rint i=t;i>=h;i--) 
#define me(x) memset(x,0,sizeof(x))
#define ll long long
const int INF=1e9;
const int N=4e6;
queue<int> q;
int s[N],count2[N],count3[N],data[N],maxa[N],mina[N],rs[N],ls[N],lazy[N],fa[N],root; 
#define max(a,b) (a)>(b)?(a):(b)
#define min(a,b) (a)<(b)?(a):(b)
int cnt,minxx=INF;
struct phs{IL void down(rint x){if (lazy[x]==INF) return;maxa[x]=mina[x]=data[x]=lazy[x];if (ls[x]) lazy[ls[x]]=lazy[x];if (rs[x]) lazy[rs[x]]=lazy[x];lazy[x]=INF;}IL void updata(rint x){rint l=ls[x],r=rs[x],tmp=data[x];down(l); down(r);count2[x]=count2[l]+count2[r]+count3[x];maxa[x]=max(tmp,max(maxa[l],maxa[r]));mina[x]=min(tmp,min(mina[l],mina[r]));}IL void rotate(int x,int y){int fa1=fa[x];if (y==1){if (ls[x]) fa[ls[x]]=fa1;rs[fa1]=ls[x];} else{if (rs[x]) fa[rs[x]]=fa1;ls[fa1]=rs[x];}fa[x]=fa[fa1];if(fa[fa1]){if (ls[fa[fa1]]==fa1) ls[fa[fa1]]=x;else rs[fa[fa1]]=x;}fa[fa1]=x;if (y==1) ls[x]=fa1; else rs[x]=fa1;updata(fa1); updata(x);}void dfs(int x){if (fa[x]) dfs(fa[x]);down(x);}IL void splay(int x,int goal){dfs(x);int fa1=fa[x];while (fa1!=goal){if (fa[fa1]==goal){if (x==ls[fa1]) rotate(x,2); else rotate(x,1);} elseif (fa1==ls[fa[fa1]])if (x==ls[fa1])rotate(fa1,2),rotate(x,2);else rotate(x,1),rotate(x,2);else if (x==rs[fa1])rotate(fa1,1),rotate(x,1);else rotate(x,2),rotate(x,1);fa1=fa[x];}if (goal==0) root=x;}IL int search(rint k){rint x=root;while (x){down(x); if (s[x]){rint l=ls[x],r=rs[x];rint tmp=count3[x];count3[x]=1;rint now=ls[x]=q.front(); q.pop();fa[now]=x;if ((count3[ls[x]]=tmp/2)!=1) s[now]=1;ls[now]=l; fa[l]=now; data[now]=data[x]; updata(now); if (tmp>2){now=rs[x]=q.front(); q.pop(); data[rs[x]]=data[x];fa[now]=x;if ((count3[now]=tmp-(tmp/2)-1)!=1) s[now]=1;rs[now]=r; fa[r]=now; updata(now);}down(x);s[x]=0;}if (count2[ls[x]]+1==k) return(x);if (count2[ls[x]]+1<k) k-=count2[ls[x]]+1,x=rs[x];else x=ls[x];}}void dfs2(int x){if (!x) return;cnt++;q.push(x);dfs2(ls[x]);dfs2(rs[x]);ls[x]=rs[x]=count2[x]=s[x]=data[x]=fa[x]=maxa[x]=mina[x]=0;count3[x]=1;lazy[x]=INF; }IL void split(int x,int y){splay(x,0); splay(y,x);}IL void cl(int x){down(x);int k1=sqrt(maxa[x]); int k2=sqrt(mina[x]);if (k1==k2){lazy[x]=k1; down(x);return;}data[x]=sqrt(data[x]);if (ls[x]) cl(ls[x]);if (rs[x]) cl(rs[x]);updata(x);}IL void ycl(){root=1; rs[1]=2; fa[2]=1; count2[1]=2; count2[2]=1;}IL void ou(int x){down(x);if (ls[x]) ou(ls[x]);if (x!=1&&x!=2)rep(i,1,count3[x]) printf("%d ",data[x]); if (rs[x]) ou(rs[x]);}
}S;
int main()
{freopen("1.in","r",stdin);freopen("1.out","w",stdout);ios::sync_with_stdio(false);int m;cin>>m;maxa[0]=-INF; mina[0]=INF;int len=0;rep(i,3,N-1) q.push(i);rep(i,0,N-1) lazy[i]=INF,count3[i]=1;S.ycl();rep(i,1,m){minxx=min(minxx,q.size());int x,y,z,k;cin>>k;if (k==1){cin>>x>>y;rint now=S.search(len+1);S.splay(2,0); S.splay(now,2);rint now2=rs[now]=q.front(); q.pop();count3[now2]=x; data[now2]=y; fa[now2]=now;  if (x!=1) s[now2]=1;S.splay(now2,0);len+=x;}if (k==2){int x;cin>>x;len-=x;x=S.search(x+2);S.split(1,x);
//      S.dfs2(ls[x]);ls[x]=0;S.splay(x,0);}if (k==3){int kk;cin>>x>>y>>z>>kk;rint t=y-x+1;rint ans=1;while(z){if (z&1) ans=(1ll*ans*t)%kk;t=(1ll*t*t)%kk;z>>=1;}int l=S.search(x);int r=S.search(y+2); S.split(l,r);lazy[ls[r]]=ans;S.splay(ls[r],0);}if (k==4){int x,y;cin>>x>>y;//cout<<x<<" "<<y<<endl;len-=y-x; x=S.search(x),y=S.search(y+2);S.split(x,y);S.down(ls[y]);int now=ls[y];int mm=maxa[now];//    S.dfs2(ls[now]); S.dfs2(rs[now]);ls[now]=rs[now]=0; lazy[now]=INF; count3[now]=1; s[now]=0;data[now]=mm; S.splay(now,0);printf("%d\n",mm);}if (k==5){cin>>x>>y;x=S.search(x),y=S.search(y+2);S.split(x,y);int now=ls[y];S.cl(now); }}S.ou(root);
//  printf("\n%d\n%d",cnt,minxx);return 0; 
}

 

转载于:https://www.cnblogs.com/yinwuxiao/p/9497398.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/413500.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

css 英文换行且单词始终保持在一起

方法一&#xff1a; 想让单词不换行用 word-break:keep-all; white-space:nowrap; 方法二&#xff1a; dispaly:block;text-overflow:ellipsis;overflow:hidden;white-space:nowrap; a换行且a内文本不换行 display:block;或者display:inline-block; width:xxpx;

工作333:uni-增加添加成功提示

this.$u.api.getPartyAdd(this.form).then(res > {console.log(res)if(res.data.code200){/* uni.showLoading({title: 添加中}); */this.$refs.uToast.show({title: res.data.message,type: success,})setTimeout(function () {uni.navigateTo({url: "../notice_notic…

HDU 6064 RXD and numbers

传送门 有向图生成树计数 &#xff08;度数 ->入度->外向树&#xff09; BEST定理 &#xff08;不定起点的欧拉回路个数某点为根的外向树个数&#xff08;存在欧拉回路->每个点为根的外向树个数相等&#xff09;*&#xff08;每个点的度数&#xff08;存在欧拉回路-&g…

vue.js框架的生命周期:常用钩子函数

//组件实例化之前执行的函数 beforeCreate:function () { alert("组件实例化之前执行的函数") }, //组件实例化完毕执行的函数 created:function () { alert("组件实例化完毕执行的函数") }, //组件挂载前&#xff0c;页面仍未展示&#xff0c;但虚拟Dom已…

工作334:uni-控制整个label区域可选

<navigator url"../LevineHua-editor/LevineHua-editor" class"single"><u-form-item label"内容" label-width"100%" prop"content" class"label-left"><u-input placeholder"请输入公告内容…

零基础Python知识点回顾(一)

如果你是小白&#xff0c;建议只要安装官网的python-3.7.0-amd64.exe 然后在电脑cmd命令提示符 输入检查是否已经安装pip,一般安装了python都会有的。 >pip (有的话会提示一大串说明&#xff0c;没有的话会提示没有) 假设有了pip&#xff0c;下面来用pip 来安装…

vue.js常用命令

安装webpack&#xff1a; npm install webpack webpack-cli -g 安装vue-cli&#xff1a; npm install -g vue-cli 用 vue-cli 来构建项目&#xff1a; vue1.x——vue init webpack vue-demo vue2.x——vue init webpack-simple vue-demo 安装路由&#xff1a; npm instal…

工作335:uni-增加表单验证

<u-form-item prop"account"><u-input v-model"form.account" placeholder"请输入账号"></u-input></u-form-item><u-form-item prop"password"><u-input class"inp" v-model"form.p…

使用IDEA 创建SpringBoot项目

首先File ->New -> project ->Spring Initializr ->next 如果没有Spring Initializr 选择右下角config ->setting 搜索Springboot 勾选 然后apply ok 第二步&#xff1a; 在项目中写上自己需要的名称 type 选择 maven project ->next 第三步&#xff1a;…

工作335:uni-ele-el-date-picker限制选择时间

<el-form-item :label"index 1 .发布时间"><el-date-picker v-model"task.start_time" :picker-options"pickerOptions" :disabled"viewMode"/></el-form-item>pickerOptions: {disabledDate(time) {return time…

PhantomJS 一个隐形的浏览器

下载地址: http://phantomjs.org/download.html 使用方法: 下载压缩包解压出来找到phantomjs.exe 放到python的根目录下 转载于:https://www.cnblogs.com/kaibindirver/p/9509684.html

Vue介绍-Vue简单应用-Vue基本用法

什么是Vue&#xff1f;1、Vue.js&#xff08;读音 /vjuː/, 类似于 view&#xff09; 是一套构建用户界面的渐进式框架。2、Vue 只关注视图层&#xff0c; 采用自底向上增量开发的设计。3、Vue 的目标是通过尽可能简单的 API 实现响应的数据绑定和组合的视图组件。Vue可以用来做…

[css] 你们团队中css的class命名采用的是什么方式呢?下划线还是横线还是驼峰?

[css] 你们团队中css的class命名采用的是什么方式呢&#xff1f;下划线还是横线还是驼峰&#xff1f; 形式 .a .a-b不用驼峰和_&#xff0c;因为这两样都需要 shift 辅助输入, 驼峰越多&#xff0c;按下shift 键的次数就越多。个人简介 我是歌谣&#xff0c;欢迎和大家一起交…

[css] 一个项目中有很多无用的css代码,怎么找到并清除这些无用的代码?

[css] 一个项目中有很多无用的css代码&#xff0c;怎么找到并清除这些无用的代码&#xff1f; 1.使用浏览器插件 2.使用PurifyCSS 3.chrome浏览器 F12审查元素的Audits&#xff0c;手动删个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放弃很容易&#xff0c;…

Mysql:替换某个字段中的部分字符串——replace函数

需求&#xff1a;因同事操作不当&#xff0c;使某个字段出现了不必要的字符串&#xff0c;导致数据无法正常解析&#xff0c;需要将该字符串统一去掉。

线段树、树状数组

A 树状数组:1 #include<iostream>2 #include<cstdio>3 #include<algorithm>4 #include <string.h>5 using namespace std;6 // 1h / 10min7 const int maxn 32001;8 int c[maxn],ans[maxn]; // c[i] : 以i为横坐标的星星左侧和下侧星星的个数&#xf…

[css] 怎么给手持设备添加特殊样式?

[css] 怎么给手持设备添加特殊样式&#xff1f; -webkit-touch-callout:none ---------- 禁止长按弹出菜单个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放弃很容易&#xff0c; 但坚持一定很酷。欢迎大家一起讨论 主目录 与歌谣一起通关前端面试题

{ parser: babylon } is deprecated; we now treat it as { parser: babel }.

npm run dev 错误提示&#xff1a; { parser: "babylon" } is deprecated; we now treat it as { parser: "babel" }. 治标的解决方法&#xff1a; 找到你的工程文件夹里的 YourProName\node_modules\vue-loader\lib\template-compiler\index.js //将以…

[css] 写出在不固定宽高的元素在固定高度的情况下水平垂直居中的方法

[css] 写出在不固定宽高的元素在固定高度的情况下水平垂直居中的方法 flex布局&#xff1b;还有就是可以用定位也可以实现等等&#xff1b; flex&#xff1a;父div&#xff1a;&#xff5b;display&#xff1a;flex&#xff1b; justify-content: center;align-items: center;…

npm WARN build `npm build` called with no arguments. Did you mean to `npm run-script build`

跑npm build结果如下&#xff1a; npm WARN build npm build called with no arguments. Did you mean to npm run-script build 把指令改成 npm run build 即可