提交记录 18740


用户 题目 状态 得分 用时 内存 语言 代码长度
myee noi19b. 【NOI2019】机器人 Accepted 100 2.431 s 21212 KB C++11 6.00 KB
提交时间 评测时间
2022-12-10 21:02:49 2022-12-10 21:03:11
// 那就是希望。
// 即便需要取模,也是光明。

#ifdef MYEE
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#endif

#include <algorithm>
#include <stdio.h>
#include <vector>
typedef long long llt;
typedef unsigned uint;typedef unsigned long long ullt;
typedef bool bol;typedef char chr;typedef void voi;
typedef double dbl;
template<typename T>bol _max(T&a,T b){return(a<b)?a=b,true:false;}
template<typename T>bol _min(T&a,T b){return(b<a)?a=b,true:false;}
template<typename T>T lowbit(T n){return n&-n;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T lcm(T a,T b){return(a!=0||b!=0)?a/gcd(a,b)*b:(T)0;}
template<typename T>T exgcd(T a,T b,T&x,T&y){if(b!=0){T ans=exgcd(b,a%b,y,x);y-=a/b*x;return ans;}else return y=0,x=1,a;}
template<typename T>T power(T base,T index,T mod)
{
    T ans=1%mod;
    while(index)
    {
        if(index&1)ans=ans*base%mod;
        base=base*base%mod,index>>=1;
    }
    return ans;
}
namespace ConstMod
{
    template<const ullt p>
    class mod_ullt
    {
        private:
            ullt v;
            inline ullt chg(ullt w){return(w<p)?w:w-p;}
            inline mod_ullt _chg(ullt w){mod_ullt ans;ans.v=(w<p)?w:w-p;return ans;}
        public:
            mod_ullt():v(0){}
            mod_ullt(ullt v):v(v%p){}
            bol empty(){return!v;}
            inline ullt val(){return v;}
            friend bol operator<(mod_ullt a,mod_ullt b){return a.v<b.v;}
            friend bol operator>(mod_ullt a,mod_ullt b){return a.v>b.v;}
            friend bol operator<=(mod_ullt a,mod_ullt b){return a.v<=b.v;}
            friend bol operator>=(mod_ullt a,mod_ullt b){return a.v>=b.v;}
            friend bol operator==(mod_ullt a,mod_ullt b){return a.v==b.v;}
            friend bol operator!=(mod_ullt a,mod_ullt b){return a.v!=b.v;}
            inline friend mod_ullt operator+(mod_ullt a,mod_ullt b){return a._chg(a.v+b.v);}
            inline friend mod_ullt operator-(mod_ullt a,mod_ullt b){return a._chg(a.v+a.chg(p-b.v));}
            inline friend mod_ullt operator*(mod_ullt a,mod_ullt b){return a.v*b.v;}
            friend mod_ullt operator/(mod_ullt a,mod_ullt b){return b._power(p-2)*a.v;}
            friend mod_ullt operator^(mod_ullt a,ullt b){return a._power(b);}
            inline mod_ullt operator-(){return _chg(p-v);}
            mod_ullt sqrt()
            {
                if(power(v,(p-1)>>1,p)!=1)return 0;
                mod_ullt b=1;do b++;while(b._power((p-1)>>1)==1);
                ullt t=p-1,s=0,k=1;while(!(t&1))s++,t>>=1;
                mod_ullt x=_power((t+1)>>1),e=_power(t);
                while(k<s)
                {
                    if(e._power(1llu<<(s-k-1))!=1)x*=b._power((1llu<<(k-1))*t);
                    e=_power(p-2)*x*x,k++;
                }
                return _min(x,-x),x;
            }
            mod_ullt inv(){return _power(p-2);}
            mod_ullt _power(ullt index){mod_ullt ans(1),w(v);while(index){if(index&1)ans*=w;w*=w,index>>=1;}return ans;}
            voi read(){v=0;chr c;do c=getchar();while(c>'9'||c<'0');do v=(c-'0'+v*10)%p,c=getchar();while(c>='0'&&c<='9');v%=p;}
            voi print()
            {
                static chr C[20];uint tp=0;
                ullt w=v;do C[tp++]=w%10+'0',w/=10;while(w);
                while(tp--)putchar(C[tp]);
            }
            voi println(){print(),putchar('\n');}
            mod_ullt operator++(int){mod_ullt ans=*this;return v=chg(v+1),ans;}
        public:
            inline ullt&operator()(){return v;}
            inline mod_ullt&operator+=(mod_ullt b){return*this=_chg(v+b.v);}
            inline mod_ullt&operator-=(mod_ullt b){return*this=_chg(v+chg(p-b.v));}
            inline mod_ullt&operator*=(mod_ullt b){return*this=v*b.v;}
            mod_ullt&operator^=(ullt b){return*this=_power(b);}
            mod_ullt&operator/=(mod_ullt b){return*this=b._power(p-2)*v;}
            mod_ullt&operator++(){return v=chg(v+1),*this;}
    };
}
const ullt Mod=1e9+7;
typedef ConstMod::mod_ullt<Mod>modint;
typedef std::vector<modint>modvec;
std::vector<std::pair<uint,std::pair<uint,uint> > >V[5005];
uint Id[305][305],tp=1;
uint Bgn[5005],End[5005];
uint dfs(uint l,uint r){
    if(l==r)return 0;
    if(~Id[l][r])return Id[l][r];
    Bgn[tp]=l,End[tp]=r,Id[l][r]=tp++;
    for(uint mid=l;mid<r;mid++)if(mid*2<=l+r+1&&mid*2+3>=l+r)
        V[Id[l][r]].push_back({mid,{dfs(l,mid),dfs(mid+1,r)}});
    return Id[l][r];
}
uint L[305],R[305];
std::vector<uint>Vp;
modvec Dp[5005];
uint Time[5005];
modint P[1000005],Q[1000005];
modint point(modvec&V,modint x,uint n){
    if(V.empty())return 0;
    if(x<V.size())return V[x()];
    modvec Suf;for(uint i=0;i<=n;i++)Suf.push_back(x-i);
    Suf.push_back(1);for(uint i=n+1;i;i--)Suf[i-1]*=Suf[i];
    modint ans,w(n&1?-modint(1):1);
    for(uint i=0;i<=n;i++)ans+=V[i]*w*Suf[i+1]*Q[n-i]*Q[i],w*=i-x;
    return ans;
}
uint n,id;
voi get(uint p){
    if(!p||Time[p]==id)return;
    modvec D(n+1);D[0]=point(Dp[p],Vp[id]-Vp[id-1]-1,End[p]-Bgn[p]);
    for(auto s:V[p]){
        uint a=s.first,l=s.second.first,r=s.second.second;get(l),get(r);
        if(Vp[id]<L[a]||Vp[id]>=R[a])continue;
        modvec D1=Dp[l],D2=Dp[r];
        D[0]+=D1[0]*point(D2,-modint(1),End[r]-Bgn[r]);
        for(uint i=1;i<=n;i++)D[i]+=D1[i]*D2[i-1];
    }
    for(uint i=1;i<=n;i++)D[i]+=D[i-1];
    Dp[p]=D,Time[p]=id;
}
int main()
{
#ifdef MYEE
    freopen("QAQ.in","r",stdin);
    // freopen("QAQ.out","w",stdout);
#endif
    P[0]=1;for(uint i=1;i<=1000000;i++)P[i]=P[i-1]*i;
    Q[1000000]=P[1000000].inv();for(uint i=1000000;i;i--)Q[i-1]=Q[i]*i;
    scanf("%u",&n);
    for(uint i=0;i<n;i++)scanf("%u%u",L+i,R+i),Vp.push_back(L[i]),Vp.push_back(++R[i]);
    for(uint i=0;i<n;i++)for(uint j=i;j<=n;j++)Id[i][j]=-1;
    Vp.push_back(0),std::sort(Vp.begin(),Vp.end());
    Vp.erase(std::unique(Vp.begin(),Vp.end()),Vp.end());
    dfs(0,n);for(uint i=0;i<tp;i++)Dp[i]={modvec(n+1,!i)};
    uint maxR=0;for(auto s:V[1])_max(maxR,R[s.first]);
    for(id=1;id<Vp.size()&&Vp[id]<=maxR;id++)get(1);
    Dp[1][0].println();
    return 0;
}

// 那就是希望。
// 即便需要取模,也是光明。

CompilationN/AN/ACompile OKScore: N/A

Testcase #18.48 ms15 MB + 552 KBAcceptedScore: 5

Testcase #28.478 ms15 MB + 552 KBAcceptedScore: 5

Testcase #38.416 ms15 MB + 552 KBAcceptedScore: 5

Testcase #48.413 ms15 MB + 552 KBAcceptedScore: 5

Testcase #511.845 ms15 MB + 708 KBAcceptedScore: 5

Testcase #612.948 ms15 MB + 696 KBAcceptedScore: 5

Testcase #710.906 ms15 MB + 696 KBAcceptedScore: 5

Testcase #81.695 s20 MB + 224 KBAcceptedScore: 5

Testcase #91.335 s19 MB + 532 KBAcceptedScore: 5

Testcase #101.581 s20 MB + 192 KBAcceptedScore: 5

Testcase #118.526 ms15 MB + 632 KBAcceptedScore: 5

Testcase #128.637 ms15 MB + 656 KBAcceptedScore: 5

Testcase #1319.952 ms15 MB + 720 KBAcceptedScore: 5

Testcase #1419.64 ms15 MB + 708 KBAcceptedScore: 5

Testcase #1517.104 ms15 MB + 684 KBAcceptedScore: 5

Testcase #16268.029 ms16 MB + 812 KBAcceptedScore: 5

Testcase #17299.376 ms16 MB + 796 KBAcceptedScore: 5

Testcase #18667.988 ms17 MB + 824 KBAcceptedScore: 5

Testcase #19721.041 ms18 MBAcceptedScore: 5

Testcase #202.431 s20 MB + 732 KBAcceptedScore: 5


Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 10:38:19 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠