CF678F Lena and Queries
题意
题目描述
time limit per test4 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Lena is a programmer. She got a task to solve at work.
There is an empty set of pairs of integers and n queries to process. Each query is one of three types:
Add a pair (a,b) to the set.
Remove a pair added in the query number i. All queries are numbered with integers from 1 to n.
For a given integer q find the maximal value x·q+y over all pairs (x,y) from the set.
Help Lena to process the queries.
输入输出格式
输入格式:
he first line of input contains integer n (1≤n≤3·105) — the number of queries.
Each of the next n lines starts with integer t (1≤t≤3) — the type of the query.
A pair of integers a and b (-109≤a,b≤109) follows in the query of the first type.
An integer i (1≤i≤n) follows in the query of the second type. It is guaranteed that i is less than the number of the query,
the query number i has the first type and the pair from the i-th query is not already removed.
An integer q (-109≤q≤109) follows in the query of the third type.
输出格式:
For the queries of the third type print on a separate line the desired maximal value of x·q+y.
If there are no pairs in the set print "EMPTY SET".
输入输出样例
输入样例#1:
7
3 1
1 2 3
3 1
1 -1 100
3 1
2 4
3 1
输出样例#1:
EMPTY SET
5
99
5
题目大意
莉娜是个程序员。她在工作中有一项任务要解决。
有一组空的整数对,n要处理的查询。每个查询都是三种类型中的一种:
1.加一对整数(a,b)。 2.删除在第i次操作所添加的整数对。所有查询都用整数编号从1到n。 3.对于给定的整数q 求最大值x*q+y 在所有整数对上(x,y)。 请你帮助莉娜处理查询。
输入 输入的第一行包含整数。n (1≤n≤3*10^5)-查询次数。
下一个n行以整数开头t (1≤t≤3)-查询的类型。
在t==1中接下来为一对整数a和b (-109≤a,b≤109)。
在t=2中接下来为整数i (1≤i≤n)保证i小于操作的数量
在t=3中接下来为整数q (-109≤q≤109)。
输出量 对于i==3输出当前最大的 x*q+y.
如果当前没有整数对,则输出"EMPTY SET".
Code
#include <bits/stdc++.h>
#define int long long
#define re register int
using namespace std;
inline void read(int &x){
x=0;char ch;bool f=0;
for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=getchar());
x=f?-x:x;
}
const int N=300010,fail=1e9+7,inf=2e18;
struct node{
int k,b;
node () { }
node(int x,int y){k=x,b=y;}
int f(int x){return k*x+b;}
bool operator < (node x) const {
return k!=x.k ? k<x.k : b<x.k;
}
}kk;
vector<node>T[N<<1];
int n,cnt,op[N][3],q[N][3];
inline void add(int L,int R,int k,int b,int l,int r){
re p=l+r|(l!=r),m=(l+r)>>1;
if(L<=l&&r<=R) {T[p].push_back(node(k,b));return;}
if(L<=m)add(L,R,k,b,l,m);
if(m<R) add(L,R,k,b,m+1,r);
}
inline int check(vector<node>& x,int i,int j,int k){
return ((x[i].b-x[j].b)*(x[k].k-x[i].k))>=(x[i].b-x[k].b)*(x[j].k-x[i].k);
}
inline void calc(vector<node>& x){
static int S[N],t,i;vector<node> tmp;
sort(x.begin(),x.end());
for(i=0,t=0;i<x.size();++i){
while(t && x[S[t]].k==x[i].k || t>1 && check(x,S[t-1],S[t],i)) --t;
S[++t]=i;
}
for(i=1;i<=t;++i) tmp.push_back(x[S[i]]);
x=tmp;
}
inline int get(int x,int p){
if(!T[p].size()) return -inf;
re l=0,r=T[p].size()-1,m;
while(l<r){
m=(l+r)>>1;
(T[p][m].f(x)>T[p][m+1].f(x))?r=m:l=m+1;
}
return T[p][l].f(x);
}
inline int ask(int x,int p,int l,int r){
re res=-inf;
while(l<r){
re id=(l+r)|(l!=r),m=(l+r)>>1;
res=max(res,get(x,id));
(p<=m)?r=m:l=m+1;
}
return res=max(res,get(x,(l+r)|(l!=r)));
}
signed main(){
read(n);
for(re x,i=1;i<=n;++i){
read(op[i][0]),read(op[i][1]);
if(op[i][0]==1)read(op[i][2]);
else if(op[i][0]==2){
x=op[i][1];
add(x,i,op[x][1],op[x][2],1,n);
op[x][1]=op[i][1]=fail;
}
else{
q[++cnt][1]=op[i][1];
q[cnt][2]=i,op[i][1]=fail;
}
}
for(re i=1;i<=n;++i)
if(op[i][1]!=fail)
add(i,n,op[i][1],op[i][2],1,n);
for(re i=1;i<=(n<<1);++i) if(T[i].size())calc(T[i]);
for(re res,i=1;i<=cnt;++i){
res=ask(q[i][1],q[i][2],1,n);
(res==-inf)?puts("EMPTY SET"):printf("%lld
",res);
}
return 0;
}