BZOJ 4552 排序
省选TM都能有BC原题?
。。。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 100500
#define inf 1000000007
using namespace std;
int n,m,a[maxn],l=inf,r=,mi,q;
int ls[maxn<<],rs[maxn<<],lazy[maxn<<],sum[maxn<<],root,tot=;
int pos[maxn],ans;
struct move
{
int type,l,r;
}p[maxn];
void build(int &now,int left,int right)
{
now=++tot;lazy[now]=-;
if (left==right)
{
pos[left]=now;
if (a[left]>=mi) {lazy[now]=;sum[now]=;}
else {lazy[now]=;sum[now]=;}
return;
}
int mid=(left+right)>>;
build(ls[now],left,mid);
build(rs[now],mid+,right);
sum[now]=sum[ls[now]]+sum[rs[now]];
}
void pushdown(int now,int left,int right)
{
if (lazy[now]==-) return;
if (left==right) return;
int mid=(left+right)>>;
if (lazy[now]==)
{
lazy[ls[now]]=;sum[ls[now]]=;
lazy[rs[now]]=;sum[rs[now]]=;
}
else
{
lazy[ls[now]]=;sum[ls[now]]=mid-left+;
lazy[rs[now]]=;sum[rs[now]]=right-mid;
}
lazy[now]=-;
}
int query(int now,int left,int right,int l,int r)
{
pushdown(now,left,right);
if ((left==l) && (right==r))
return sum[now];
int mid=(left+right)>>;
if (r<=mid) return query(ls[now],left,mid,l,r);
else if (l>=mid+) return query(rs[now],mid+,right,l,r);
else return query(ls[now],left,mid,l,mid)+query(rs[now],mid+,right,mid+,r);
}
void modify(int now,int left,int right,int l,int r,int p)
{
pushdown(now,left,right);
if ((left==l) && (right==r))
{
lazy[now]=p;
if (p==) sum[now]=;
else sum[now]=right-left+;
return;
}
int mid=(left+right)>>;
if (r<=mid) modify(ls[now],left,mid,l,r,p);
else if (l>=mid+) modify(rs[now],mid+,right,l,r,p);
else
{
modify(ls[now],left,mid,l,mid,p);
modify(rs[now],mid+,right,mid+,r,p);
}
sum[now]=sum[ls[now]]+sum[rs[now]];
}
void work0(int x)
{
int len=p[x].r-p[x].l+,lenr=query(root,,n,p[x].l,p[x].r);
if (p[x].l<=p[x].l+(len-lenr)-) modify(root,,n,p[x].l,p[x].l+(len-lenr)-,);
if (p[x].l+(len-lenr)<=p[x].r) modify(root,,n,p[x].l+(len-lenr),p[x].r,);
}
void work1(int x)
{
int len=p[x].r-p[x].l+,lenl=query(root,,n,p[x].l,p[x].r);
if (p[x].l<=p[x].l+lenl-) modify(root,,n,p[x].l,p[x].l+lenl-,);
if (p[x].l+lenl<=p[x].r) modify(root,,n,p[x].l+lenl,p[x].r,);
}
int main()
{
scanf("%d%d",&n,&m);
for (int i=;i<=n;i++)
{
scanf("%d",&a[i]);
l=min(l,a[i]);
r=max(r,a[i]);
}
for (int i=;i<=m;i++)
scanf("%d%d%d",&p[i].type,&p[i].l,&p[i].r);
scanf("%d",&q);
while (l<=r)
{
tot=;
mi=(l+r)>>;
build(root,,n);
for (int i=;i<=m;i++)
{
if (p[i].type==) work0(i);
else work1(i);
}
int regis=query(root,,n,q,q);
if (regis==) {ans=mi;l=mi+;}
else r=mi-;
}
printf("%d\n",ans);
return ;
}
BZOJ 4552 排序的更多相关文章
- BZOJ 4552 排序 Heoi2016
记得当年省选的时候 这道题连暴力都没写对(尴尬ing) (当年天真的认为sort是左闭右闭的hhhhhh) 思路: 首先 二分答案 线段树 首先二分答案,然后需要知道进行m次排序后p位置上的数字是否大 ...
- BZOJ 4552: [Tjoi2016&Heoi2016]排序
4552: [Tjoi2016&Heoi2016]排序 Time Limit: 60 Sec Memory Limit: 256 MBSubmit: 579 Solved: 322[Sub ...
- bzoj 4552 [Tjoi2016&Heoi2016]排序 (二分答案 线段树)
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=4552 题意: 给你一个1-n的全排列,m次操作,操作由两种:1.将[l,r]升序排序,2 ...
- BZOJ 4552 [Tjoi2016&Heoi2016]排序 线段树的分裂和合并
https://www.lydsy.com/JudgeOnline/problem.php?id=4552 https://blog.csdn.net/zawedx/article/details/5 ...
- bzoj 4552 [Tjoi2016&Heoi2016]排序——二分答案
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4552 二分答案,把 >= mid 的设成1.< mid 的设成0,之后排序就变成 ...
- BZOJ 4552 [Tjoi2016&Heoi2016]排序 | 二分答案 线段树
题目链接 题面 题目描述 在2016年,佳媛姐姐喜欢上了数字序列.因而他经常研究关于序列的一些奇奇怪怪的问题,现在他在研究一个难题,需要你来帮助他.这个难题是这样子的:给出一个1到n的全排列,现在对这 ...
- BZOJ 4552: [Tjoi2016&Heoi2016]排序 线段树 二分
目录 此代码是个假代码,只能糊弄luogu,以后再改,路过大佬也可以帮一下辣 update 10.6 此代码是个假代码,只能糊弄luogu,以后再改,路过大佬也可以帮一下辣 /* //fang zhi ...
- bzoj 4552: [Tjoi2016&Heoi2016]排序——二分+线段树
Description 在2016年,佳媛姐姐喜欢上了数字序列.因而他经常研究关于序列的一些奇奇怪怪的问题,现在他在研究一个难题 ,需要你来帮助他.这个难题是这样子的:给出一个1到n的全排列,现在对这 ...
- 排序(bzoj 4552)
Description 在2016年,佳媛姐姐喜欢上了数字序列.因而他经常研究关于序列的一些奇奇怪怪的问题,现在他在研究一个难题 ,需要你来帮助他.这个难题是这样子的:给出一个1到n的全排列,现在对这 ...
随机推荐
- HDU 2672 god is a girl (字符串处理,找规律,简单)
题目 //1,1,2,3,5,8,13,21,34,55…… //斐波纳契数列 #include<math.h> #include<stdio.h> #include<s ...
- MJRefresh插件引起的错误
添加的头部或者尾部刷新,离开这个界面的时候需要移除 - (void)dealloc { [_tableView removeHeader];} 不同版本的处理的方式不同 报的错误: 类的一个实例 ...
- POJ 1607
#include<iostream> #include<iomanip> using namespace std; int main() { //freopen("a ...
- iis 重启 (三种方法)
iis 重启 (三种方法) WINDOWS提供WEB服务的IIS有时候会出现访问过大导致网站打不开,这时重启IIS是最好的选择. 方法/步骤 1 1.界面操作 打开“控制面板”->“管理工具”- ...
- C#格式化输出
double a = 12354.365; Console.WriteLine(string.Format("{0:f4}", a)); 输出a的四位小数
- for语句中声明变量
在C语言中,局部变量应该在函数的可执行语句之前定义,但在C++中变量可在任何语句位置定义,只要允许程序语句的地方,都允许定义变量. 在C99标准中C同C++一样允许在for循环语句中定义变量.并且这个 ...
- WordPress主题制作教程5:循环
wordpress循环分两种,一种是自定义循环,一种是默认循环. 自定义循环:根据指定参数进行实例化 调用所有页面,post_type值:page对应页面,post对应文章 <?php $arg ...
- oracle11g 修改字符集 修改为ZHS16GBK
1.cmd下,cd到oracle数据库软件的服务器端 如:D:\app\Administrator\product\11.2.0\dbhome_1\BIN 2.输入set ORACLE_SID=你想进 ...
- Iterator的remove方法可保证从源集合中安全地删除对象(转)
如果对正在被迭代的集合进行结构上的改变(即对该集合使用add.remove或clear方法),那么迭代器就不再合法(并且在其后使用该迭代器将会有ConcurrentModificationExcept ...
- 编辑器Emacs下载网址(中国镜像)
Root gnu emacs windows File Name ↓ File Size ↓ Date ↓ Parent directory/ - - README 14K 2014-Nov-15 ...