#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<cctype>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define fi first
#define se second
const int N=1e5+10;
const int M=5e5+10;
inline int read(){
int X=0,w=0;char ch=0;
while(!isdigit(ch)){w|=ch=='-';ch=getchar();}
while(isdigit(ch))X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
return w?-X:X;
}
vector<pii>a[N];
int t[N+M],q[M],lim,n,m;
char s[20];
struct node{
int l,r;
ll k,b;
node(int L=0,int R=0,ll K=0,ll B=0){
l=L,r=R,k=K,b=B;
}
ll point(int x){return k*x+b;}
}mx[(N+M)*4],mn[(N+M)*4];
inline int LSH(int x){
return lower_bound(t+1,t+lim+1,x)-t;
}
ll query(int a,int l,int r,int k){
ll a1=abs(mx[a].point(t[k])),a2=abs(mn[a].point(t[k]));
if(l==r)return max(a1,a2);
int mid=(l+r)>>1;ll ans;
if(k<=mid)ans=query(a<<1,l,mid,k);
else ans=query(a<<1|1,mid+1,r,k);
return max(ans,max(a1,a2));
}
void upt(int a,int l,int r,node k){
int mid=(l+r)>>1;
if(k.point(t[mid])>mx[a].point(t[mid]))swap(k,mx[a]);
if(l==r)return;
if(min(mx[a].point(t[l]),mx[a].point(t[r]))>=max(k.point(t[l]),k.point(t[r])))return;
if(mx[a].k>k.k)upt(a<<1,l,mid,k);
else upt(a<<1|1,mid+1,r,k);
}
void dwn(int a,int l,int r,node k){
int mid=(l+r)>>1;
if(k.point(t[mid])<mn[a].point(t[mid]))swap(k,mn[a]);
if(l==r)return;
if(max(mn[a].point(t[l]),mn[a].point(t[r]))<=min(k.point(t[l]),k.point(t[r])))return;
if(mn[a].k<=k.k)dwn(a<<1,l,mid,k);
else dwn(a<<1|1,mid+1,r,k);
}
void insert(int a,int l,int r,node k){
if(r<k.l||k.r<l)return;
if(k.l<=l&&r<=k.r){
upt(a,l,r,k);dwn(a,l,r,k);
return;
}
if(l==r)return;
int mid=(l+r)>>1;
insert(a<<1,l,mid,k);insert(a<<1|1,mid+1,r,k);
}
int main(){
n=read(),m=read();
for(int i=1;i<=n;i++)a[i].push_back(pii(0,read()));
t[++lim]=0;
for(int i=1;i<=m;i++){
int x=read();t[++lim]=x;scanf("%s",s);
if(s[0]=='c'){
int id=read(),v=read();
a[id].push_back(pii(x,v));
}else q[++q[0]]=x;
}
for(int i=1;i<=n;i++)a[i].push_back(pii(1e9,0));
t[++lim]=1e9;
sort(t+1,t+lim+1);
lim=unique(t+1,t+lim+1)-t;
for(int i=1;i<=n;i++){
int sz=a[i].size();
ll now=a[i][0].se;
node p=node(LSH(a[i][0].fi),LSH(a[i][1].fi),0,now);
insert(1,1,lim,p);
for(int j=1;j<sz-1;j++){
int l=a[i][j].fi,r=a[i][j+1].fi,k=a[i][j].se;
p=node(LSH(l),LSH(r),k,now-(ll)k*l);
insert(1,1,lim,p);
now=now+(ll)k*(r-l);
}
}
for(int i=1;i<=q[0];i++)
printf("%lld\n",query(1,1,lim,LSH(q[i])));
return 0;
}
13938:Robot
最新推荐文章于 2024-09-04 21:39:45 发布