题目:
题解:
这绝对是我见过最敷衍的输出样例
可以发现这都是递增的一次函数
那么每次修改的时候我们都分三种情况:两端都大于(修改走人),两端都小于(走人),递归解决问题
代码:
#include <cstdio>
#include <iostream>
using namespace std;
const int N=50005;
struct hh{double s,p;}t[N*4];
double ans=0;
double Y(int x,double s,double p){return x*p+s;}
void change(int now,int l,int r,double s,double p)
{
double yl=Y(l,t[now].s,t[now].p),nl=Y(l,s,p);
double yr=Y(r,t[now].s,t[now].p),nr=Y(r,s,p);
if (yl>=nl && yr>=nr) return;
if (nl>=yl && nr>=yr){t[now].s=s;t[now].p=p;return;}
int mid=(l+r)>>1;
change(now<<1,l,mid,s,p);
change(now<<1|1,mid+1,r,s,p);
}
void qurry(int now,int l,int r,int x)
{
ans=max(ans,t[now].s+t[now].p*x);
if (l==r) return;
int mid=(l+r)>>1;
if (x<=mid) qurry(now<<1,l,mid,x);
else qurry(now<<1|1,mid+1,r,x);
}
int main()
{
int n;scanf("%d",&n);int T=50000;
for (int i=1;i<=n;i++)
{
char st[10];scanf("%s",st);int x;double s,p;
if (st[0]=='Q')
{
scanf("%d",&x);ans=0;
qurry(1,1,T,x);
printf("%d\n",(int)(ans/100));
}
else
{
scanf("%lf%lf",&s,&p);s-=p;
change(1,1,T,s,p);
}
}
}