李超线段树,sub1通过,sub2只通过第二个,求Hack或者帮调,谢大佬

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

anideahe @ 2022-11-18 14:40:14

#include<bits/stdc++.h>
#define db long double
#define int long long 
using namespace std;
template<typename T>
inline void read(T &x){
    x=0;char c=getchar();int f=1;
    for(;!isdigit(c);c=getchar())f=(c=='-')?-1:1;
    for(; isdigit(c);c=getchar())x=(x<<3)+(x<<1)+(c^48);
    x*=f;
}
const int N=1e5+10;
const int P=39989;
const int mod=1e9;
struct line{
    db k,b;int i;
    template<typename T> db f(T x){return k*(db)x+b;}
}t[N<<2];
#define mid ((l+r)>>1)
#define ls x<<1,l,mid
#define rs x<<1|1,mid+1,r
line max(line x,line y,int pos){ 
    if(x.f(pos)==y.f(pos)) return x.i<y.i?x:y;
    return x.f(pos)>y.f(pos)?x:y;
}
line query(int x,int l,int r,int pos){
    if(l==r) return t[x];
    line ans=t[x];
    if(pos<=mid) ans=max(ans,query(ls,pos),pos);
    if(pos> mid) ans=max(ans,query(rs,pos),pos);
    return ans;
}
void insert(int x,int l,int r,line p){
    double Mid=((db)l+(db)r)/2.0;
    if(p.f(Mid)>t[x].f(Mid)) swap(t[x],p);
    if(l==r) return ;
    if(p.f(l)>=t[x].f(l)) insert(ls,p);
    if(p.f(r)>=t[x].f(r)) insert(rs,p);
}
void modify(int x,int l,int r,int ql,int qr,line p){
    if(l>=ql&&r<=qr) return insert(x,l,r,p);
    if(ql<=mid) modify(ls,ql,qr,p);
    if(qr> mid) modify(rs,ql,qr,p);
}
int n,lastans,cnt;
inline int get(int x){return (x+lastans-1)%P+1;}
signed main(){
    read(n);
    for(int i=1;i<=n;i=-~i){
        int opt,k,xa,ya,xb,yb;
        read(opt);
        if(opt==0){
            read(k);k=get(k);
            printf("%lld\n",lastans=query(1,1,P,k).i);
        }
        if(opt==1){
            read(xa),read(ya),read(xb),read(yb);
            if(xa>xb) swap(xa,xb),swap(ya,yb);
            xa=get(xa),ya=(ya+lastans-1)%mod+1;
            xb=get(xb),yb=(yb+lastans-1)%mod+1;
            db K=(xa==xb)?0.0:((db)yb-(db)ya)/((db)xb-(db)xa),B=(db)ya-(db)xa*K;
            if(K==0.0) modify(1,1,P,xa,xb,(line){K,(db)yb,++cnt});
            else modify(1,1,P,xa,xb,(line){K,B,++cnt});
        }
    }
    return 0;
}

by youdu666 @ 2023-05-26 15:05:28

@anideahe 挖坟式回复:交换两个坐标应在解码后进行


|