#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
typedef pair<ll, int> ii;
const int mod = (int) 1e9 + 7;
const ll inf = 1LL << 60;
const int maxn = (int) 1005;
const ld eps = 1e-9;
void add(int &a, ll b) {
a += (b % mod);
while (a >= mod) a -= mod;
}
ll pw(ll a, int b) {
ll res = 1;
while (b) {
if(b & 1) res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
int n, m, a[maxn], b[maxn], sz[maxn];
int f[maxn][maxn], inv[maxn], C[maxn][maxn];
vector<int> p;
int main() {
//freopen("test.txt", "r", stdin);
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n;
rep(i, 1, n + 1) {
cin >> a[i] >> b[i];
b[i] ++;
p.pb(a[i]);
p.pb(b[i]);
inv[i] = pw(i, mod - 2);
}
p.pb(0);
sort(all(p));
p.resize(unique(all(p)) - p.begin());
rep(i, 1, n + 1) a[i] = lower_bound(all(p), a[i]) - p.begin();
rep(i, 1, n + 1) b[i] = lower_bound(all(p), b[i]) - p.begin();
m = SZ(p) - 2;
rep(i, 1, m + 1) sz[i] = p[i + 1] - p[i];
rep(i, 0, m + 1) f[0][i] = 1;
rep(i, 1, n + 1) {
rep(k, a[i], b[i]) {
ll cnt = 1, x = sz[k], y = 1;
per(j, 0, i) {
if(a[j + 1] <= k && k < b[j + 1]) {
cnt = ((cnt * x % mod) * inv[y]) % mod;
x ++, y ++;
}
add(f[i][k], cnt * f[j][k - 1]);
}
}
rep(j, 1, m + 1) add(f[i][j], f[i][j - 1]);
}
int ans = 0;
rep(i, 1, n + 1) add(ans, f[i][m]);
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
10088 KB |
Output is correct |
2 |
Correct |
6 ms |
10088 KB |
Output is correct |
3 |
Correct |
3 ms |
10088 KB |
Output is correct |
4 |
Correct |
3 ms |
10088 KB |
Output is correct |
5 |
Correct |
6 ms |
10088 KB |
Output is correct |
6 |
Correct |
6 ms |
10088 KB |
Output is correct |
7 |
Correct |
6 ms |
10088 KB |
Output is correct |
8 |
Correct |
6 ms |
10088 KB |
Output is correct |
9 |
Correct |
6 ms |
10088 KB |
Output is correct |
10 |
Correct |
6 ms |
10088 KB |
Output is correct |
11 |
Correct |
9 ms |
10088 KB |
Output is correct |
12 |
Correct |
6 ms |
10088 KB |
Output is correct |
13 |
Correct |
6 ms |
10088 KB |
Output is correct |
14 |
Correct |
6 ms |
10088 KB |
Output is correct |
15 |
Correct |
3 ms |
10088 KB |
Output is correct |
16 |
Correct |
3 ms |
10088 KB |
Output is correct |
17 |
Correct |
3 ms |
10088 KB |
Output is correct |
18 |
Correct |
3 ms |
10088 KB |
Output is correct |
19 |
Correct |
3 ms |
10088 KB |
Output is correct |
20 |
Correct |
3 ms |
10088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
10088 KB |
Output is correct |
2 |
Correct |
6 ms |
10088 KB |
Output is correct |
3 |
Correct |
3 ms |
10088 KB |
Output is correct |
4 |
Correct |
3 ms |
10088 KB |
Output is correct |
5 |
Correct |
6 ms |
10088 KB |
Output is correct |
6 |
Correct |
6 ms |
10088 KB |
Output is correct |
7 |
Correct |
6 ms |
10088 KB |
Output is correct |
8 |
Correct |
6 ms |
10088 KB |
Output is correct |
9 |
Correct |
6 ms |
10088 KB |
Output is correct |
10 |
Correct |
6 ms |
10088 KB |
Output is correct |
11 |
Correct |
9 ms |
10088 KB |
Output is correct |
12 |
Correct |
6 ms |
10088 KB |
Output is correct |
13 |
Correct |
6 ms |
10088 KB |
Output is correct |
14 |
Correct |
6 ms |
10088 KB |
Output is correct |
15 |
Correct |
3 ms |
10088 KB |
Output is correct |
16 |
Correct |
3 ms |
10088 KB |
Output is correct |
17 |
Correct |
3 ms |
10088 KB |
Output is correct |
18 |
Correct |
3 ms |
10088 KB |
Output is correct |
19 |
Correct |
3 ms |
10088 KB |
Output is correct |
20 |
Correct |
3 ms |
10088 KB |
Output is correct |
21 |
Correct |
699 ms |
10088 KB |
Output is correct |
22 |
Correct |
673 ms |
10088 KB |
Output is correct |
23 |
Correct |
633 ms |
10088 KB |
Output is correct |
24 |
Correct |
653 ms |
10088 KB |
Output is correct |
25 |
Correct |
666 ms |
10088 KB |
Output is correct |
26 |
Correct |
946 ms |
10088 KB |
Output is correct |
27 |
Correct |
966 ms |
10088 KB |
Output is correct |
28 |
Correct |
923 ms |
10088 KB |
Output is correct |
29 |
Correct |
926 ms |
10088 KB |
Output is correct |
30 |
Correct |
13 ms |
10088 KB |
Output is correct |
31 |
Correct |
13 ms |
10088 KB |
Output is correct |
32 |
Correct |
13 ms |
10088 KB |
Output is correct |
33 |
Correct |
9 ms |
10088 KB |
Output is correct |
34 |
Correct |
13 ms |
10088 KB |
Output is correct |
35 |
Correct |
6 ms |
10088 KB |
Output is correct |
36 |
Correct |
9 ms |
10088 KB |
Output is correct |
37 |
Correct |
13 ms |
10088 KB |
Output is correct |
38 |
Correct |
9 ms |
10088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
10088 KB |
Output is correct |
2 |
Correct |
3 ms |
10088 KB |
Output is correct |
3 |
Correct |
3 ms |
10088 KB |
Output is correct |
4 |
Correct |
6 ms |
10088 KB |
Output is correct |
5 |
Correct |
6 ms |
10088 KB |
Output is correct |
6 |
Correct |
6 ms |
10088 KB |
Output is correct |
7 |
Correct |
6 ms |
10088 KB |
Output is correct |
8 |
Correct |
6 ms |
10088 KB |
Output is correct |
9 |
Correct |
6 ms |
10088 KB |
Output is correct |
10 |
Correct |
9 ms |
10088 KB |
Output is correct |
11 |
Correct |
3 ms |
10088 KB |
Output is correct |
12 |
Correct |
3 ms |
10088 KB |
Output is correct |
13 |
Correct |
3 ms |
10088 KB |
Output is correct |
14 |
Correct |
3 ms |
10088 KB |
Output is correct |
15 |
Correct |
3 ms |
10088 KB |
Output is correct |
16 |
Correct |
3 ms |
10088 KB |
Output is correct |
17 |
Correct |
3 ms |
10088 KB |
Output is correct |
18 |
Correct |
3 ms |
10088 KB |
Output is correct |
19 |
Correct |
3 ms |
10088 KB |
Output is correct |
20 |
Correct |
3 ms |
10088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
10088 KB |
Output is correct |
2 |
Correct |
6 ms |
10088 KB |
Output is correct |
3 |
Correct |
3 ms |
10088 KB |
Output is correct |
4 |
Correct |
3 ms |
10088 KB |
Output is correct |
5 |
Correct |
6 ms |
10088 KB |
Output is correct |
6 |
Correct |
6 ms |
10088 KB |
Output is correct |
7 |
Correct |
6 ms |
10088 KB |
Output is correct |
8 |
Correct |
6 ms |
10088 KB |
Output is correct |
9 |
Correct |
6 ms |
10088 KB |
Output is correct |
10 |
Correct |
6 ms |
10088 KB |
Output is correct |
11 |
Correct |
9 ms |
10088 KB |
Output is correct |
12 |
Correct |
6 ms |
10088 KB |
Output is correct |
13 |
Correct |
6 ms |
10088 KB |
Output is correct |
14 |
Correct |
6 ms |
10088 KB |
Output is correct |
15 |
Correct |
3 ms |
10088 KB |
Output is correct |
16 |
Correct |
3 ms |
10088 KB |
Output is correct |
17 |
Correct |
3 ms |
10088 KB |
Output is correct |
18 |
Correct |
3 ms |
10088 KB |
Output is correct |
19 |
Correct |
3 ms |
10088 KB |
Output is correct |
20 |
Correct |
3 ms |
10088 KB |
Output is correct |
21 |
Correct |
699 ms |
10088 KB |
Output is correct |
22 |
Correct |
673 ms |
10088 KB |
Output is correct |
23 |
Correct |
633 ms |
10088 KB |
Output is correct |
24 |
Correct |
653 ms |
10088 KB |
Output is correct |
25 |
Correct |
666 ms |
10088 KB |
Output is correct |
26 |
Correct |
946 ms |
10088 KB |
Output is correct |
27 |
Correct |
966 ms |
10088 KB |
Output is correct |
28 |
Correct |
923 ms |
10088 KB |
Output is correct |
29 |
Correct |
926 ms |
10088 KB |
Output is correct |
30 |
Correct |
13 ms |
10088 KB |
Output is correct |
31 |
Correct |
13 ms |
10088 KB |
Output is correct |
32 |
Correct |
13 ms |
10088 KB |
Output is correct |
33 |
Correct |
9 ms |
10088 KB |
Output is correct |
34 |
Correct |
13 ms |
10088 KB |
Output is correct |
35 |
Correct |
6 ms |
10088 KB |
Output is correct |
36 |
Correct |
9 ms |
10088 KB |
Output is correct |
37 |
Correct |
13 ms |
10088 KB |
Output is correct |
38 |
Correct |
9 ms |
10088 KB |
Output is correct |
39 |
Correct |
6 ms |
10088 KB |
Output is correct |
40 |
Correct |
3 ms |
10088 KB |
Output is correct |
41 |
Correct |
3 ms |
10088 KB |
Output is correct |
42 |
Correct |
6 ms |
10088 KB |
Output is correct |
43 |
Correct |
6 ms |
10088 KB |
Output is correct |
44 |
Correct |
6 ms |
10088 KB |
Output is correct |
45 |
Correct |
6 ms |
10088 KB |
Output is correct |
46 |
Correct |
6 ms |
10088 KB |
Output is correct |
47 |
Correct |
6 ms |
10088 KB |
Output is correct |
48 |
Correct |
9 ms |
10088 KB |
Output is correct |
49 |
Correct |
3 ms |
10088 KB |
Output is correct |
50 |
Correct |
3 ms |
10088 KB |
Output is correct |
51 |
Correct |
3 ms |
10088 KB |
Output is correct |
52 |
Correct |
3 ms |
10088 KB |
Output is correct |
53 |
Correct |
3 ms |
10088 KB |
Output is correct |
54 |
Correct |
3 ms |
10088 KB |
Output is correct |
55 |
Correct |
3 ms |
10088 KB |
Output is correct |
56 |
Correct |
3 ms |
10088 KB |
Output is correct |
57 |
Correct |
3 ms |
10088 KB |
Output is correct |
58 |
Correct |
3 ms |
10088 KB |
Output is correct |
59 |
Correct |
746 ms |
10088 KB |
Output is correct |
60 |
Correct |
723 ms |
10088 KB |
Output is correct |
61 |
Correct |
646 ms |
10088 KB |
Output is correct |
62 |
Correct |
743 ms |
10088 KB |
Output is correct |
63 |
Correct |
753 ms |
10088 KB |
Output is correct |
64 |
Correct |
1073 ms |
10088 KB |
Output is correct |
65 |
Correct |
1069 ms |
10088 KB |
Output is correct |
66 |
Correct |
1059 ms |
10088 KB |
Output is correct |
67 |
Correct |
1069 ms |
10088 KB |
Output is correct |
68 |
Correct |
1076 ms |
10088 KB |
Output is correct |
69 |
Correct |
589 ms |
10088 KB |
Output is correct |
70 |
Correct |
576 ms |
10088 KB |
Output is correct |
71 |
Correct |
569 ms |
10088 KB |
Output is correct |
72 |
Correct |
606 ms |
10088 KB |
Output is correct |
73 |
Correct |
609 ms |
10088 KB |
Output is correct |
74 |
Correct |
139 ms |
10088 KB |
Output is correct |
75 |
Correct |
126 ms |
10088 KB |
Output is correct |
76 |
Correct |
136 ms |
10088 KB |
Output is correct |
77 |
Correct |
133 ms |
10088 KB |
Output is correct |
78 |
Correct |
149 ms |
10088 KB |
Output is correct |