mxqz 李超线段树 Sub1全WA Sub2AC四个点

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

shyr @ 2022-10-05 16:46:53

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double db;
template<typename t> t &read(t &x){
    char c; int f=1;
    while(!isdigit(c=getchar())) if(c=='-') f=-1;
    x=c^'0';
    while(isdigit(c=getchar())) x=x*10+(c^'0');
    return x*=f;
}
int n, opt, lst, x1, yy, x2, y2, k, cnt;
int s[160005];
const db eps=1e-9;
struct seg{
    db k, b;
}d[100005];
const int mod=39989;
db cal(int id, int x){
    return (double)x*d[id].k+d[id].b;
}
void upd(int p, int l, int r, int u){
    int &q=s[p], mid=(l+r)>>1;
    if(cal(u,mid)>cal(q,mid)) swap(u, q);
    if(cal(u,l)>cal(q,l)) upd(p<<1,l,mid,u);
    if(cal(u,r)>cal(q,r)) upd(p<<1,mid+1,r,u);
}
void update(int p, int l, int r, int L, int R, int id){
    if(L<=l&&r<=R){
        upd(p, l, r, id);
        return ;
    }
    int mid=(l+r)/2;
    if(L<=mid) update(p<<1, l, mid, L, R, id);
    if(mid+1<=R) update(p<<1|1, mid+1, r, L, R, id);
}
pair<db,int> Max(pair<db,int> a, pair<db,int> b){
    if(abs(a.first-b.first)<=eps) return a.second<b.second?a:b;
    return a.first>b.first?a:b;
}
pair<db,int> query(int p, int l, int r, int k){
//  printf("%d %d %d %d %d %.6lf\n", p, l, r, k, s[p], cal(s[p], k));
    if(l==r){
        return {cal(s[p],k),s[p]};
    }
    int mid=(l+r)>>1;
    if(k<=mid) return Max({cal(s[p],k),s[p]},query(p<<1,l,mid,k));
    else return Max({cal(s[p],k),s[p]},query(p<<1|1,mid+1,r,k));
}
signed main(){
    read(n);
    while(n--){
        read(opt);
        if(opt){
            read(x1), read(yy); read(x2), read(y2);
            x1=(x1+lst-1+mod)%mod+1, x2=(x2+lst-1+mod)%mod+1;
            yy=(yy+lst-1+1000000000)%(1000000000)+1, y2=(y2+lst-1+1000000000)%(1000000000)+1;
            ++cnt;
            if(x1>x2) swap(x1,x2),swap(yy,y2);
            if(!(x2-x1)){
                d[cnt].k=0, d[cnt].b=max(yy,y2);
            }
            else{
                d[cnt].k=(y2-yy)*1.0/(x2-x1); d[cnt].b=y2-x2*d[cnt].k;
            }
            update(1, 1, mod, x1, x2, cnt);
        }
        else read(k),k=(k+lst-1+mod)%mod+1,printf("%d\n", lst=query(1,1,mod,k).second);
    }
}

by shyr @ 2022-10-05 16:58:55

改正:Sub0 AC 4个点


|