// 那就是希望。
// 即便需要取模,也是光明。
#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;
}
// 那就是希望。
// 即便需要取模,也是光明。
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 8.48 ms | 15 MB + 552 KB | Accepted | Score: 5 | 显示更多 |
Testcase #2 | 8.478 ms | 15 MB + 552 KB | Accepted | Score: 5 | 显示更多 |
Testcase #3 | 8.416 ms | 15 MB + 552 KB | Accepted | Score: 5 | 显示更多 |
Testcase #4 | 8.413 ms | 15 MB + 552 KB | Accepted | Score: 5 | 显示更多 |
Testcase #5 | 11.845 ms | 15 MB + 708 KB | Accepted | Score: 5 | 显示更多 |
Testcase #6 | 12.948 ms | 15 MB + 696 KB | Accepted | Score: 5 | 显示更多 |
Testcase #7 | 10.906 ms | 15 MB + 696 KB | Accepted | Score: 5 | 显示更多 |
Testcase #8 | 1.695 s | 20 MB + 224 KB | Accepted | Score: 5 | 显示更多 |
Testcase #9 | 1.335 s | 19 MB + 532 KB | Accepted | Score: 5 | 显示更多 |
Testcase #10 | 1.581 s | 20 MB + 192 KB | Accepted | Score: 5 | 显示更多 |
Testcase #11 | 8.526 ms | 15 MB + 632 KB | Accepted | Score: 5 | 显示更多 |
Testcase #12 | 8.637 ms | 15 MB + 656 KB | Accepted | Score: 5 | 显示更多 |
Testcase #13 | 19.952 ms | 15 MB + 720 KB | Accepted | Score: 5 | 显示更多 |
Testcase #14 | 19.64 ms | 15 MB + 708 KB | Accepted | Score: 5 | 显示更多 |
Testcase #15 | 17.104 ms | 15 MB + 684 KB | Accepted | Score: 5 | 显示更多 |
Testcase #16 | 268.029 ms | 16 MB + 812 KB | Accepted | Score: 5 | 显示更多 |
Testcase #17 | 299.376 ms | 16 MB + 796 KB | Accepted | Score: 5 | 显示更多 |
Testcase #18 | 667.988 ms | 17 MB + 824 KB | Accepted | Score: 5 | 显示更多 |
Testcase #19 | 721.041 ms | 18 MB | Accepted | Score: 5 | 显示更多 |
Testcase #20 | 2.431 s | 20 MB + 732 KB | Accepted | Score: 5 | 显示更多 |