大致题意:

      给出三种操作

        1、往平面点集中添加一个点

        2、删除第i次添加的点

        3、给出一个q,询问平面点集中的q*x+y的最大值

  

    首先对于每个询问,可将z=q*x+y转化为y=z-q*x,即过点(x,y)的斜率为-q的最大截距,很容易发现这些点只会在上凸包上,只要在

    凸包上三分即可。

    对于插入和删除操作,对于每个点可求得其“生存周期”,即其存在于[L,R]的时间范围内。对每个点的时间区间建线段树,则每次询问的

    答案即为询问所在的区间内凸包上点中的最大值。

    

 #include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<time.h>
#include<cstdlib>
#include<cmath>
#include<list>
using namespace std;
#define MAXN 300100
#define eps 1e-5
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Fore(i,a,b) for(int i=a;i>=b;i--)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mkp make_pair
#define pb push_back
#define cr clear()
#define sz size()
#define met(a,b) memset(a,b,sizeof(a))
#define iossy ios::sync_with_stdio(false)
#define fr freopen
#define pi acos(-1.0)
#define Vector Point
const long long inf=1LL<<;
const int Mod=1e9+;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int dcmp(double x){
if(fabs(x)<=eps) return ;
return x<?-:;
}
struct Point {
ll x,y;
int l,r;
Point(ll x=,ll y=) : x(x),y(y) {}
Point operator - (const Point &a)const{ return Point(x-a.x,y-a.y); }
Point operator + (const Point &a)const{ return Point(x+a.x,y+a.y); }
Point operator * (const double &a)const{ return Point(x*a,y*a); }
Point operator / (const double &a)const{ return Point(x/a,y/a); }
bool operator < (const Point &a)const{ if(x==a.x) return y<a.y;return x<a.x; }
bool operator == (const Point &a)const{ return dcmp(x-a.x)== && dcmp(y-a.y)==; }
void read() { scanf("%lld%lld",&x,&y);}
void out(){cout<<"Bug: "<<x<<" "<<y<<endl;}
};
inline ll Cross(Vector a,Vector b) { return a.x*b.y-a.y*b.x; }
inline double Dot(Vector a,Vector b) { return a.x*b.x+a.y*b.y; }
inline double dis(Vector a) { return sqrt(Dot(a,a)); }
Point p[MAXN];
pii q[MAXN];
int mp[MAXN],m,n;
vector<Point>T[MAXN<<];
ll ans[MAXN];
Point ch[MAXN];
int ty[MAXN];
void Insert(int L,int R,Point pp,int l,int r,int rt){
int mid=l+r>>;
// cout<<L<<" "<<R<<" "<<l<<" "<<r<<" "<<rt<<endl;
if(L<=l && r<=R) {T[rt].pb(pp);return ;}
// if(l==r) return ;
if(R<=mid) Insert(L,R,pp,lson);
else if(L>mid) Insert(L,R,pp,rson);
else Insert(L,mid,pp,lson),Insert(mid+,R,pp,rson);
}
ll Query(int x,int now){
int l=,r=m-;
while(l<r-){
int lmid=(l+l+r)/;
int rmid=(l+r+r+)/;
if(x*ch[lmid].x+ch[lmid].y<x*ch[rmid].x+ch[rmid].y) l=lmid;
else r=rmid;
}
For(i,l,r) ans[now]=max(ans[now],x*ch[i].x+ch[i].y);
}
void Down(int l,int r,int rt){
int mid=l+r>>;
if(l<r){
Down(lson);
Down(rson);
}
m=;
for(int i=;i<T[rt].sz;i++){
while(m> && Cross(T[rt][i]-ch[m-],ch[m-]-ch[m-])<=) m--;
ch[m++]=T[rt][i];
}
For(i,l,r){
if(ty[i]==) Query(mp[i],i);
}
}
void solve(){
cin>>n;
met(mp,);
fill(ans,ans+MAXN,-inf);
For(i,,n*) T[i].clear();
met(p,);
int ct=,pt=,now=;
For(i,,n){
scanf("%d",&ty[i]);
if(ty[i]==) p[pt].read(),p[pt].l=i,p[pt].r=n,mp[i]=pt++,now++;
if(ty[i]==) {scanf("%d",&m);p[mp[m]].r=i,now--;}
if(ty[i]==) {scanf("%d",&mp[i]);if(now==) ty[i]=;}
}
sort(p,p+pt);
For(i,,pt-) Insert(p[i].l,p[i].r,p[i],,n,);
Down(,n,);
for(int i=;i<=n;i++){
if(ty[i]==) puts("EMPTY SET");
if(ty[i]==) printf("%lld\n",ans[i]);
}
}
int main(){
// fre("in.txt","r",stdin);
int t=;
while(t--)solve();
return ;
}

[CodeForces - 678F] Lena and Queries 线段树维护凸包的更多相关文章

  1. codeforces Good bye 2016 E 线段树维护dp区间合并

    codeforces Good bye 2016 E 线段树维护dp区间合并 题目大意:给你一个字符串,范围为‘0’~'9',定义一个ugly的串,即串中的子串不能有2016,但是一定要有2017,问 ...

  2. BZOJ 3672[NOI2014]购票(树链剖分+线段树维护凸包+斜率优化) + BZOJ 2402 陶陶的难题II (树链剖分+线段树维护凸包+分数规划+斜率优化)

    前言 刚开始看着两道题感觉头皮发麻,后来看看题解,发现挺好理解,只是代码有点长. BZOJ 3672[NOI2014]购票 中文题面,题意略: BZOJ 3672[NOI2014]购票 设f(i)f( ...

  3. [Educational Round 13][Codeforces 678F. Lena and Queries]

    题目连接:678F - Lena and Queries 题目大意:要求对一个点集实现二维点对的插入,删除,以及询问\(q\):求\(max(x\cdot q+y)\) 题解:对每个点集内的点\(P( ...

  4. Codeforces GYM 100114 D. Selection 线段树维护DP

    D. Selection Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descriptio ...

  5. bzoj 3533: [Sdoi2014]向量集 线段树维护凸包

    题目大意: http://www.lydsy.com/JudgeOnline/problem.php?id=3533 题解: 首先我们把这些向量都平移到原点.这样我们就发现: 对于每次询问所得到的an ...

  6. Codeforces 997E - Good Subsegments(线段树维护最小值个数+历史最小值个数之和)

    Portal 题意: 给出排列 \(p_1,p_2,p_3,\dots,p_n\),定义一个区间 \([l,r]\) 是好的当且仅当 \(p_l,p_{l+1},p_{l+2},\dots,p_r\) ...

  7. Codeforces 678F Lena and Queries

    题意: 你有一个点集,有三种操作: 往集合里插入一个点\((x, y)\) 从集合中删除第\(i\)次操作插入的点 对于给出的\(q\),询问点集中\(x \cdot q + y\)的最大值 分析: ...

  8. [BZOJ2402]陶陶的难题II(树链剖分+线段树维护凸包+分数规划)

    陶陶的难题II 时间限制:40s      空间限制:128MB 题目描述 输入格式 第一行包含一个正整数N,表示树中结点的个数. 第二行包含N个正实数,第i个数表示xi (1<=xi<= ...

  9. Contest Hunter 模拟赛09 A [线段树维护斜率]

    题面 传送门 思路 首先看看我们到底要干什么:有$1e6$次询问,遍历$i$,每次要求一个形如$b_i \ast a_j - a_i \ast b_j$的东西的最大值 考虑如果一个$j$的决策在当前的 ...

随机推荐

  1. 20155307 2016-2017-2 《Java程序设计》第5周学习总结

    20155307 2016-2017-2 <Java程序设计>第5周学习总结 教材学习内容总结 这两章主要讲的是如何处理程序中的异常情况,对于错误,java会将其打包成对象,可以用&quo ...

  2. Throwable、Error、Exception、RuntimeException 区别

    1.java将所有的错误封装为一个对象,其根本父类为Throwable, Throwable有两个子类:Error和Exception. 2.Error是Throwable 的子类,用于指示合理的应用 ...

  3. HDU 3449 Consumer (背包问题之有依赖背包)

    题目链接 Problem Description FJ is going to do some shopping, and before that, he needs some boxes to ca ...

  4. 【转换】Bean、List、Map、Array、String与JSON字符串的相互转换

    import java.beans.Introspector; import java.beans.PropertyDescriptor; import java.math.BigDecimal; i ...

  5. python3学习笔记.4.turtle绘图

    先放上参考 https://docs.python.org/3/library/turtle.html //********************************************** ...

  6. springcloud的Turbine配置监控多个服务的一些坑!!!!InstanceMonitor$MisconfiguredHostException,No message available","path":"/actuator/hystrix.stream,页面不显示服务或者一直loading

    踩了几个小时坑,使用仪表盘监控单个服务的时候很容易,但是一到多个服务,瞬间坑就来了,大概碰到下面三个: 1InstanceMonitor$MisconfiguredHostException, No ...

  7. flask基础之app初始化(四)

    前言 flask的核心对象是Flask,它定义了flask框架对于http请求的整个处理逻辑.随着服务器被启动,app被创建并初始化,那么具体的过程是这样的呢? 系列文章 flask基础之安装和使用入 ...

  8. checkbox 全选和取消

    //全选 $("#checkall").click(function () { if (this.checked) { //如果当前点击的多选框被选中 $('input[type= ...

  9. HDU 2825 Wireless Password

    题目链接:HDU-2825 题意:给出m个单词,要构造出满足包含其中大于等于k个单词的字符串,字符只包括小写字母,问长度为n的这样的串有多少个. 思路:令dp[i][j][k]表示当前已经构造了i个字 ...

  10. python hash()和hashlib

    一.哈希算法 哈希算法:哈希算法并不是特定的算法而是一类算法的统称,只要是完成这种功能的算法都是哈希算法,哈希算法也叫做散列算法.同时这个过程是不可逆的,无法由key推导出data.判断一个哈希算法是 ...