传送门
思路很简单呀,就是套路题
(别听这家伙瞎说,他调了2h+)
线段树分治+凸包+三分
然后就是写三分一定要写那种缩小到一定区间内暴力判定
凸包一定不能错
线段树分治一般不会错
全程开long long
然后就没什么了
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<vector>
#define LL long long
using namespace std;
inline int read(){
int x=0,f=1;char ch=' ';
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
return x*f;
}
const int N=2e5+5;
struct Point{
LL x,y;
Point(){}
Point(LL _x,LL _y):x(_x),y(_y){}
inline Point operator - (const Point& b) const {return Point(x-b.x,y-b.y);}
inline LL operator * (const Point& b) const {return x*b.y-y*b.x;}
inline bool operator < (const Point& b) const {return x==b.x?y<b.y:x<b.x;}
};
vector<Point> t[N<<2],p[N<<2];
int n,tot;
int X[N],Y[N],L[N],R[N];
LL ans[N];
LL qx[N],qy[N];
inline void insert(int rt,int l,int r,int L,int R,int X,int Y){
if(L<=l && r<=R){
t[rt].push_back(Point(X,Y));
return;
}
int mid=(l+r)>>1;
if(L<=mid)insert(rt<<1,l,mid,L,R,X,Y);
if(mid+1<=R)insert(rt<<1|1,mid+1,r,L,R,X,Y);
}
inline void build(int rt){
if(!t[rt].size())return;
sort(t[rt].begin(),t[rt].end());
if(t[rt].size()==1){p[rt].push_back(t[rt][0]);return;}
p[rt].push_back(t[rt][0]);
p[rt].push_back(t[rt][1]);
if(t[rt].size()==2)return;
for(int i=2,top=1;i<t[rt].size();++i){
while(top>0 && (t[rt][i]-p[rt][top])*(p[rt][top]-p[rt][top-1])<=0)p[rt].pop_back(),top--;
p[rt].push_back(t[rt][i]);top++;
}
}
inline void Build(int rt,int l,int r){
build(rt);
if(l==r)return;
int mid=(l+r)>>1;
Build(rt<<1,l,mid);
Build(rt<<1|1,mid+1,r);
}
LL Qx,Qy;
inline LL query(int rt){
int l=0,r=p[rt].size()-1,mid1,mid2;
while(r-l>5){
mid1=(l+l+r)/3;
mid2=(l+r+r)/3;
LL ans1=Qx*p[rt][mid1].x+Qy*p[rt][mid1].y;
LL ans2=Qx*p[rt][mid2].x+Qy*p[rt][mid2].y;
if(ans1<ans2)l=mid1;
else r=mid2;
}
LL ans=0;
for(int i=l;i<=r;++i)ans=max(ans,Qx*p[rt][i].x+Qy*p[rt][i].y);
return ans;
}
inline LL Query(int rt,int l,int r,int pos){
LL ans=query(rt);
if(l==r)return ans;
int mid=(l+r)>>1;
if(pos<=mid)ans=max(ans,Query(rt<<1,l,mid,pos));
else ans=max(ans,Query(rt<<1|1,mid+1,r,pos));
return ans;
}
int main(){
n=read();
for(int i=1;i<=n;++i){
int opt=read();ans[i]=-1;
if(opt==1){
++tot;L[tot]=i;
X[tot]=read();Y[tot]=read();
}
else if(opt==2)R[read()]=i-1;
else qx[i]=read(),qy[i]=read();
}
for(int i=1;i<=tot;++i)if(!R[i])R[i]=n;
for(int i=1;i<=tot;++i)insert(1,1,n,L[i],R[i],X[i],Y[i]);
Build(1,1,n);
for(int i=1;i<=n;++i){
if(qx[i]){
Qx=qx[i];Qy=qy[i];
ans[i]=Query(1,1,n,i);
}
}
for(int i=1;i<=n;++i)if(ans[i]!=-1)printf("%lld\n",ans[i]);
return 0;
}