[题目链接]

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 ; }

最新文章

  1. java泛型上下限
  2. |原创|unity 4.3 2D功能SpriteRenderer修改颜色的方法
  3. LDA-math-认识Beta/Dirichlet分布
  4. C# 平时碰见的问题【4】
  5. MacTerminal快捷键
  6. heritrix启动问题修正
  7. 谈论高并发(十二)分析java.util.concurrent.atomic.AtomicStampedReference看看如何解决源代码CAS的ABA问题
  8. Aforge.net 一个专门为开发者和研究者基于C#框架设计
  9. spring的value,null标签
  10. Creating beautiful charts in chinese with ggplot2
  11. node.js面向对象实现(二)继承
  12. 测试 多线程 实现 callable 带返回值
  13. linux状态及原理全剖析
  14. 分布式系统登录功能拦截器的实现以及cookie的共享问题(利用cookie实现session在分布式系统的共享)
  15. 使用ClaimsIdentity来实现登录授权
  16. CentOS6.5下安装Oracle11g
  17. Jquery 表单提交后3s禁用
  18. VIN码识别/车架号识别独家支持云识别
  19. 【pyhon】nvshens图片批量下载爬虫
  20. 走进__proto__属性,看ie是否支持它,谁又来给他归宿

热门文章

  1. Charm Bracelet(01背包)
  2. springcloud了解
  3. 手动扩大栈内存,让AC无忧
  4. 如何在Eclipse中生成Native类对应的JNI的.h文件
  5. [NOIP2000] 提高组 洛谷P1022 计算器的改良
  6. ACM-ICPC 2018 徐州赛区网络预赛 D 杜教筛 前缀和
  7. css三大特性
  8. 【APUE】进程间通信之FIFO
  9. 说说Android应用的persistent属性(转)
  10. Hashmap在JDK8中的提升