#include "bits/stdc++.h"
using namespace std;
#define ar array
const int mod = 1e9 + 7;
int bp(int a, int b){
int r=1;
while(b){
if(b&1) r = r * 1ll * a % mod;
a = a * 1ll * a % mod; b >>= 1;
} return r;
}
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n; cin>>n;
vector<int> a(2 * n), p(2 * n), og;
iota(p.begin(), p.end(), 0);
for(int i=0;i<n;i++){
cin>>a[i<<1]>>a[i<<1|1];
a[i<<1|1]++;
}
sort(p.begin(), p.end(), [&](int i, int j){
return (a[i] < a[j]);
});
int last=0;
for(int i=0, j=0;i<n+n;last++){
while(j<n+n && a[p[j]] == a[p[i]]) j++;
og.push_back(a[p[i]]);
while(i < j) a[p[i]] = last, i++;
}
vector<int> f(n + 1), inv(n + 1);
f[0] = inv[0] = 1;
for(int i=1;i<=n;i++){
f[i] = f[i-1] * 1ll * i % mod;
inv[i] = bp(f[i], mod - 2);
}
auto C = [&](int n, int k){
if(n < k) return 0ll;
return f[n] * 1ll * inv[k] % mod * inv[n - k] % mod;
};
vector<vector<int>> cnt(n + 1, vector<int>(last));
for(int c=1;c<=n;c++){
for(int k=0;k+1<last;k++){
int x = og[k+1] - og[k], f = x;
for(int j=0;j<c && j<x;j++){
cnt[c][k] = (cnt[c][k] + C(c - 1, j) * 1ll * f % mod * inv[j + 1]) % mod;
f = f * 1ll * (x - j - 1) % mod;
}
}
}
int res = 0;
vector<vector<int>> dp(n, vector<int>(last));
for(int i=0;i<n;i++){
int l = a[i<<1], r = a[i<<1|1];
for(int k=l;k<r;k++){
int c=1;
for(int j=i-1;~j;j--){
if(k){
dp[i][k] = (dp[i][k] + dp[j][k-1] * 1ll * cnt[c][k]) % mod;
}
if(a[j<<1] <= k && k < a[j<<1|1]) c++;
}
dp[i][k] = (dp[i][k] + cnt[c][k]) % mod;
res = (res + dp[i][k]) % mod;
if(k) dp[i][k] = (dp[i][k] + dp[i][k-1]) % mod;
}
}
cout<<res<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
635 ms |
4224 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
635 ms |
4224 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
635 ms |
4224 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |