hdu Luck and Love 1823

hdu  1823


这题真恶心,用M究竟多大没有说,我的代码测试了好几组数据都对了,但是就是wa,后来改成c++就ac了,O__O"…,二维线段树不话可说,

#include <iostream>
#include <cstdio>

using namespace std;

struct Sub
{
    int l,r;
    double love;
};
struct Tree
{
    int l,r;
    Sub sub[4000];
}tree[800];

void init(int root,int rt,int l,int r)
{
    tree[root].sub[rt].love=-1;
    tree[root].sub[rt].l=l;
    tree[root].sub[rt].r=r;
    if(l==r) return;
    //cout<<l<<" "<<r<<endl;
    int m=(l+r)>>1;
    init(root,rt<<1,l,m);
    init(root,rt<<1|1,m+1,r);
}
void build(int rt,int l,int r,int ll,int rr)
{
    tree[rt].l=l,tree[rt].r=r;
    init(rt,1,ll,rr);
    if(l==r) return;
    //cout<<"bug"<<endl;
    int m=(l+r)/2;
    build(rt<<1,l,m,ll,rr);
    build(rt<<1|1,m+1,r,ll,rr);
}

void insert(int root,int rt,int act,double love)
{
    tree[root].sub[rt].love=max(tree[root].sub[rt].love,love);
    if(tree[root].sub[rt].l==tree[root].sub[rt].r)
    {
       //cout<<root<<" "<<rt<<endl;
        return;
    }
    int m=(tree[root].sub[rt].l+tree[root].sub[rt].r)>>1;
    if(act<=m) insert(root,rt<<1,act,love);
    else insert(root,rt<<1|1,act,love);
    tree[root].sub[rt].love=max(tree[root].sub[rt<<1].love,tree[root].sub[rt<<1|1].love);
    //cout<<tree[root].sub[rt].love<<endl;
}
void update(int rt,int height,int act,double love)
{
    insert(rt,1,act,love);
    if(tree[rt].l==tree[rt].r) return;
    int m=(tree[rt].l+tree[rt].r)>>1;
    if(height<=m) update(rt<<1,height,act,love);
    else update(rt<<1|1,height,act,love);
}

double answer(int root,int rt,int l,int r)
{
     if(l<=tree[root].sub[rt].l&&r>=tree[root].sub[rt].r)
     {
         return tree[root].sub[rt].love;
     }
     int m=(tree[root].sub[rt].l+tree[root].sub[rt].r)>>1;
     double ret1=-1,ret2=-1;
     if(l<=m) ret1=answer(root,rt<<1,l,r);
     if(r>m)  ret2=answer(root,rt<<1|1,l,r);
     return max(ret1,ret2);
}
double query(int rt,int l,int r,int ll,int rr)
{
    if(l<=tree[rt].l&&r>=tree[rt].r)
    {
        return answer(rt,1,ll,rr);
    }
    int m=(tree[rt].l+tree[rt].r)>>1;
    double ret1=-1,ret2=-1;
    //cout<<l<<" "<<m<<endl;
    if(l<=m) ret1=query(rt<<1,l,r,ll,rr);
    if(r>m)  ret2=query(rt<<1|1,l,r,ll,rr);
    return max(ret1,ret2);
}

int main()
{
    int m,height;
    double act,love;
    char ord[5];
    while(scanf("%d",&m)&&m)
    {
        build(1,100,200,0,1000);
        while(m--)
        {
            scanf("%s",ord);
            if(ord[0]=='I')
            {
                 scanf("%d %lf %lf",&height,&act,&love);
                 update(1,height,(int)(act*10),love);
            }
            else
            {
                 // cout<<tree[1].sub[1450].love<<endl;
                 int hl,hr;
                 double al,ar;
                 scanf("%d %d %lf %lf",&hl,&hr,&al,&ar);
                 if(hl>hr) swap(hl,hr);
                 if(al>ar) swap(al,ar);
                 double ans=query(1,hl,hr,(int)(al*10),(int)(ar*10));
                 if(ans==-1)  printf("-1\n");
                 else printf("%.1lf\n",ans);
            }
        }
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值