MnZn刚学李超树1e-18秒,爆0求调教

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

Da_Vinci @ 2024-08-08 20:10:39

3,5,6,7为ac,其他都为wa

//火车头比较长,正文在下面
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define ll long long
#define lll __int128
#define ull unsigned long long
#define ld long double
#define db double
#define gc getchar();
#define pc(x) putchar(x)
#define O(x) cout<<x<<'\n';
#define mkp make_pair

namespace constant_warrior
{
    template<typename T> inline void fr(T& num)
    {
        num=0;
        short sign=1;
        char ch=std::getchar();
        while(ch<'0'||ch>'9')
            {
                if(ch=='-')sign=-1;
                ch=std::getchar();
            }
        while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
        num=num*sign;
    }
    template<typename T>inline void fw(T x)
    {
        if(x<0)std::putchar('-'),x=-x;
        if(x>9)fw(x/10);
        std::putchar(x%10+'0');
    }
    template<typename T>inline const T& maxf(const T& a,const T& b)
    {
        if(a>b)return a;
        return b;
    }
    template<typename T>inline const T& minf(const T& a,const T& b)
    {
        if(a>b)return b;
        return a;
    }
    template<typename T>inline void swapf(T& a,T& b)
    {
        a^=b^=a^=b;
    }
}
using namespace constant_warrior;

//以下为正文
//以下为正文
//以下为正文

const int N=262144,M=1048576,K=1024,m1=39989,m2=1e9+1;
const ld eps=1e-9;
int n,lst;
struct str
{
    int X1,X2,Y1,Y2;
    inline ld cal(int x)
    {
        if(X1==X2)return maxf(Y1,Y2);
        ld res=1;
        res=res*X1*Y1/(X1+X2)+res*X2*Y2/(X1+X2);
        return res;
    }
} a[N];
inline int cmp(ld x,ld y)
{
    if(x-y>eps)return 1;
    if(y-x>eps)return -1;
    return 0;
}
inline pair<ld,int> pmax(const pair<ld,int> &x,const pair<ld,int> &y)
{
    switch(cmp(x.first,y.first))
        {
            case 1:
                return x;
            case -1:
                return y;
            default:
                {
                    return x.second<y.second?x:y;
                    break;
                }
        }

}
namespace seg
{
    int id[N<<2];
#define ls(p) p<<1
#define rs(p) p<<1|1

    void update(int p,int tl,int tr,int x)
    {
        int mid=(tl+tr)>>1,cmid=cmp(a[x].cal(mid),a[id[p]].cal(mid));
        if(cmid==1||(!cmid&&x<id[p]))swapf(x,id[p]);
        int cl=cmp(a[x].cal(tl),a[id[p]].cal(tl)),
            cr=cmp(a[x].cal(tr),a[id[p]].cal(tr));
        if(cl==1||(!cl&&x<id[p]))update(ls(p),cl,mid,x);
        if(cr==1||(!cr&&x<id[p]))update(rs(p),mid+1,cr,x);
    }
    void add(int p,int tl,int tr,int l,int r,int x)
    {
        if(l<=tl&&tr<=r)return update(p,tl,tr,x);
        int mid=(tl+tr)>>1;
        if(l<=mid)add(ls(p),tl,mid,l,r,x);
        if(mid<r)add(rs(p),mid+1,tr,l,r,x);
    }
    pair<ld,int> query(int p,int l,int r,int pos)
    {
        if(r<pos||pos<l)return mkp(0,0);
        int mid=(l+r)>>1;
        ld res=a[id[p]].cal(pos);
        if(l==r)return mkp(res,id[p]);
        return pmax(mkp(res,id[p]),
                    pmax(query(ls(p),l,mid,pos),query(rs(p),mid+1,r,pos)));
    }
}
inline void dec(int& x,int mod)
{
    x=(x+lst-1+mod)%mod+1;
}
int cnt;
void solve()
{
    fr(n);
    for(int i=1; i<=n; i++)
        {
            int op;
            fr(op);
            if(op)
                {
                    fr(a[++cnt].X1),fr(a[cnt].Y1),fr(a[cnt].X2),fr(a[cnt].Y2);
                    dec(a[cnt].X1,m1),dec(a[cnt].X2,m1),
                        dec(a[cnt].Y1,m2),dec(a[cnt].Y2,m2);
                    if(a[cnt].X1>a[cnt].X2)
                        swapf(a[cnt].X1,a[cnt].X2),swapf(a[cnt].Y1,a[cnt].Y2);
                    seg::add(1,1,m1,a[cnt].X1,a[cnt].X2,cnt);
                }
            else
                {
                    int x;
                    fr(x);
                    dec(x,m1);
                    fw(lst=seg::query(1,1,m1,x).second),pc('\n');
                }
        }
}
int main()
{
//  ios::sync_with_stdio(0);
//  cin.tie(0);cout.tie(0);
    int Count=1;//fr(Count);
    while(Count--)solve();
}
/*
暴力出奇迹,卡常能AC。
Violent makes miracle,pursuing better constant can AC.
多测不清空,OI见祖宗。
multitesting without clearing,oier meets the LCA.
十年OI一场空,不开LL见祖宗。
Ten years of OI just AFO,no #define int long long sees the LCA.
似是神犇成才处,实为蒟蒻黄泉路。
It is likely to be the Au medal for the big old,but in fact it is the Si medal for me.
黄题有恨无正解,码力不若小学生。
A yellow problem I can't AC,codeforces is not as NB as HNO3(Dilute nitric acid).
今生无奈入OI,来世不做信竞人。
This life I am a Siliy Being in oi,next life I won't f**k the sh*t of infomatics.
*/

by _Firefly__ @ 2024-08-10 18:26:12

哇dalao


by Da_Vinci @ 2024-10-05 20:20:34

已经重构。

此贴结。


by newtocpp @ 2024-11-19 12:12:21

哇dalao


|