BZOJ传送门

# 思路

$A=x_0x_1+y_0y_1$

$y_1=-\frac{x_0}{y_0}x_1+\frac{A}{y_0}$

# Code

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cassert>
#include<vector>
#define eps 1e-9
#define ll long long
using namespace std;
int re=0,flag=1;char ch=getchar();
while(!isdigit(ch)){
if(ch=='-') flag=-1;
ch=getchar();
}
while(isdigit(ch)) re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
return re*flag;
}
struct node{
ll x,y;
node(ll xx=0,ll yy=0){x=xx;y=yy;}
inline friend bool operator <(const node &a,const node &b){return (a.x==b.x)?(a.y<b.y):(a.x<b.x);}
inline friend node operator -(const node &a,const node &b){return node(a.x-b.x,a.y-b.y);}
inline friend ll operator *(const node &a,const node &b){return a.x*b.y-a.y*b.x;}
inline friend ll operator /(const node &a,const node &b){return a.x*b.x+a.y*b.y;}
};
vector<node>seg[1600010],q1[1600010],q2[1600010];int top1[1600010],top2[1600010],n;
inline void insert(int l,int r,int num,int pos,node p){
seg[num].push_back(p);
int mid=(l+r)>>1,i;
if(pos==r){//只有完全插入的时候才求凸包
sort(seg[num].begin(),seg[num].end());
int &t1=(top1[num]),&t2=(top2[num]);
for(i=0;i<r-l+1;i++){
while(t1>0&&(q1[num][t1]-q1[num][t1-1])*(q1[num][t1]-seg[num][i])<eps) q1[num].pop_back(),t1--;
q1[num].push_back(seg[num][i]);t1++;
while(t2>0&&(q2[num][t2]-q2[num][t2-1])*(q2[num][t2]-seg[num][i])>-eps) q2[num].pop_back(),t2--;
q2[num].push_back(seg[num][i]);t2++;
}
}
if(l==r) return;
if(mid>=pos) insert(l,mid,num<<1,pos,p);
else insert(mid+1,r,num<<1|1,pos,p);
}
inline ll query1(int l,int r,int ql,int qr,int num,node p){
if(l>=ql&&r<=qr){
int L=1,R=top1[num],MID,ANS=0;
while(L<=R){
MID=(L+R)>>1;
if(q1[num][MID]/p>q1[num][MID-1]/p) ANS=MID,L=MID+1;
else R=MID-1;
}
return q1[num][ANS]/p;
}
int mid=(l+r)>>1;ll re=-1e18;
if(mid>=ql) re=max(re,query1(l,mid,ql,qr,num<<1,p));
if(mid<qr) re=max(re,query1(mid+1,r,ql,qr,num<<1|1,p));
return re;
}

inline ll query2(int l,int r,int ql,int qr,int num,node p){
if(l>=ql&&r<=qr){
int L=1,R=top2[num],MID,ANS=0;
while(L<=R){
MID=(L+R)>>1;
if(q2[num][MID]/p>q2[num][MID-1]/p) ANS=MID,L=MID+1;
else R=MID-1;
}
return q2[num][ANS]/p;
}
int mid=(l+r)>>1;ll re=-1e18;
if(mid>=ql) re=max(re,query2(l,mid,ql,qr,num<<1,p));
if(mid<qr) re=max(re,query2(mid+1,r,ql,qr,num<<1|1,p));
return re;
}
int main(){
memset(top1,-1,sizeof(top1));
memset(top2,-1,sizeof(top2));
scanf("%s",op);
for(i=1;i<=n;i++){
if(op[0]!='E'){
t1^=(lastans&0x7fffffff);
t2^=(lastans&0x7fffffff);
if(s[0]=='Q'){
t3^=(lastans&0x7fffffff);
t4^=(lastans&0x7fffffff);
}
}
if(s[0]=='Q'){
if(t2>0) lastans=query1(1,n,t3,t4,1,node(t1,t2));
else lastans=query2(1,n,t3,t4,1,node(t1,t2));
printf("%lld\n",lastans);
}
else insert(1,n,1,++cntn,node(t1,t2));
}
}


posted @ 2019-04-07 13:11  dedicatus545  阅读(136)  评论(0编辑  收藏  举报