[TJOI2016&HEOI2016] 排序
[题目链接]
https://www.lydsy.com/JudgeOnline/problem.php?id=4552
[算法]
首先 , 二分答案x , 将比x小的数看作1,比x大的数看作0
然后用线段树检验即可
时间复杂度 : O(MlogN^2)
[代码]
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + ; int n , m , q;
int a[MAXN],b[MAXN]; struct Que
{
int op , l , r;
} que[MAXN];
struct Node
{
int l , r;
int tag , cnt;
} Tree[MAXN << ]; template <typename T> inline void chkmax(T &x,T y) { x = max(x,y); }
template <typename T> inline void chkmin(T &x,T y) { x = min(x,y); }
template <typename T> inline void read(T &x)
{
T f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
}
inline void update(int index)
{
Tree[index].cnt = Tree[index << ].cnt + Tree[index << | ].cnt;
}
inline void build(int index,int l,int r)
{
Tree[index].l = l;
Tree[index].r = r;
Tree[index].tag = -;
if (l == r)
{
Tree[index].cnt = b[l];
return;
}
int mid = (l + r) >> ;
build(index << ,l,mid);
build(index << | ,mid + ,r);
update(index);
}
inline void pushdown(int index)
{
int l = Tree[index].l , r = Tree[index].r ,
mid = (l + r) >> ;
if (Tree[index].tag != -)
{
if (Tree[index].tag)
{
Tree[index << ].cnt = mid - l + ;
Tree[index << | ].cnt = r - mid;
Tree[index << ].tag = Tree[index << | ].tag = ;
} else
{
Tree[index << ].cnt = Tree[index << | ].cnt = ;
Tree[index << ].tag = Tree[index << | ].tag = ;
}
Tree[index].tag = -;
}
}
inline void modify(int index,int l,int r,int value)
{
if (l > r) return;
if (Tree[index].l == l && Tree[index].r == r)
{
if (value == ) Tree[index].cnt = Tree[index].r - Tree[index].l + ;
else Tree[index].cnt = ;
Tree[index].tag = value;
return;
}
pushdown(index);
int mid = (Tree[index].l + Tree[index].r) >> ;
if (mid >= r) modify(index << ,l,r,value);
else if (mid + <= l) modify(index << | ,l,r,value);
else
{
modify(index << ,l,mid,value);
modify(index << | ,mid + ,r,value);
}
update(index);
}
inline int query(int index,int l,int r)
{
if (Tree[index].l == l && Tree[index].r == r) return Tree[index].cnt;
pushdown(index);
int mid = (Tree[index].l + Tree[index].r) >> ;
if (mid >= r) return query(index << ,l,r);
else if (mid + <= l) return query(index << | ,l,r);
else return query(index << ,l,mid) + query(index << | ,mid + ,r);
}
inline bool check(int x)
{
for (int i = ; i <= n; i++) b[i] = (a[i] <= x);
build(,,n);
for (int i = ; i <= m; i++)
{
if (que[i].op == )
{
int cnt = query(,que[i].l,que[i].r);
modify(,que[i].l,que[i].l + cnt - ,);
modify(,que[i].l + cnt,que[i].r,);
} else
{
int cnt = query(,que[i].l,que[i].r);
modify(,que[i].l,que[i].r - cnt,);
modify(,que[i].r - cnt + ,que[i].r,);
}
}
return query(,q,q) == ;
} int main()
{ read(n); read(m);
for (int i = ; i <= n; i++) read(a[i]);
for (int i = ; i <= m; i++)
{
read(que[i].op);
read(que[i].l);
read(que[i].r);
}
read(q);
int l = , r = n , ans;
while (l <= r)
{
int mid = (l + r) >> ;
if (check(mid))
{
ans = mid;
r = mid - ;
} else l = mid + ;
}
printf("%d\n",ans); return ; }
[TJOI2016&HEOI2016] 排序的更多相关文章
- BZOJ 4552: [Tjoi2016&Heoi2016]排序
4552: [Tjoi2016&Heoi2016]排序 Time Limit: 60 Sec Memory Limit: 256 MBSubmit: 579 Solved: 322[Sub ...
- bzoj千题计划128:bzoj4552: [Tjoi2016&Heoi2016]排序
http://www.lydsy.com/JudgeOnline/problem.php?id=4552 二分答案 把>=mid 的数看做1,<mid 的数看做0 这样升序.降序排列相当于 ...
- [Tjoi2016&Heoi2016]排序[01序列]
4552: [Tjoi2016&Heoi2016]排序 Time Limit: 60 Sec Memory Limit: 256 MBSubmit: 994 Solved: 546[Sub ...
- 4552: [Tjoi2016&Heoi2016]排序
4552: [Tjoi2016&Heoi2016]排序 链接 分析: 因为只询问一次,所以考虑二分这个数.显然是没有单调性的,但是我们可以二分所有大于等于mid的数中,是否有满足条件的x(而不 ...
- 【BZOJ4552】[Tjoi2016&Heoi2016]排序 二分+线段树
[BZOJ4552][Tjoi2016&Heoi2016]排序 Description 在2016年,佳媛姐姐喜欢上了数字序列.因而他经常研究关于序列的一些奇奇怪怪的问题,现在他在研究一个难题 ...
- [bzoj4552][Tjoi2016][Heoi2016]排序
Description 给出一个$1$到$n$的全排列,现在对这个全排列序列进行$m$次局部排序,排序分为$2$种: $1.(0,l,r)$表示将区间$[l,r]$的数字升序排序; $2.(1,l,r ...
- BZOJ4552: [Tjoi2016&Heoi2016]排序
Description 在2016年,佳媛姐姐喜欢上了数字序列.因而他经常研究关于序列的一些奇奇怪怪的问题,现在他在研究一个难题 ,需要你来帮助他.这个难题是这样子的:给出一个1到n的全排列,现在对这 ...
- [bzoj4552][Tjoi2016&Heoi2016]排序-二分+线段树
Brief Description DZY有一个数列a[1..n],它是1∼n这n个正整数的一个排列. 现在他想支持两种操作: 0, l, r: 将a[l..r]原地升序排序. 1, l, r: 将a ...
- bzoj 4552 [Tjoi2016&Heoi2016]排序 (二分答案 线段树)
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=4552 题意: 给你一个1-n的全排列,m次操作,操作由两种:1.将[l,r]升序排序,2 ...
- BZOJ 4552 [Tjoi2016&Heoi2016]排序 | 二分答案 线段树
题目链接 题面 题目描述 在2016年,佳媛姐姐喜欢上了数字序列.因而他经常研究关于序列的一些奇奇怪怪的问题,现在他在研究一个难题,需要你来帮助他.这个难题是这样子的:给出一个1到n的全排列,现在对这 ...
随机推荐
- server中intersect的用法
intersect 就像数学中的交集一样, select nam from tb_table1 intersect select name from tb_table2 查询的是两个数据集的交集 ...
- iOS时钟,秒针扫秒样式
昨天做一个时钟小demo,发现了一些问题. 描述能力有限,我封装好了一个时钟框架,朋友们可以参考 https://github.com/qianlishun/ClockView 点击这里可以 ...
- [CERC2015]Digit Division
题目描述 We are given a sequence of n decimal digits. The sequence needs to be partitioned into one or m ...
- Linux下设置swappiness参数来配置内存使用到多少才开始使用swap分区(转)
swappiness的值的大小对如何使用swap分区是有着很大的联系的.swappiness=0的时候表示最大限度使用物理内存,然后才是swap空间,swappiness=100的时候表示积极的使用s ...
- ArcEngine中IFeatureClass.Search(filter, Recycling)方法中Recycling参数的理解
转自 ArcEngine中IFeatureClass.Search(filter, Recycling)方法中Recycling参数的理解 ArcGIS Engine中总调用IFeatureCla ...
- ArcGIS Engine三维动画开发 来自:http://www.iarcgis.com/?p=826
ArcGIS Engine 三维开发 来自:http://www.iarcgis.com/?p=826 在三维中,经常使用的一个功能就是播放动画,也就是我们要对一条动画轨迹进行播放,而在ArcGIS ...
- db2安装配置备份还原
环境 cenos 7.0 db2版本 db2_v101_linuxx64_expc.tar 安装db2 解压db2 tar zxvf db2_v101_linuxx64_expc.tar cd exp ...
- [Angular] Communicate Between Components Using Angular Dependency Injection
Allow more than one child component of the same type. Allow child components to be placed within the ...
- 成员函数指针 C++ FAQ LITE — Frequently Asked Questions
http://www.sunistudio.com/cppfaq/pointers-to-members.html C++ FAQ LITE — Frequently Asked Questions ...
- 将Python打印的内容进行高亮的输出
将打印的内容进行高亮的显示 内容: 格式: echo "\033[字背景颜色;字体颜色m字符串\033[0m" 例如: "\033[41;36m something he ...