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>
using namespace std;
#define int long long
#define in array<int, 2>
#define pb push_back
#define pob pop_back
#define INF (int)1e17
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL)
const int mod = 1e9+7;
const int MX = 5e3+5;
int dp[MX][2*MX];
int ans[2*MX];
signed main()
{
fast();
vector<int> v;
int n;
cin >> n;
n++;
vector<in> a(n+1);
for(int i = 1; i < n; i++)
{
cin >> a[i][0] >> a[i][1];
v.pb(a[i][0]); v.pb(++a[i][1]);
}
a[n][0] = 1e9+1; a[n][1] = 1e9+2;
v.pb(a[n][0]); v.pb(a[n][1]);
sort(v.begin(), v.end());
vector<int> CC; CC.pb(v[0]);
for(auto x: v)
{
if(x != CC.back())
CC.pb(x);
}
for(int i = 1; i <= n; i++)
{
a[i][0] = lower_bound(CC.begin(), CC.end(), a[i][0])-CC.begin();
a[i][1] = lower_bound(CC.begin(), CC.end(), a[i][1])-CC.begin();
}
int M = CC.size();
//We are interested in dp[n][MM]
for(int i = 1; i <= n; i++)
{
for(int j = a[i][0]; j < a[i][1]; j++)
{
dp[i][j] = 1;
for(int d = 0; d < j; d++)
{
dp[i][j]+=ans[d];
dp[i][j]%=mod;
}
dp[i][j]*=(CC[j+1]-CC[j]); dp[i][j]%=mod;
}
for(int j = a[i][0]; j < a[i][1]; j++)
{
ans[j]+=dp[i][j];
ans[j]%=mod;
}
}
dp[n][M-2]+=(mod-1); dp[n][M-2]%=mod;
cout << dp[n][M-2] << "\n";
return 0;
}
# | 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... |