李超线段树求调

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

wjh213 @ 2023-10-01 23:33:08

题解看的有些懵,按照自己的想法写的代码,码风比较奇怪,sub0都过了,sub1全wa,大数据调不出来了。

#include<bits/stdc++.h>
using namespace std;
#define int long long
int const MAX=1e7+10;
int const MAX2=4e6+10;
struct edge{
    int x1,x2,ind;
    double k,b;
}E[MAX];
double zhi(edge t1,int x){
    return t1.k*x+t1.b;
}
double zhi(int t1,int x){
    return E[t1].k*x+E[t1].b;
}
bool cmp(pair<int,double> t1,pair<int,double> t2){
    return abs(t1.second-t2.second)<1e-7?t1.first<t2.first:t1.second>t2.second;
}
struct tree{
    int a[MAX2*8];
    bool outrange(int l1,int r1,int l2,int r2){
        if(r1<l2||r2<l1)return true;
        return false;
    }
    void push(int t1,int ind=1,int l=1,int r=39989){
        if(l>r)return;
        //cout<<t1<<" ";
        int mid=(l+r)/2;
        if(outrange(E[t1].x1,E[t1].x2,l,r)){
            return;
        }
        else if(l<E[t1].x1||r>E[t1].x2){
            if(l==r)return;
            push(t1,ind*2,l,mid);
            push(t1,ind*2+1,mid+1,r);
        }else{
            //cout<<"a";
            if(a[ind]==0){
                //cout<<t1<<" "<<l<<" "<<r<<" ";
                a[ind]=t1;
                return;
            }
            if(zhi(t1,l)-zhi(a[ind],l)<-1e-6&&zhi(t1,r)-zhi(a[ind],r)<-1e-6){
                cout<<l<<" "<<r<<" "<<t1<<" \n";
                return;
            }else{
                cout<<l<<" "<<r<<" "<<t1<<" \n";
                if(zhi(t1,mid)-zhi(a[ind],mid)>1e-6){
                    swap(t1,a[ind]);

                }
                if(l==r)return;
                if(zhi(t1,l)-zhi(a[ind],l)>1e-6){
                    push(t1,ind*2,l,mid);
                }else if(zhi(t1,r)-zhi(a[ind],r)>1e-6){
                    push(t1,ind*2+1,mid+1,r);
                }else{
                    push(t1,ind*2,l,mid);push(t1,ind*2+1,mid+1,r);
                }
            }
        }
    }
    pair<int,double> find(int x,int ind=1,int l=1,int r=39989){
        //cout<<l<<" "<<r<<" "<<a[ind]<<" \n";
        pair<int,double> ans={0,-1e9};
        int mid=(l+r)/2;
        if(l<=x&&x<=r){
            //cout<<a[ind]<<" ";
            if(zhi(a[ind],x)>ans.second){
                ans.second=zhi(a[ind],x);
                ans.first=a[ind];
                //cout<<ans.first<<" ";
                //cout<<a[ind]<<" ";
            }else if(zhi(a[ind],x)==ans.second&&a[ind]<ans.first){
                ans.second=zhi(a[ind],x);
                ans.first=a[ind];
                //cout<<a[ind]<<" ";
            }
            if(l==r)return ans;
            //cout<<ans.first<<" ";
            //cout<<ans.first<<" ";
            pair<int,double> tp=find(x,ind*2,l,mid);
            //cout<<tp.first<<" ";
            if(cmp(tp,ans))ans=tp;
            tp=find(x,ind*2+1,mid+1,r);
            //cout<<tp.first<<" "<<ans.first<<" "<<abs(tp.second-ans.second)<<"\n ";
            if(cmp(tp,ans))ans=tp;
        }
        return ans;
    }
}T;
signed main(){
    int n;
    cin>>n;
    int lastans=0;
    int ji=0;
    for(int i=1;i<=n;i++){
        int op;
        cin>>op;
        if(op==0){
            int tp;
            cin>>tp;
            cout<<(lastans=T.find((tp+lastans-1)%39989+1).first)<<"\n";
        }else{
            int x00,y00,x01,y01;
            cin>>x00>>y00>>x01>>y01;
            x00=(x00+lastans-1)%39989+1;
            y00=(y00+lastans-1)%39989+1;
            x01=(x01+lastans-1)%(int)1e9+1;
            y01=(y01+lastans-1)%(int)1e9+1;
            if(x01<x00){
                swap(x01,x00);
                swap(y01,y00);
            }
            if(x00==x01){
                y00=y01=max(y00,y01);
                ji++;
                E[ji]=edge{x00,x01,ji,0,(double)y00};
                T.push(ji);
            }
            else{
                ji++;
                //cout<<y01<<" "<<y00<<"\n";
                //cout<<(y01-y00)*1.0/(x01-x00)*1.0<<" "<<y01-(y01-y00)*1.0/(x01-x00)*1.0*x01<<"\n";
                E[ji]=edge{x00,x01,ji,(y01-y00)*1.0/(x01-x00)*1.0,y01-(y01-y00)*1.0/(x01-x00)*1.0*x01};
                T.push(ji);
            }
        }
    }
    return 0;
}

by JROIer_chj @ 2024-02-02 20:21:39

你的模数打错了,怎么和我一样??


|