【BZOJ 3165】 [Heoi2013]Segment 李超线段树
2024-09-03 09:04:08
所谓李超线段树就是解决此题一类的问题(线段覆盖查询点最大(小)),把原本计算几何的题目变成了简单的线段树,巧妙地结合了线段树的标记永久化与标记下传,在不考虑精度误差的影响下,打法应该是这样的。
#include <cstdio>
#include <cstring>
#include <algorithm>
#define mid(a,b) ((a+b)>>1)
typedef long double ld;
const int Inf_x=;
const int Inf_y=;
int cnt,sz;
struct Line{
ld k,b;int id;
inline ld f(int x){return k*x+b;}
inline ld point(Line a){return (b-a.b)/(a.k-k);}
};
struct lcSegment_Tree{
lcSegment_Tree *ch[];
Line line;
}seg[Inf_x<<],*root;
void pushdown(lcSegment_Tree *p,int l,int r,Line line){
ld a1=p->line.f(l),a2=line.f(l),b1=p->line.f(r),b2=line.f(r);
if(a1<=a2&&b1<=b2){p->line=line;return;}
if(a1>a2&&b1>b2)return;
ld x=line.point(p->line);
if(x<=mid(l,r)){
if(a1>a2)pushdown(p->ch[],l,mid(l,r),p->line),p->line=line;
else pushdown(p->ch[],l,mid(l,r),line);
}else{
if(a1>a2)pushdown(p->ch[],mid(l,r)+,r,line);
else pushdown(p->ch[],mid(l,r)+,r,p->line),p->line=line;
}
}
void build(lcSegment_Tree *&p,int l,int r){
p=seg+sz,++sz;
if(l==r)return;
build(p->ch[],l,mid(l,r));
build(p->ch[],mid(l,r)+,r);
}
void insert(lcSegment_Tree *p,int l,int r,int z,int y,Line line){
if(z<=l&&r<=y){pushdown(p,l,r,line);return;}
if(z<=mid(l,r))insert(p->ch[],l,mid(l,r),z,y,line);
if(mid(l,r)<y)insert(p->ch[],mid(l,r)+,r,z,y,line);
}
void query(lcSegment_Tree *p,int l,int r,int pos,ld last,int &ans){
if(p->line.f(pos)>last||(p->line.f(pos)==last&&p->line.id<ans))ans=p->line.id,last=p->line.f(pos);
if(l==r)return;
if(pos<=mid(l,r))query(p->ch[],l,mid(l,r),pos,last,ans);
else query(p->ch[],mid(l,r)+,r,pos,last,ans);
}
int main(){
int T,opt,zzh1,zzh2,wq1,wq2,lastans=,x;Line temp;
scanf("%d",&T),build(root,,Inf_x);
while(T--){
scanf("%d",&opt);
if(opt){
scanf("%d%d%d%d",&zzh1,&zzh2,&wq1,&wq2);
zzh1=(zzh1+lastans-)%Inf_x+,zzh2=(zzh2+lastans-)%Inf_y+,
wq1=(wq1+lastans-)%Inf_x+,wq2=(wq2+lastans-)%Inf_y+;
if(wq1>zzh1)wq1^=zzh1^=wq1^=zzh1,wq2^=zzh2^=wq2^=zzh2;
if(wq1==zzh1)temp.k=.,temp.b=std::max(wq2,zzh2);
else temp.k=(ld)(zzh2-wq2)/(zzh1-wq1),temp.b=zzh2-temp.k*zzh1;
temp.id=++cnt,insert(root,,Inf_x,wq1,zzh1,temp);
}else{
scanf("%d",&x),x=(x+lastans-)%Inf_x+,lastans=;
query(root,,Inf_x,x,.,lastans);
printf("%d\n",lastans);
}
}return ;
}
最新文章
- SQL中Round(),Floor(),Ceiling()函数的浅析
- PHP对象Object的概念
- 使用ActionBar Tab
- 自己做了一个json格式化工具,亲测可以使用
- django中上传图片的写法(转)
- ORACLE之UTL_FILE包详解
- [BTS]The join order has been enforced because a local join hint is used.;Duplicate key was ignored.";.
- python 练习多级菜单思路
- 虚拟机centos6.5 --VirtualBox设置全屏
- windows 8.1 administrator相关设置
- Mvc中DropDownList 和DropDownListFor的常用方法
- 1.配置vsftp服务器
- SpringMVC 实现文件的上传与下载
- Jquery 使用和Jquery选择器
- Tomcat 加腾讯云 实现二级域名访问
- 环境部署(七):linux下Jenkins+Git+JDK持续集成
- 编程调节Win7/Win8系统音量的一种方法
- django面试大全
- 使用 docker compose 安装 tidb
- 使用 IntraWeb (10) - CSS
热门文章
- PHP 十问
- python爬虫之有道在线翻译
- python中如何统计一个类的实例化对象
- 什么是mysql数据库安全 简单又通俗的mysql库安全简介
- Leecode刷题之旅-C语言/python-20.有效的括号
- poj_2339
- 按平均成绩从高到低显示所有学生的“数据库”、“企业管理”、“英语”三门的课程成绩,按如下形式显示: 学生ID,,数据库,企业管理,英语,有效课程数,有效平均分
- javascript 自定义发布与订阅
- Python的文件输入输出,如何追加内容,读取内容,添加内容
- 标志寄存器PSW和汇编条件转移指令解释