题意:要求支持三个操作,加入删除一个向量,询问当前向量与给定向量的最大值。

题解:线段树时间分治,每个区间做一个凸包,查询的时候到对应区间的凸包上三分。

(话说我这个可能有点问题,三分那一块R-L>=20我才过的。。)

 #include<bits/stdc++.h>
using namespace std;
#define LL long long
#define N 300005 inline LL read(){
LL x=,f=; char a=getchar();
while(a<'' || a>'') {if(a=='-') f=-; a=getchar();}
while(a>='' && a<='') x=x*+a-'',a=getchar();
return x*f;
} int n,cnt,st[N],ed[N],qnum,root,ti[N];
LL ans; struct point{
LL x,y;
bool operator < (const point& w)const{
if(x==w.x) return y<w.y;
return x<w.x;
}
}p[N],Q[N],tmp[N]; point operator - (const point& a,const point& b){return (point){a.x-b.x,a.y-b.y};} inline LL cross(point a,point b){return a.x*b.y-a.y*b.x;} LL operator * (const point& a,const point& b){
return a.x*b.x+a.y*b.y;
} struct segment{
int l,r;
vector<point>s;
}a[*N]; void build(int k,int l,int r){
a[k].l=l; a[k].r=r;
if(l==r) return;
int mid=(l+r)>>;
build(k<<,l,mid); build(k<<|,mid+,r);
} void insert(int k,int L,int R,int x){
int l=a[k].l,r=a[k].r;
if(l==L && r==R) {a[k].s.push_back(p[x]); return;}
int mid=(l+r)>>;
if(R<=mid) insert(k<<,L,R,x);
else if(mid<L) insert(k<<|,L,R,x);
else insert(k<<,L,mid,x),insert(k<<|,mid+,R,x);
} void convexhull(int k){
if(!a[k].l) return;
int len=a[k].s.size();
sort(a[k].s.begin(),a[k].s.end());
int top=;
for(int i=;i<len;i++){
while(top> && cross(a[k].s[i]-tmp[top-],tmp[top]-tmp[top-])>=) top--;
tmp[++top]=a[k].s[i];
}
int tt=top;
for(int i=len-;i>=;i--){
while(top>tt && cross(a[k].s[i]-tmp[top-],tmp[top]-tmp[top-])>=) top--;
tmp[++top]=a[k].s[i];
}
if(len>) top--;
a[k].s.clear();
for(int i=;i<=top;i++) a[k].s.push_back(tmp[i]);
convexhull(k<<); convexhull(k<<|);
} void query(int k,int pos,int num){
int l=a[k].l,r=a[k].r;
int L=,R=a[k].s.size()-;
while(R-L>=){
int ll=L+(R-L)/,rr=R-(R-L)/;
if(Q[num]*a[k].s[ll]>Q[num]*a[k].s[rr]) R=rr;
else L=ll;
}
for(int i=L;i<=R;i++)
ans=max(ans,Q[num]*a[k].s[i]);
if(l==r) return;
int mid=(l+r)>>;
if(pos<=mid) query(k<<,pos,num);
else query(k<<|,pos,num);
} int main(){
n=read();
for(int i=;i<=n;i++){
int type=read();
if(type==) p[++cnt].x=read(),p[cnt].y=read(),st[cnt]=i;
else if(type==) ed[read()]=i;
else Q[++qnum].x=read(),Q[qnum].y=read(),ti[qnum]=i;
}
build(,,n);
for(int i=;i<=cnt;i++) if(!ed[i]) ed[i]=n;
for(int i=;i<=cnt;i++) insert(,st[i],ed[i],i);
convexhull();
for(int i=;i<=qnum;i++) ans=,query(,ti[i],i),printf("%lld\n",ans);
return ;
}

BZOJ4311:向量的更多相关文章

  1. [BZOJ4311]向量(凸包+三分+线段树分治)

    可以发现答案一定在所有向量终点形成的上凸壳上,于是在上凸壳上三分即可. 对于删除操作,相当于每个向量有一个作用区间,线段树分治即可.$O(n\log^2 n)$ 同时可以发现,当询问按斜率排序后,每个 ...

  2. BZOJ4311 : 向量

    考虑离线操作,求出每个向量存在的时间区间,用时间线段树来进行分治,在每个节点求出凸壳后,询问时在凸壳上三分答案.时间复杂度$O(n\log^2n)$. #include<cstdio> # ...

  3. 2019.02.26 bzoj4311: 向量(线段树分治+凸包)

    传送门 题意: 支持插入一个向量,删去某一个现有的向量,查询现有的所有向量与给出的一个向量的点积的最大值. 思路: 考虑线段树分治. 先对于每个向量处理出其有效时间放到线段树上面,然后考虑查询:对于两 ...

  4. BZOJ4311 向量(线段树分治+三分)

    由点积的几何意义(即投影)可以发现答案一定在凸壳上,并且投影的变化是一个单峰函数,可以三分.现在需要处理的只有删除操作,线段树分治即可. #include<iostream> #inclu ...

  5. bzoj4311向量(线段树分治+斜率优化)

    第二道线段树分治. 首先设当前向量是(x,y),剩余有两个不同的向量(u1,v1)(u2,v2),假设u1>u2,则移项可得,若(u1,v1)优于(u2,v2),则-x/y>(v1-v2) ...

  6. 【BZOJ4311】向量(线段树分治,斜率优化)

    [BZOJ4311]向量(线段树分治,斜率优化) 题面 BZOJ 题解 先考虑对于给定的向量集,如何求解和当前向量的最大内积. 设当前向量\((x,y)\),有两个不同的向量\((u1,v1),(u2 ...

  7. 【bzoj4311】向量 线段树对时间分治+STL-vector维护凸包

    题目描述 你要维护一个向量集合,支持以下操作: 1.插入一个向量(x,y) 2.删除插入的第i个向量 3.查询当前集合与(x,y)点积的最大值是多少.如果当前是空集输出0 输入 第一行输入一个整数n, ...

  8. BZOJ4311:向量——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=4311 你要维护一个向量集合,支持以下操作: 1.插入一个向量(x,y) 2.删除插入的第i个向量 ...

  9. 机器学习实战笔记(Python实现)-05-支持向量机(SVM)

    --------------------------------------------------------------------------------------- 本系列文章为<机器 ...

随机推荐

  1. [转]Linux进程通信之POSIX消息队列

    进程间的消息队列可以用这个实现,学习了下. http://blog.csdn.net/anonymalias/article/details/9799645?utm_source=tuicool&am ...

  2. 次小生成树模板(poj1679)

    prim #include <iostream> #include <cstdio> #include <cstdlib> #include <cmath&g ...

  3. NodeJS版本EasyDarwin开源流媒体服务器开发心得

    title: Node版本EasyDarwin开发心得 date: 2018-03-27 22:46:15 tags: 年后着手Node版本EasyDarwin的开发工作,截止到今天2018年03月2 ...

  4. MySql 批处理

    1. 批处理 批处理只针对更新(增,删,改)语句. MySql 的批处理默认是关闭的, 需要在 url 中配置参数: jdbc:mysal://localhost:3306/mydb1?rewrite ...

  5. speech sdk 文字转语音

    1.下载SDK包 https://www.microsoft.com/en-us/download/details.aspx?id=10121 2.直接上代码 // SpeechRecognition ...

  6. 基于Django的Disqus如何支持每月80亿PV(转)

    原文:基于Django的Disqus如何支持每月80亿PV 本文由 伯乐在线 - 贱圣OMG 翻译.未经许可,禁止转载!英文出处:Matt Robenolt.欢迎加入翻译小组. 现在我们Disqus能 ...

  7. CentOS 7.4系统优化/安装软件

    源改为国内源 阿里云yum源 https://opsx.alibaba.com/mirror 清华yum源 https://mirrors.tuna.tsinghua.edu.cn/ 网易163yum ...

  8. 我的Android进阶之旅------>adbd cannot run as root in production builds 的解决方法

    今天用adb root命令时候,报了错误:adbd cannot run as root in production builds C:\Documents and Settings\Administ ...

  9. 字符串之strstr

    功能:查找第二个字符串是否存在第一个字符串中. 输入:字符串1,字符串2 返回值:成功返回str1中的位置,失败返回NULL #include <iostream> using names ...

  10. C语言运算符优先级误解

    优先级问题 表达式 可能误以为的结果 实际结果 .的优先级高于*. ->操作符用于消除这个问题 *p.f p所指对象的字段f. (*p).f 对p去f偏移,作为指针,然后进行解除引用操作. *( ...