[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$的决策在当前的 ...
随机推荐
- Django 2.0.1 官方文档翻译:接下来读什么(page 14)
接下来读什么(page 14) 现在你应该已经阅读了所有的(page1-13 )介绍材料,决定继续使用Django.我们仅仅做了简要的介绍(事实上,如果你阅读了前面所有的内容,也只是全部文档的5%.) ...
- springboot 以jar方式在linux后台运行
linux命令如下: nohup java -jar 自己的springboot项目.jar >日志文件名.log 2>&1 & 命令解释: nohup:不挂断地运行命令, ...
- Java并发编程原理与实战六:主线程等待子线程解决方案
本文将研究的是主线程等待所有子线程执行完成之后再继续往下执行的解决方案 public class TestThread extends Thread { public void run() { Sys ...
- Function Names as Strings
[Function Names as Strings] GCC provides three magic variables that hold the name of the current fun ...
- 设置view controller到iPhone或者iPad模式
在写iOS程序时,view controller的显示大小以及控件大小的调节是在是一个费力的事,尤其是对于用mac本的童鞋,更难驾驭,这时我们可以根据需要设置专门针对iphone或者ipad的view ...
- 【总结】前端框架:react还是vue?
之前写了一篇前端框架的大汇总,主要介绍了当下主流的框架和其特性.最近除了bootstrap,就属react和vue最为热门,这篇就主要拿这两个框架来做一下详细对比. 究竟如何正确使用?作为小白的我们从 ...
- 差分约束系统+输出路径(I - Advertisement POJ - 1752 )
题目链接:https://cn.vjudge.net/contest/276233#problem/I 题目大意:输入k和n,然后输入n行,每一次输入两个数,代表开端和结尾,如果这个区间内点的个数大于 ...
- 关于runOnUiThread()与Handler两种更新UI的方法
在Android开发过程中,常需要更新界面的UI.而更新UI是要主线程来更新的,即UI线程更新.如果在主线线程之外的线程中直接更新页面显示常会报错.抛出异常:android.view.ViewRoot ...
- XXX变种-防火墙放行自身
1.利用防火墙命令放行自身手法 netsh firewall add allowedprogram "C:\Users\USER\AppData\Local\Temp\Discord Can ...
- LINUX的DNS设置【转】
网卡DNS设置 用windos系统大家都知道,本地连接里面有一个DNS设置. 那么这个选项对应Linux系统的话就是在网卡配置文件,通过编辑vi /etc/sysconfig/network-scr ...