This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define all(a) a.begin(),a.end()
#define pb push_back
const int N=1010,mod=1e9+7;
int n,f[N][N],a[N],b[N],old[N],s[N][N],m;
vector<int> e;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
//freopen("BOAT.inp","r",stdin);
//freopen("BOAT.out","w",stdout);
cin>>n;
forinc(i,1,n)
{
cin>>a[i]>>b[i];
e.pb(a[i]);e.pb(b[i]);
}
e.erase(unique(all(e)),e.end());
m=e.size();
forinc(i,0,m-1)
{
old[i+1]=e[i];
a[i]=lower_bound(all(e),a[i])-e.begin()+1;
b[i]=lower_bound(all(e),b[i])-e.begin()+1;
}
old[m+1]=1e9;
f[0][0]=1;
forinc(j,0,m) s[0][j]=1;
forinc(i,1,n) forinc(j,0,m)
{
f[i][j]=(f[i][j]+f[i-1][j])%mod;
if(j>=a[i]&&j<=b[i])
{
int c=min(old[b[i]],old[j+1]-1);
f[i][j]=(f[i][j]+s[i-1][j-1]*(c-old[j]+1))%mod;
}
s[i][j]=s[i][j-1]+f[i][j];
}
cout<<s[n][m]-1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |