Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
33765 | LYLAKIOI | 【S】T2 | C++ | 运行超时 | 30 | 3000 MS | 1768 KB | 2083 | 2024-10-22 14:58:09 |
//100pts #include<bits/stdc++.h> #define up(i,l,r) for(int i=(l);i<=(r);++i) #define down(i,l,r) for(int i=(l);i>=(r);--i) #define pi pair<int,int> #define p1 first #define p2 second #define m_p make_pair #define p_b push_back using namespace std; typedef long long ll; const int maxn=1e6+10,mod=998244353; inline ll read(){ ll x=0;short t=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();} while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); return x*t; }int n,dp[505][1005],sdp[505][1005]; struct nd { int l,r; }d[505]; int P[1005],m; int qp(int a,int b){ int res=1; while(b){ if(b&1)res=res*1ll*a%mod; a=a*1ll*a%mod;b>>=1; }return res; } int C(int n,int m){ int s1=1,s2=1; up(i,m-n+1,m)s1=s1*1ll*i%mod; up(i,1,n)s2=s2*1ll*i%mod; return s1*1ll*qp(s2,mod-2)%mod; } int calc(int n,int m){ return C(m-1,n+m-1); } void slv(){ n=read(); up(i,1,n)d[i].l=read(),d[i].r=read(),P[++m]=d[i].l,P[++m]=d[i].r+1; reverse(d+1,d+n+1); sort(P+1,P+m+1); m=unique(P+1,P+m+1)-P-1; up(i,1,n)d[i].l=lower_bound(P+1,P+m+1,d[i].l)-P,d[i].r=lower_bound(P+1,P+m+1,d[i].r+1)-P; dp[0][0]=sdp[0][0]=1; up(i,1,m)sdp[0][i]=(sdp[0][i-1]+dp[0][i])%mod; up(i,1,n){ up(j,1,m-1){ bool ok=1; int len=P[j+1]-P[j]; if(d[i].l<=j&&j<d[i].r);else { sdp[i][j]=(sdp[i][j-1]+dp[i][j])%mod; continue; } down(k,i-1,0){ //up(x,0,j-1)(dp[i][j]+=dp[k][x]*1ll*calc(i-k,len)%mod)%=mod; (dp[i][j]+=sdp[k][j-1]*1ll*calc(i-k,len)%mod)%=mod; if(d[k].l<=j&&j<d[k].r);else ok=0; if(!ok)break; }sdp[i][j]=(sdp[i][j-1]+dp[i][j])%mod; } }int res=0; up(i,0,m-1)(res+=dp[n][i])%=mod; cout<<res; }int main(){ //freopen("array.in","r",stdin); //freopen("array.out","w",stdout); slv(); fclose(stdin); fclose(stdout); return 0; }