luogu2293 [JSOI2008]Blue Mary开公司

ref好像叫什么李超线段树?……这篇不是太通用……

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int n, T, uu;
double sa, sb;
const double eps=1e-7;
char ss[15];
struct SGT{
    double tagk[200005], tagx[200005];
    void update(int o, int l, int r, double k, double x){
        if(tagk[o]*l+tagx[o]<k*l+x && tagk[o]*r+tagx[o]<k*r+x){
            tagk[o] = k;
            tagx[o] = x;
        }
        else if(tagk[o]*l+tagx[o]<k*l+x || tagk[o]*r+tagx[o]<k*r+x){
            int mid=(l+r)>>1;
            int lson=o<<1;
            int rson=lson|1;
            update(lson, l, mid, k, x);
            update(rson, mid+1, r, k, x);
        }
    }
    double query(int o, int l, int r, int x){
        double re=x*tagk[o]+tagx[o];
        if(l==r)    return re;
        else{
            int mid=(l+r)>>1;
            int lson=o<<1;
            int rson=lson|1;
            if(x<=mid)  return max(re, query(lson, l, mid, x));
            else    return max(re, query(rson, mid+1, r, x));
        }
    }
}sgt;
int main(){
    cin>>n;
    while(n--){
        scanf("%s", ss);
        if(ss[0]=='P'){
            scanf("%lf %lf", &sa, &sb);
            sgt.update(1, 1, 50000, sb, sa-sb);
        }
        else{
            scanf("%d", &uu);
            printf("%d\n", (int)floor(sgt.query(1, 1, 50000, uu)/100));
        }
    }
    return 0;
}

转载于:https://www.cnblogs.com/poorpool/p/8891047.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值