#include<bits/stdc++.h>
#define lc x<<1,l,mid
#define rc x<<1|1,mid+1,r
using namespace std;
const double eps=1e-12;
const int N=50010;
struct Line
{
double k,b;
int l,r;
int flag;
}tr[N*4];
double calc(Line line,int x)
{
return line.k*x+line.b;
}
int cross(Line l1,Line l2)
{
return floor((l1.b-l2.b)/(l2.k-l1.k));
}
void build(int x,int l,int r)
{
tr[x]=(Line){0, 0, 1, 50000, false};//?
if(l==r) return ;
int mid=l+r>>1;
build(lc);
build(rc);
}
void modify(int x,int l,int r,Line k)
{
if(k.l<=l && r<=k.r)
{
if(!tr[x].flag)
{
tr[x]=k;
tr[x].flag=true;
}
else if(calc(k,l)-calc(tr[x],l)>eps && calc(k,r)-calc(tr[x],r)>eps)
{
tr[x]=k;
}
else if(calc(k,l)-calc(tr[x],l)>eps || calc(k,r)-calc(tr[x],r)>eps)
{
int mid=l+r>>1;
if(calc(k,mid)-calc(tr[x],mid)>eps) swap(k,tr[x]);
if(cross(k,tr[x])<=mid) modify(lc,k);
else modify(rc,k);
}
}
else
{
int mid=l+r>>1;
if(k.l<=mid) modify(lc,k);
if(mid<k.r) modify(rc,k);
// if(mid<=k.r) modify(lc,k);
// if(k.l<mid) modify(rc,k);
}
}
double query(int x,int l,int r,int pos)
{
if(l==r) return calc(tr[x],pos);//?
int mid=l+r>>1;
double ans=calc(tr[x],pos);
if(pos<=mid) return max(ans,query(lc,pos));
else return max(ans,query(rc,pos));
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n;cin>>n;
const int root=1;
// build(root, 1, 50000);
for(int i=1;i<=n;i++)
{
string opt;cin>>opt;
if(opt[0]=='P')
{
Line now;
cin>>now.b>>now.k;
now.b=now.b-now.k;
now.l=1;now.r=50000;
modify(root, 1, 50000, now);
}
else
{
int day;
cin>>day;
double ans=query(root, 1, 50000, day);
cout<<floor(ans/100)<<endl;
}
}
return 0;
}
李超线段树—板子
最新推荐文章于 2024-06-15 15:45:58 发布