This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//In the name of God
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll maxn = 1024;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r+", stdin);freopen("output.txt", "w+", stdout);
#define pb push_back
#define Mp make_pair
#define F first
#define S second
#define Sz(x) ll((x).size())
#define all(x) (x).begin(), (x).end()
ll pw(ll a, ll b){
ll c = 1;
while(b){
if(b & 1) c = c * a % mod;
a = a * a % mod;
b >>= 1;
}
return c;
}
int n, a[maxn], b[maxn];
ll pre[maxn][maxn];
vector<int> vec;
vector<pll> g[maxn];
int main(){
fast_io;
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i] >> b[i];
b[i]++;
vec.pb(a[i]);
vec.pb(b[i]);
}
vec.pb(0);
sort(all(vec));
vec.resize(unique(all(vec)) - vec.begin());
for(int i = 0; i + 1 < Sz(vec); i++){
g[i].pb({0, 0});
int x = vec[i + 1] - vec[i] - 1;
pre[i][0] = 1;
for(int j = 1; j < maxn; j++){
pre[i][j] = pre[i][j - 1] * (x + j) % mod * pw(j, mod - 2) % mod;
}
}
g[0].pb({1, 1});
for(int i = 1; i <= n; i++){
ll x = 0;
for(int j = 0; j < Sz(vec) - 1; j++){
if(vec[j] < a[i] || b[i] <= vec[j]){
x = (x + g[j].back().S) % mod;
continue;
}
ll y = x * pre[j][1] % mod;
for(int k = 0; k < Sz(g[j]); k++){
y = (y + g[j][Sz(g[j]) - 1 - k].F * pre[j][k + 2]) % mod;
}
ll x2 = (x + g[j].back().S) % mod;
g[j].pb(Mp(x, y));
x = x2;
}
}
int ans = 0;
for(int i = 0; i < Sz(vec) - 1; i++){
ans += g[i].back().S;
if(ans >= mod) ans -= mod;
}
cout << (ans - 1 + mod) % mod << "\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... |