传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3533
显然答案一定在凸包上
所以我们需要维护区间凸包然后三分
凸包的合并是线性的
所以不能每加一个点就维护一次线段树……
考虑线段树的结点个数是线性的
线段树每个结点维护的区间长度总和是nlogn级别的
对于一个询问[l,r]把它拆成logn个区间,如果这个结点没有构建凸包,暴力构建,然后查询答案
这样下来每个结点最多建一次,建凸包的复杂度再挂一个logn,均摊每次操作就是log^2n的
其他:
1.树套树有可能因为常数T几个点
2.二进制分组太神看不懂
3.drcow的标程有点问题,似乎只维护了上凸壳然后x轴翻转就当下凸壳用了 = =、对于一些负数和0的数据会WA,但是官方数据全都过了……
Code:
#include<cstdio>
#include<cctype>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=4e5+5;
typedef long long LL;
int n,m,tmpsize;
LL lastans=0;
int getint(){
int res=0,f=1;char c=getchar();
while(!isdigit(c))f=f==-1||c=='-'?-1:1,c=getchar();
while(isdigit(c))res=res*10+c-'0',c=getchar();
return (res*f);
}
int decode(LL x){return x^(lastans&0x7fffffff);}
struct point{
int x,y;
point(int _x=0,int _y=0):
x(_x),y(_y){}
}p[maxn],tmp[maxn];
point operator+(const point &a,const point &b){return point(a.x+b.x,a.y+b.y);}
point operator-(const point &a,const point &b){return point(a.x-b.x,a.y-b.y);}
LL operator*(const point &a,const point &b){return (LL)a.x*b.y-(LL)a.y*b.x;}
LL operator^(const point &a,const point &b){return (LL)a.x*b.x+(LL)a.y*b.y;}
bool operator<(const point &a,const point &b){return a.x<b.x||(a.x==b.x&&a.y<b.y);}
struct CH{
point *up,*dw;
int upsize,dwsize;
void init(int l,int r){
up=new point[r-l+2];
dw=new point[r-l+2];
tmpsize=dwsize=upsize=0;
for(int i=l;i<=r;i++)tmp[++tmpsize]=p[i];
sort(tmp+1,tmp+1+tmpsize);
for(int i=1;i<=tmpsize;i++){
while(upsize>1&&(tmp[i]-up[upsize])*(up[upsize]-up[upsize-1])<=0)upsize--;
up[++upsize]=tmp[i];
while(dwsize>1&&(dw[dwsize]-dw[dwsize-1])*(tmp[i]-dw[dwsize])<=0)dwsize--;
dw[++dwsize]=tmp[i];
}
}
LL Qmax(point p){
int l,r,mid1,mid2;
LL res=-(1LL<<61);
if(p.y>=0){
l=1;r=upsize;
while(r-l>2){
mid1=l+(r-l)/3;
mid2=r-(r-l)/3;
if((up[mid1]^p)<(up[mid2]^p))
l=mid1;
else r=mid2;
}for(int i=l;i<=r;i++)res=max(res,up[i]^p);
}else{
l=1;r=dwsize;
while(r-l>2){
mid1=l+(r-l)/3;
mid2=r-(r-l)/3;
if(dw[mid1]^p<dw[mid2]^p)
l=mid1;
else r=mid2;
}for(int i=l;i<=r;i++)res=max(res,dw[i]^p);
}return res;
}
};
struct seg{
#define lson i<<1,l,mid
#define rson i<<1|1,mid+1,r
#define L i<<1
#define R i<<1|1
bool bud[maxn<<2];
CH C[maxn<<2];
LL Qmax(int i,int l,int r,int l0,int r0,point p){
if(l0<=l&&r0>=r){
if(bud[i])return C[i].Qmax(p);
bud[i]=1;C[i].init(l,r);
return C[i].Qmax(p);
}int mid=(l+r)>>1;LL ans=-(1LL<<61);
if(l0<=mid)ans=max(ans,Qmax(lson,l0,r0,p));
if(r0>mid)ans=max(ans,Qmax(rson,l0,r0,p));
return ans;
}
#undef lson
#undef rson
#undef L
#undef R
}T;
struct qes{int l,r,x,y,ty;}Q[maxn];
int main(){
m=getint();char type=getchar();
while(!isalpha(type))type=getchar();
for(int i=1;i<=m;i++){
char op=getchar();while(op!='A'&&op!='Q')op=getchar();
int l=0,r=0,x=0,y=0,ty=0;LL ans=0;
if(op=='Q'){
x=getint();y=getint();
l=getint();r=getint();
ty=1;
}else{
x=getint();y=getint();
n++;ty=2;
}Q[i]=(qes){l,r,x,y,ty};
}int size=0;
for(int i=1;i<=m;i++){
int l=0,r=0,x=0,y=0;LL ans=0;
if(Q[i].ty==1){
x=decode(Q[i].x);y=decode(Q[i].y);
l=decode(Q[i].l);r=decode(Q[i].r);
printf("%lld\n",(ans=T.Qmax(1,1,n,l,r,point(x,y))));
if(type!='E')lastans=ans;
}else{
x=decode(Q[i].x);y=decode(Q[i].y);
p[++size]=point(x,y);
}
}
return 0;
}