题意

李超树板子题。

对每个区间维护该区间中点\(mid\)的最优线段。

插入一个线段:

求出这个线段的斜率和截距,注意特判无斜率的情况,得到\(y=kx+b\)。

之后开始在线段树上插入,假设当前节点\(p\)区间为\([l,r]\)包含在插入区间内,那么比较插入的线段\(id\)与当前维护的线段\(pos\),分类讨论:

1.\(id\)完全优于\(pos\):直接替换。

2.\(id\)完全劣于\(pos\):什么也不做。

3.找到在\(mid\)优的那条线段,将劣的那条下放到左右儿子中,那边有优势(相较于在\(mid\)更优的那条)下放哪边。

查询:

查到叶子节点后回溯,不断当前节点维护的(我们插入时把劣的那条下放,因此叶子结点不一定最优)比较。

code:

#include<bits/stdc++.h>
using namespace std;
#define ls(p) (p<<1)
#define rs(p) (p<<1|1)
const int maxn=40000;
const int maxm=1e5+10;
const double eps=1e-8;
int n,m,lastans,cnt;
int maxpos[maxn<<2];
double k[maxm],b[maxm];
inline int read()
{
char c=getchar();int res=0,f=1;
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9')res=res*10+c-'0',c=getchar();
return res*f;
}
inline double f(int x,int id){return k[id]*x+b[id];}
inline bool check(int a,int b,int x){return fabs(f(x,a)-f(x,b))>eps?f(x,a)<f(x,b):a>b;}
void insert(int p,int l,int r,int ql,int qr,int id)
{
int mid=(l+r)>>1;
if(l>=ql&&r<=qr)
{
if(check(id,maxpos[p],l)&&check(id,maxpos[p],r))return;
if(!check(id,maxpos[p],l)&&!check(id,maxpos[p],r)){maxpos[p]=id;return;}
if(!check(id,maxpos[p],mid))swap(id,maxpos[p]);
if(!check(id,maxpos[p],l))insert(ls(p),l,mid,ql,qr,id);
else insert(rs(p),mid+1,r,ql,qr,id);
return;
}
if(ql<=mid)insert(ls(p),l,mid,ql,qr,id);
if(qr>mid)insert(rs(p),mid+1,r,ql,qr,id);
}
int query(int p,int l,int r,int pos)
{
if(l==r)return maxpos[p];
int mid=(l+r)>>1,res;
res=pos<=mid?query(ls(p),l,mid,pos):query(rs(p),mid+1,r,pos);
res=check(res,maxpos[p],pos)?maxpos[p]:res;
return res;
}
int main()
{
n=read();
for(int i=1;i<=n;i++)
{
int op=read();
if(!op)
{
int k=(read()+lastans-1)%39989+1;
printf("%d\n",lastans=query(1,1,40000,k));
}
else
{
int x0=(read()+lastans-1)%39989+1,y0=(read()+lastans-1)%1000000000+1,x1=(read()+lastans-1)%39989+1,y1=(read()+lastans-1)%1000000000+1;
cnt++;
if(x1<x0)swap(x0,x1),swap(y0,y1);
if(x0==x1)k[cnt]=0,b[cnt]=max(y0,y1);
else k[cnt]=1.0*(y1-y0)/(x1-x0),b[cnt]=1.0*y0-1.0*k[cnt]*x0;
insert(1,1,40000,x0,x1,cnt);
}
}
return 0;
}

最新文章

  1. Spring boot: Request method &#39;DELETE&#39; not supported, Request method &#39;PUT&#39; not supported, Request method &#39;POST&#39; not supported
  2. Mac OS X常用操作入门指南
  3. HTML5 十大新特性(六)——地理定位
  4. Koala-Sass编译
  5. ASM:《X86汇编语言-从实模式到保护模式》第12章:存储器的保护
  6. 自定义控件之 TextBox
  7. 13. Reorder List
  8. leetcode 125
  9. nodejs学习之表单提交(1)
  10. 打开网页自动弹出qq客户端
  11. 关于常用meta的总结
  12. poj2752 Seek the Name, Seek the Fame(next数组的运用)
  13. JAVA技术交流群
  14. Beta冲刺 4
  15. ubuntu18.04静态ip设置
  16. 把Oracle由归档模式改为非归档模式
  17. Java知多少(99)Graphics2D类的绘图方法
  18. 102. Binary Tree Level Order Traversal 广度优先遍历
  19. 小学四则运算APP 第一个冲刺阶段 第三天
  20. 关于Cocos2d-x中打包图集和使用方法

热门文章

  1. poj 3070 矩阵计算Fibonacci
  2. Maven为项目配置仓库
  3. WPF 精修篇 数据触发器
  4. seq参数 RANDOM 参数 openssl参数 cut参数
  5. eclipse3.7以后编译代码提示ambiguous 的解决方法
  6. 微服务SpringCloud项目架构搭建入门
  7. Sublime和VSCode生成基础HTML代码
  8. 拎壶学python3-----(2)python之if语句用法
  9. Elastic:如何在一个机器上同时模拟多个node
  10. 转 googlenet论文解读