求调,Subtask#1 全WA

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

Motonic_queues @ 2024-08-08 07:58:31

rt

#include<bits/stdc++.h>
#define pl p<<1
#define pr p<<1|1
#define tp tr[p]
#define mid (l+r>>1)
#define int __int128
//#define double long double
#define pdi pair<double,int>
#define max(a,b) (a>b?a:b)
using namespace std;

const int N=100005;
const int MOD1=39989;
const int MOD2=1e9;
const int inf=0x3f3f3f3f;
const double eps=1e-9;

int n,lastans,cnt;

void read(int &res){res=0;char c=getchar();int f=1;while(c<48||c>57){if(c=='-')f=-1;c=getchar();}while(c>47&&c<58)res=(res<<3)+(res<<1)+(c^48),c=getchar();res*=f;}
void write(int a){if(!a){putchar('0');putchar('\n');return;}if(a<0){putchar('-');a=-a;}int l=0;char c[50];while(a){c[++l]=(a%10)^48;a/=10;}while(l)putchar(c[l--]);putchar('\n');}
struct segm{
    long double k,b;
    int s,e;
    long double operator()(long double x){
        if(s<=x&&x<=e)
            return k*x+b;
        return -inf;
    }
}ss[N+11];

int tr[4*MOD1];

int cmp(long double a,long double b){if(a-b>eps)return 1;if(b-a>eps)return -1;return 0;}

pdi _max(pdi a,pdi b){
    if(cmp(a.first,b.first)==1)return a;
    if(cmp(a.first,b.first)==-1)return b;
    return (a.second<b.second?a:b);
}

pdi ___max(pdi a,pdi b,pdi c){
    return _max(_max(a,b),c);
}

void update(int p,int l,int r,int L,int R,int id){
    if(l>R||r<L)return;
    if(L<=l&&r<=R){
        if(!tp)tp=id;
        int bmid=cmp(ss[tp](mid),ss[id](mid));
        if(bmid==-1||(bmid==0&&tp>id))swap(tp,id);
        int br=cmp(ss[tp](r),ss[id](r)),bl=cmp(ss[tp](l),ss[id](l));
        if(br==-1||(br==0&&tp>id))update(pr,mid+1,r,L,R,id);
        if(bl==-1||(bl==0&&tp>id))update(pr,l,mid,L,R,id);
        return;
    }
    if(L<=mid)update(pl,l,mid,L,R,id);
    if(R>mid)update(pr,mid+1,r,L,R,id);
}

void add(int a,int b,int c,int d){
    cnt++;
    if(a==c){
        ss[cnt].k=0,ss[cnt].b=max(max(b,d),0);
        ss[cnt].s=ss[cnt].e=a;
        update(1,1,MOD1,a,a,cnt);
    }else{
        ss[cnt].k=((1.0*b-d)/(1.0*a-c)),ss[cnt].b=(1.0*b-ss[cnt].k*a);
        ss[cnt].s=min(a,c);ss[cnt].e=max(a,c);
        update(1,1,MOD1,min(a,c),max(a,c),cnt);
    }
}

pdi query(int p,int x,int l,int r){
    //cout<<l<<' '<<mid<<' '<<r<<'\n';
    if(l>x||r<x)return {0,0};
    pdi res;
    if(tp)res={ss[tp](x),tp};
    if(l==r)return res;
    return ___max(res,query(pl,x,l,mid),query(pr,x,mid+1,r));
}

signed main(){
    //freopen("P4097_8.in","r",stdin);
    read(n);
    while(n--){
        int op,a,b,c,d;
        read(op);
        if(op){
            read(a);
            read(b);
            read(c);
            read(d);
            a=(a+lastans-1)%MOD1+1;
            c=(c+lastans-1)%MOD1+1;
            b=(b+lastans-1)%MOD2+1;
            d=(d+lastans-1)%MOD2+1;
            if(a>c){
                swap(a,c);swap(b,d);
            }
            add(a,b,c,d);
        }else{
            read(a);
            a=(a+lastans-1)%MOD1+1;
            write(lastans=query(1,a,1,MOD1).second);
        }
    }
    return 0;
}

by Motonic_queues @ 2024-08-08 17:05:16

牛逼,update把pl写成pr了
这个a样还能A掉sub0...


|