[CodeForces - 678F] Lena and Queries 线段树维护凸包
大致题意:
给出三种操作
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 线段树维护凸包的更多相关文章
- codeforces Good bye 2016 E 线段树维护dp区间合并
codeforces Good bye 2016 E 线段树维护dp区间合并 题目大意:给你一个字符串,范围为‘0’~'9',定义一个ugly的串,即串中的子串不能有2016,但是一定要有2017,问 ...
- BZOJ 3672[NOI2014]购票(树链剖分+线段树维护凸包+斜率优化) + BZOJ 2402 陶陶的难题II (树链剖分+线段树维护凸包+分数规划+斜率优化)
前言 刚开始看着两道题感觉头皮发麻,后来看看题解,发现挺好理解,只是代码有点长. BZOJ 3672[NOI2014]购票 中文题面,题意略: BZOJ 3672[NOI2014]购票 设f(i)f( ...
- [Educational Round 13][Codeforces 678F. Lena and Queries]
题目连接:678F - Lena and Queries 题目大意:要求对一个点集实现二维点对的插入,删除,以及询问\(q\):求\(max(x\cdot q+y)\) 题解:对每个点集内的点\(P( ...
- Codeforces GYM 100114 D. Selection 线段树维护DP
D. Selection Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descriptio ...
- bzoj 3533: [Sdoi2014]向量集 线段树维护凸包
题目大意: http://www.lydsy.com/JudgeOnline/problem.php?id=3533 题解: 首先我们把这些向量都平移到原点.这样我们就发现: 对于每次询问所得到的an ...
- 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\) ...
- Codeforces 678F Lena and Queries
题意: 你有一个点集,有三种操作: 往集合里插入一个点\((x, y)\) 从集合中删除第\(i\)次操作插入的点 对于给出的\(q\),询问点集中\(x \cdot q + y\)的最大值 分析: ...
- [BZOJ2402]陶陶的难题II(树链剖分+线段树维护凸包+分数规划)
陶陶的难题II 时间限制:40s 空间限制:128MB 题目描述 输入格式 第一行包含一个正整数N,表示树中结点的个数. 第二行包含N个正实数,第i个数表示xi (1<=xi<= ...
- Contest Hunter 模拟赛09 A [线段树维护斜率]
题面 传送门 思路 首先看看我们到底要干什么:有$1e6$次询问,遍历$i$,每次要求一个形如$b_i \ast a_j - a_i \ast b_j$的东西的最大值 考虑如果一个$j$的决策在当前的 ...
随机推荐
- 【精选】Nginx负载均衡学习笔记(一)实现HTTP负载均衡和TCP负载均衡(官方和OpenResty两种负载配置)
说明:很简单一个在HTTP模块中,而另外一个和HTTP 是并列的Stream模块(Nginx 1.9.0 支持) 一.两个模块的最简单配置如下 1.HTTP负载均衡: http { include m ...
- [转载]js 程序执行与顺序实现详解
http://www.jb51.net/article/36755.htm JavaScript是一种描述型脚本语言,由浏览器进行动态的解析与执行,浏览器对于不同的方式有不同的解析顺序,详细介绍如下, ...
- Web开发中的18个关键性错误
前几年,我有机会能参与一些有趣的项目,并且独立完成开发.升级.重构以及新功能的开发等工作. 本文总结了一些PHP程序员在Web开发中经常 忽略的关键错误,尤其是在处理中大型的项目上问题更为突出.典型的 ...
- Spark MLlib使用有感
这些天在公司里面做文本分析的任务,我跟着玻哥一起做,先研究了算法的可行度,最后决定使用Google的Word2Vector和LDA算法来对文本进行分析.之前因为看过一些Spark的东西,所以准备瞄准M ...
- 【leetcode 简单】 第一百零八题 找到所有数组中消失的数字
给定一个范围在 1 ≤ a[i] ≤ n ( n = 数组大小 ) 的 整型数组,数组中的元素一些出现了两次,另一些只出现一次. 找到所有在 [1, n] 范围之间没有出现在数组中的数字. 您能在不 ...
- 【前端】直击源头的让你3秒理解并且会用Jsonp!!!
1. 同源策略 ajax之所以需要“跨域”,罪魁祸首就是浏览器的同源策略.即,一个页面的ajax只能获取这个页面相同源或者相同域的数据. 如何叫“同源”或者“同域”呢?——协议.域名.端口号都必须相同 ...
- 【总结】前端框架:react还是vue?
之前写了一篇前端框架的大汇总,主要介绍了当下主流的框架和其特性.最近除了bootstrap,就属react和vue最为热门,这篇就主要拿这两个框架来做一下详细对比. 究竟如何正确使用?作为小白的我们从 ...
- css 实现圆形头像
1.方法一 直接设置img为圆形,这种情况下如果图片不是正方形,图片会被拉伸 <img class="circleImg" src="../img/photo/im ...
- Once you eliminate all the other factors,the only thing remaining must be the truth.
Once you eliminate all the other factors,the only thing remaining must be the truth. 一旦你排除了杂因,剩下的一定是 ...
- Windows执行命令与下载文件总结
1.前言 在渗透或是病毒分析总是会遇到很多千奇百怪的下载文件和执行命令的方法. 2.实现方式 2.1.Powershell win2003.winXP不支持 $client = new-object ...