shallot+向量集 混合版?

首先我们考虑每个向量的存在时间为[L,R]

那么我们知道任意一个区间在线段树上最多被分解成logn个区间

那么我们可以像shallot一样进行区间覆盖

注意到本题的查询是在凸壳上完成的,而凸壳不像shallot的线性基一样有固定的时间复杂度

但是本题的查询是可分离的,那么我们不需要将向量下传,只需要在线段树的每一层做凸壳即可

查询时每走一层对该层三分取最优解,建造凸壳和三分方法同向量集

QAQ 上午因为排序不小心写反了符号调了好久 QAQ

时间复杂度O(nlog^2n)

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<vector>
using namespace std; typedef long long LL;
const int maxn=200010;
const LL oo=1LL<<62;
int n,m,f,x,cnt;
int top=0;
int L[maxn],R[maxn];
struct Point{
int x,y;
Point(int x=0,int y=0):x(x),y(y){}
void print(){printf("%d %d\n",x,y);}
}p[maxn],st[4000010],now;
typedef Point Vector;
bool cmp(const Point &A,const Point &B){
if(A.x==B.x)return A.y<B.y;
return A.x<B.x;
}
Vector operator -(const Point &A,const Point &B){return Vector(A.x-B.x,A.y-B.y);}
LL Cross(const Point &A,const Point &B){return 1LL*A.x*B.y-1LL*A.y*B.x;}
LL Dot(const Point &A,const Point &B){return 1LL*A.x*B.x+1LL*A.y*B.y;}
struct ASK{
int x,y,t;
}Q[maxn];
struct Seg_Tree{
vector<Point>V;
int A,B;
void Get_Hull(){
A=top+1;
int sz=V.size();
sort(V.begin(),V.end(),cmp);
for(int i=0;i<sz;++i){
while(top>A&&Cross(V[i]-st[top],st[top]-st[top-1])<=0)top--;
st[++top]=V[i];
}B=top;
}
LL Max(){
if(V.empty())return 0;
if(!A)Get_Hull();
int L=A,R=B;
LL ans=0;
while(R-L>=3){
int m1=(L+L+R)/3,m2=(L+R+R)/3;
if(Dot(st[m1],now)<=Dot(st[m2],now))L=m1;
else R=m2;
}
for(int i=L;i<=R;++i)ans=max(ans,Dot(st[i],now));
return ans;
}
}t[maxn<<2];
void read(int &num){
num=0;char ch=getchar();
while(ch<'!')ch=getchar();
while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
}
void modify(int o,int L,int R,int x,int y,int id){
if(L>=x&&R<=y){
t[o].V.push_back(p[id]);
return;
}
int mid=(L+R)>>1;
if(y<=mid)modify(o<<1,L,mid,x,y,id);
else if(x>mid)modify(o<<1|1,mid+1,R,x,y,id);
else modify(o<<1,L,mid,x,y,id),modify(o<<1|1,mid+1,R,x,y,id);
}
LL ask(int o,int L,int R,int p){
if(L==R)return t[o].Max();
int mid=(L+R)>>1;
if(p<=mid)return max(t[o].Max(),ask(o<<1,L,mid,p));
else return max(t[o].Max(),ask(o<<1|1,mid+1,R,p));
}
int main(){
read(n);
for(int i=1;i<=n;++i){
read(f);
if(f==1){
++cnt;
read(p[cnt].x);read(p[cnt].y);
L[cnt]=i;
}else if(f==2){
read(x);R[x]=i;
}else{
++m;
read(Q[m].x);read(Q[m].y);
Q[m].t=i;
}
}
for(int i=1;i<=cnt;++i){
if(!R[i])R[i]=n;
modify(1,1,n,L[i],R[i],i);
}
for(int i=1;i<=m;++i){
now=Point(Q[i].x,Q[i].y);
printf("%lld\n",ask(1,1,n,Q[i].t));
}
return 0;
}

  

BZOJ 4311 向量的更多相关文章

  1. BZOJ 4311: 向量( 按时间分治 + 线段树 )

    离线, 然后按时间分治, 每个向量都有出现时间[l, r], 直接插入时间线段树(一个向量只会影响O(logN)数量级的线段树节点). 在线段树每个节点弄出凸壳然后二分. 时间复杂度O(Nlog^2N ...

  2. bzoj 4311 向量 时间线建线段树+凸包+三分

    题目大意 你要维护一个向量集合,支持以下操作: 1.插入一个向量(x,y) 2.删除插入的第i个向量 3.查询当前集合与(x,y)点积的最大值是多少.如果当前是空集输出0 分析 按时间线建线段树 大致 ...

  3. 【BZOJ】4311: 向量(线段树分治板子题)

    题解 我们可以根据点积的定义,垂直于原点到给定点构成的直线作一条直线,从正无穷往下平移,第一个碰到的点就是答案 像什么,上凸壳哇 可是--动态维护上凸壳? 我们可以离线,计算每个点能造成贡献的一个询问 ...

  4. BZOJ 3243 向量内积

    Description 两个\(d\)维向量\(A=[a_{1},a_{2},...,a_{d}]\)与\(B=[b_{1},b_{2},...,b_{d}]\)的内积为其相对应维度的权值的乘积和,即 ...

  5. [BZOJ]3243 向量内积(Noi2013)

    小C做了之后很有感觉的题目之一,但因为姿势不对调了很久. Description 两个d 维向量A=[a1,a2,...,ad]与B=[b1,b2,...,bd]的内积为其相对应维度的权值的乘积和,即 ...

  6. BZOJ 2299 向量

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2299 题意:给出一对数a,b,任意使用(a,b), (a,-b), (-a,b), (- ...

  7. BZOJ 2299 向量(裴蜀定理)

    题意:给你一对数a,b,你可以任意使用(a,b), (a,-b), (-a,b), (-a,-b), (b,a), (b,-a), (-b,a), (-b,-a)这些向量,问你能不能拼出另一个向量(x ...

  8. bzoj 4004 向量拟阵

    题解RT. eps = 1e-10 WrongAnswer eps = 1e-5 Accepted /************************************************* ...

  9. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

随机推荐

  1. JSON解析例子

    //解析的东西是数组就用数组接受,是字典就用字典接受 //my.h#ifndef __1_Header_h#define __1_Header_h#define DEBUG 1#define aa 1 ...

  2. 委托[delegate]_C#

    委托(delegate): 委托声明定义了一种类型,它用一组特定的参数以及返回类型来封装方法.对于静态方法,委托对象封装要调用的方法.对于实例方法,委托对象同时封装一个实例和该实例上的一个方法.如果您 ...

  3. (转)Salesforce的440亿美金并购宣告企业软件市场进入3.0互联网化时代

    导语:Salesforce代表着“移动+云”时代企业软件领域新的架构和商业模式的颠覆者.企业软件转向“移动+云”架构,将极大改变传统企业IT市场的格局…… 近期一则新闻极大的刺激了企业软件市场的神经, ...

  4. DOM_节点层次_Element类型

    一.Element类型: nodeType: 1; nodeName: 元素名; nodeValue: null; parentValue: Document 或者 Element; var oDiv ...

  5. Windows 右键添加「cmd 打开」

    1. 2. 3. 参考: 1.Windows右键添加"使用CMD打开" 2.WIN7.WIN8 右键在目录当前打开命令行Cmd窗口(图文)

  6. C++运用SDK截屏

    引言 最近有一个需要截取当前屏幕,并保存成BMP文件的需求.整个需求,拆分成三步:1.截取屏幕,获得位图数据.2.配合bmp文件结构信息,将数据整合.3.对整合后的数据做操作,如保存在本地.通过网络传 ...

  7. ListView 复制到剪切板

    private void 导出ToolStripMenuItem_Click(object sender, EventArgs e) { Clipboard.SetText(GetListView(l ...

  8. dapper extensions (predicates)

    https://github.com/tmsmith/Dapper-Extensions/wiki/Predicates The predicate system in Dapper Extensio ...

  9. liger grid loadData

    function fn_Search() { var beginDt = $("#txtBegin").val(); var endDt = $("#txtEnd&quo ...

  10. API删除文件

    using System; using System.Runtime.InteropServices; namespace ConsoleApplication1 { class Program { ...