李超线段树。
GTMD调了一下午。。。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 100500
#define eps 1e-8
#define inf 10000000
using namespace std;
long long n,x,tot=,root,ls[maxn<<],rs[maxn<<];
double s,p,b[maxn<<],k[maxn<<],ans=;
char type[];
bool flag[maxn<<];
void build(long long &now,long long left,long long right)
{
now=++tot;b[now]=k[now]=-inf;
if (left==right) return;
long long mid=(left+right)>>;
build(ls[now],left,mid);
build(rs[now],mid+,right);
}
double f (double s,int pos,double p)
{
return s+(double)(pos-)*p;
}
void modify(long long now,long long left,long long right,double s,double p)
{
double f1,f2,f3,f4;
if (!flag[now])
{
k[now]=p;b[now]=s;flag[now]=true;
return;
}
f1=s+(left-)*p;f2=b[now]+(double)(left-)*k[now];f3=s+(double)(right-)*p;f4=b[now]+(double)(right-)*k[now];
if ((f1<f2) && (f3<f4)) return;
if ((f1>f2) && (f3>f4)) {b[now]=s;k[now]=p;return;}
if (left==right) return;int mid=(left+right)>>;
double r1=f(s,mid,p),r2=f(b[now],mid,k[now]);
if (r1>r2) {swap(s,b[now]);swap(p,k[now]);}
if (!((r1<r2)^(f1>f2))) modify(ls[now],left,mid,s,p);
else modify(rs[now],mid+,right,s,p);
}
void ask(long long now,long long left,long long right,long long pos)
{
ans=max(ans,b[now]+(pos-)*k[now]);
if (left==right) return;
long long mid=(left+right)>>;
if (pos<=mid) ask(ls[now],left,mid,pos);
else ask(rs[now],mid+,right,pos);
}
int main()
{
scanf("%lld",&n);
build(root,,);
for (long long i=;i<=n;i++)
{
scanf("%s",type);
if (type[]=='P')
{
scanf("%lf%lf",&s,&p);
modify(root,,,s,p);
}
else
{
scanf("%lld",&x);ans=;
ask(root,,,x);
printf("%lld\n",(long long)(ans/+eps));
}
}
return ;
}