求助李超树,本地和IDE跑出的结果不一致/kel

P4097 【模板】李超线段树 / [HEOI2013] Segment

樱雪喵 @ 2022-07-31 10:13:53

RT,本地可过第一个点,但在 IDE 上却 WA。(第七行,本地输出 16,IDE 输出 49)

感谢各位大佬帮忙,蒟蒻感激不尽/kel

#include<bits/stdc++.h>
#define ls (now<<1)
#define rs (now<<1|1) 
using namespace std;
typedef double db;
const int N=1e5+5; 
const db eps=1e-13;
int n,lastans=0,cnt;
int tr[N<<2],ans;
db maxn;
struct node{
    db k,b;
}a[N];
db gety(int id,db x){
    if(id==0) return 0;
    return a[id].k*x+a[id].b;
}
int readx(int x) {return (x+lastans-1)%39989+1;}
int ready(int x) {return (x+lastans-1)%1000000000+1;}
void modify(int now,int l,int r,int ml,int mr,int id)
{
    //cout<<now<<" "<<l<<" "<<r<<" "<<ml<<" "<<mr<<" "<<tr[now]<<endl;
    int mid=(l+r)>>1;
    if(l==ml&&r==mr)
    {
        int trw=tr[now];
        if(gety(id,mid)>gety(tr[now],mid)) tr[now]=id;
        if(gety(id,l)-gety(trw,l)>-eps&&gety(id,r)-gety(trw,r)>-eps) return;
        else if(gety(id,l)-gety(tr[now],l)<eps&&gety(id,r)-gety(tr[now],r)<eps) return;
        //if(gety(id,l)>=gety(trw,l)&&gety(id,r)>=gety(trw,r)) return;
        //else if(gety(id,l)<=gety(tr[now],l)&&gety(id,r)<=gety(tr[now],r)) return;
        else {modify(ls,l,mid,ml,mid,id);modify(rs,mid+1,r,mid+1,mr,id);}
    }
    if(mr<=mid) modify(ls,l,mid,ml,mr,id);
    else if(ml>mid) modify(rs,mid+1,r,ml,mr,id);
    else
    {
        modify(ls,l,mid,ml,mid,id);
        modify(rs,mid+1,r,mid+1,mr,id);
    }
    //cout<<now<<" "<<l<<" "<<r<<" "<<ml<<" "<<mr<<" "<<tr[now]<<endl;
}
void query(int now,int l,int r,int x)
{
    //cout<<now<<" "<<l<<" "<<r<<" "<<tr[now]<<endl;
    int mid=(l+r)>>1;
    //if(tr[now]>10) cout<<now<<" "<<tr[now]<<" "<<gety(tr[now],x)<<" ";
    if(gety(tr[now],x)>maxn||(gety(tr[now],x)==maxn&&tr[now]<ans)) ans=tr[now],maxn=gety(tr[now],x);
    if(l==r) return;
    if(x<=mid) query(ls,l,mid,x);
    else query(rs,mid+1,r,x);
}
int main()
{
    //freopen("P4097_1.in","r",stdin);
    scanf("%d",&n);
    for(int i=1,op,xa,ya,xb,yb;i<=n;i++) 
    {
        scanf("%d",&op);
        if(op==0)
        {
            scanf("%d",&xa);xa=readx(xa);
            maxn=0.0,ans=0;
            //cout<<xa<<endl;
            query(1,1,40000,xa);
            cout<<ans<<endl;
            lastans=ans;
        }
        else
        {
            scanf("%d%d%d%d",&xa,&ya,&xb,&yb);
            xa=readx(xa);xb=readx(xb);ya=ready(ya);yb=ready(yb);
            if(xa>xb) {swap(xa,xb);swap(ya,yb);}
            db k=0.0,b=0.0;
            if(xa==xb) k=0.0,b=yb;
            else 
            {
                k=(db)(yb-ya)/(db)(xb-xa);
                b=(db)yb-k*(db)xb;
            }
            a[++cnt]={k,b};
            modify(1,1,40000,xa,xb,cnt); 
        }
    }
    return 0;
}
/*
6
1 8 5 10 8
1 6 7 2 6
0 2
0 9
1 4 7 6 7
0 5
*/
/*
3
1 8 5 10 8
1 6 7 2 6
0 2
*/          

by 樱雪喵 @ 2022-07-31 11:50:14

没人吗/kk


by 红火恍惚cxy @ 2022-07-31 20:20:17

???您
这涉及到我的知识盲区了qwq


by 樱雪喵 @ 2022-07-31 21:40:51

问题已解决,modify 函数中若更新失败传参要把 trw 传下去而不是 id。


|