博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UESTC #1919 一棵复杂的线段树
阅读量:7052 次
发布时间:2019-06-28

本文共 1423 字,大约阅读时间需要 4 分钟。

给一个\(1 \sim n\)的排列,进行\(m\)次操作,可以将一个区间\([l,r]\)内的数升序排序或者降序排序,最后进行一次询问问第\(k\)个数字为多少。

Solution

二分答案,对于每一个二分的值\(x\),将原排列中小于等于\(x\)的数视为\(0\),大于\(x\)的树视为\(1\),用线段树维护,排序操作可以用线段树的区间赋值实现。

/* Author: LargeDumpling Email: LargeDumpling@qq.com Edit History:    2018-07-24  File created.*/#include
#include
#include
#include
#include
#include
using namespace std;const int MAXN=100050;struct jz{ int l,r,typ;}O[MAXN];int num[MAXN],sum[MAXN<<2],tag[MAXN<<2],L[MAXN<<2],R[MAXN<<2],n,m,k;void maintain(int root){ sum[root]=sum[root<<1]+sum[root<<1|1]; return;}void build(int root,int l,int r,int x){ L[root]=l; R[root]=r; tag[root]=-1; if(l==r) { sum[root]=(num[l]<=x)?0:1; return; } int mid=(l+r)>>1; build(root<<1,l,mid,x); build(root<<1|1,mid+1,r,x); maintain(root); return;}void down(int root){ if(tag[root]==-1) return; sum[root<<1]=tag[root]*(R[root<<1]-L[root<<1]+1); tag[root<<1]=tag[root]; sum[root<<1|1]=tag[root]*(R[root<<1|1]-L[root<<1|1]+1); tag[root<<1|1]=tag[root]; tag[root]=-1; return;}void change(int root,int l,int r,int x){ if(r
>1; if(l<=mid) change(root<<1,l,r,x); if(mid
>1; if(l<=mid) ans+=query(root<<1,l,r); if(mid
>1; if(check(mid)) r=mid; else l=mid; } printf("%d\n",r); fclose(stdin); fclose(stdout); return 0;}

Other thing

傅大爷数据出的太好了,把我原来线段树的写法卡疯了。

转载于:https://www.cnblogs.com/LargeDumpling/p/9362321.html

你可能感兴趣的文章
C#类型简述
查看>>
Go:字符串操作
查看>>
EXCEL 2010学习笔记 —— VLOOKUP函数 嵌套 MATCH 函数
查看>>
android graphics: 2D animation
查看>>
升级 python 2.6.6 系统到 2.7.10 版本
查看>>
start with connect by prior 递归查询用法
查看>>
OS X 10.11 安装Cocoapods
查看>>
MATLAB测试机器零阈值的大小
查看>>
优化查询
查看>>
odoo开发笔记-自定义发送邮件模板
查看>>
19、集合概述
查看>>
茄子烧豆角
查看>>
Jmeter(三)-简单的HTTP请求(非录制)
查看>>
linux查看系统类型和版本
查看>>
ThinkPHP将上传问件添加到数据库
查看>>
python 不同目录间的模块调用
查看>>
centos7 安装 chrome
查看>>
IOS 关于上传图片裁剪以及压缩,确保高清
查看>>
HDU - 6115 Factory (LCA 倍增)
查看>>
unity客户端与c++服务器之间的简单通讯_1
查看>>