#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
2304 KB |
Output is correct |
2 |
Correct |
8 ms |
2304 KB |
Output is correct |
3 |
Correct |
8 ms |
2304 KB |
Output is correct |
4 |
Correct |
7 ms |
2304 KB |
Output is correct |
5 |
Correct |
8 ms |
2304 KB |
Output is correct |
6 |
Correct |
7 ms |
2304 KB |
Output is correct |
7 |
Correct |
7 ms |
2304 KB |
Output is correct |
8 |
Correct |
8 ms |
2304 KB |
Output is correct |
9 |
Correct |
7 ms |
2304 KB |
Output is correct |
10 |
Correct |
7 ms |
2304 KB |
Output is correct |
11 |
Correct |
7 ms |
2304 KB |
Output is correct |
12 |
Correct |
7 ms |
2304 KB |
Output is correct |
13 |
Correct |
7 ms |
2304 KB |
Output is correct |
14 |
Correct |
7 ms |
2304 KB |
Output is correct |
15 |
Correct |
7 ms |
2304 KB |
Output is correct |
16 |
Correct |
4 ms |
2304 KB |
Output is correct |
17 |
Correct |
4 ms |
2304 KB |
Output is correct |
18 |
Correct |
4 ms |
2304 KB |
Output is correct |
19 |
Correct |
4 ms |
2304 KB |
Output is correct |
20 |
Correct |
4 ms |
2304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
2304 KB |
Output is correct |
2 |
Correct |
8 ms |
2304 KB |
Output is correct |
3 |
Correct |
8 ms |
2304 KB |
Output is correct |
4 |
Correct |
7 ms |
2304 KB |
Output is correct |
5 |
Correct |
8 ms |
2304 KB |
Output is correct |
6 |
Correct |
7 ms |
2304 KB |
Output is correct |
7 |
Correct |
7 ms |
2304 KB |
Output is correct |
8 |
Correct |
8 ms |
2304 KB |
Output is correct |
9 |
Correct |
7 ms |
2304 KB |
Output is correct |
10 |
Correct |
7 ms |
2304 KB |
Output is correct |
11 |
Correct |
7 ms |
2304 KB |
Output is correct |
12 |
Correct |
7 ms |
2304 KB |
Output is correct |
13 |
Correct |
7 ms |
2304 KB |
Output is correct |
14 |
Correct |
7 ms |
2304 KB |
Output is correct |
15 |
Correct |
7 ms |
2304 KB |
Output is correct |
16 |
Correct |
4 ms |
2304 KB |
Output is correct |
17 |
Correct |
4 ms |
2304 KB |
Output is correct |
18 |
Correct |
4 ms |
2304 KB |
Output is correct |
19 |
Correct |
4 ms |
2304 KB |
Output is correct |
20 |
Correct |
4 ms |
2304 KB |
Output is correct |
21 |
Correct |
576 ms |
2384 KB |
Output is correct |
22 |
Correct |
547 ms |
2316 KB |
Output is correct |
23 |
Correct |
507 ms |
2280 KB |
Output is correct |
24 |
Correct |
539 ms |
2288 KB |
Output is correct |
25 |
Correct |
531 ms |
2304 KB |
Output is correct |
26 |
Correct |
805 ms |
2296 KB |
Output is correct |
27 |
Correct |
796 ms |
2388 KB |
Output is correct |
28 |
Correct |
809 ms |
2324 KB |
Output is correct |
29 |
Correct |
780 ms |
2300 KB |
Output is correct |
30 |
Correct |
10 ms |
2304 KB |
Output is correct |
31 |
Correct |
10 ms |
2304 KB |
Output is correct |
32 |
Correct |
10 ms |
2304 KB |
Output is correct |
33 |
Correct |
10 ms |
2304 KB |
Output is correct |
34 |
Correct |
10 ms |
2432 KB |
Output is correct |
35 |
Correct |
11 ms |
2304 KB |
Output is correct |
36 |
Correct |
9 ms |
2304 KB |
Output is correct |
37 |
Correct |
10 ms |
2304 KB |
Output is correct |
38 |
Correct |
10 ms |
2304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
800 KB |
Output is correct |
2 |
Correct |
5 ms |
768 KB |
Output is correct |
3 |
Correct |
5 ms |
768 KB |
Output is correct |
4 |
Correct |
8 ms |
768 KB |
Output is correct |
5 |
Correct |
6 ms |
768 KB |
Output is correct |
6 |
Correct |
9 ms |
768 KB |
Output is correct |
7 |
Correct |
8 ms |
768 KB |
Output is correct |
8 |
Correct |
9 ms |
728 KB |
Output is correct |
9 |
Correct |
9 ms |
768 KB |
Output is correct |
10 |
Correct |
8 ms |
768 KB |
Output is correct |
11 |
Correct |
5 ms |
768 KB |
Output is correct |
12 |
Correct |
4 ms |
768 KB |
Output is correct |
13 |
Correct |
5 ms |
768 KB |
Output is correct |
14 |
Correct |
6 ms |
768 KB |
Output is correct |
15 |
Correct |
5 ms |
768 KB |
Output is correct |
16 |
Correct |
4 ms |
768 KB |
Output is correct |
17 |
Correct |
4 ms |
768 KB |
Output is correct |
18 |
Correct |
4 ms |
768 KB |
Output is correct |
19 |
Correct |
3 ms |
768 KB |
Output is correct |
20 |
Correct |
4 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
2304 KB |
Output is correct |
2 |
Correct |
8 ms |
2304 KB |
Output is correct |
3 |
Correct |
8 ms |
2304 KB |
Output is correct |
4 |
Correct |
7 ms |
2304 KB |
Output is correct |
5 |
Correct |
8 ms |
2304 KB |
Output is correct |
6 |
Correct |
7 ms |
2304 KB |
Output is correct |
7 |
Correct |
7 ms |
2304 KB |
Output is correct |
8 |
Correct |
8 ms |
2304 KB |
Output is correct |
9 |
Correct |
7 ms |
2304 KB |
Output is correct |
10 |
Correct |
7 ms |
2304 KB |
Output is correct |
11 |
Correct |
7 ms |
2304 KB |
Output is correct |
12 |
Correct |
7 ms |
2304 KB |
Output is correct |
13 |
Correct |
7 ms |
2304 KB |
Output is correct |
14 |
Correct |
7 ms |
2304 KB |
Output is correct |
15 |
Correct |
7 ms |
2304 KB |
Output is correct |
16 |
Correct |
4 ms |
2304 KB |
Output is correct |
17 |
Correct |
4 ms |
2304 KB |
Output is correct |
18 |
Correct |
4 ms |
2304 KB |
Output is correct |
19 |
Correct |
4 ms |
2304 KB |
Output is correct |
20 |
Correct |
4 ms |
2304 KB |
Output is correct |
21 |
Correct |
576 ms |
2384 KB |
Output is correct |
22 |
Correct |
547 ms |
2316 KB |
Output is correct |
23 |
Correct |
507 ms |
2280 KB |
Output is correct |
24 |
Correct |
539 ms |
2288 KB |
Output is correct |
25 |
Correct |
531 ms |
2304 KB |
Output is correct |
26 |
Correct |
805 ms |
2296 KB |
Output is correct |
27 |
Correct |
796 ms |
2388 KB |
Output is correct |
28 |
Correct |
809 ms |
2324 KB |
Output is correct |
29 |
Correct |
780 ms |
2300 KB |
Output is correct |
30 |
Correct |
10 ms |
2304 KB |
Output is correct |
31 |
Correct |
10 ms |
2304 KB |
Output is correct |
32 |
Correct |
10 ms |
2304 KB |
Output is correct |
33 |
Correct |
10 ms |
2304 KB |
Output is correct |
34 |
Correct |
10 ms |
2432 KB |
Output is correct |
35 |
Correct |
11 ms |
2304 KB |
Output is correct |
36 |
Correct |
9 ms |
2304 KB |
Output is correct |
37 |
Correct |
10 ms |
2304 KB |
Output is correct |
38 |
Correct |
10 ms |
2304 KB |
Output is correct |
39 |
Correct |
7 ms |
800 KB |
Output is correct |
40 |
Correct |
5 ms |
768 KB |
Output is correct |
41 |
Correct |
5 ms |
768 KB |
Output is correct |
42 |
Correct |
8 ms |
768 KB |
Output is correct |
43 |
Correct |
6 ms |
768 KB |
Output is correct |
44 |
Correct |
9 ms |
768 KB |
Output is correct |
45 |
Correct |
8 ms |
768 KB |
Output is correct |
46 |
Correct |
9 ms |
728 KB |
Output is correct |
47 |
Correct |
9 ms |
768 KB |
Output is correct |
48 |
Correct |
8 ms |
768 KB |
Output is correct |
49 |
Correct |
5 ms |
768 KB |
Output is correct |
50 |
Correct |
4 ms |
768 KB |
Output is correct |
51 |
Correct |
5 ms |
768 KB |
Output is correct |
52 |
Correct |
6 ms |
768 KB |
Output is correct |
53 |
Correct |
5 ms |
768 KB |
Output is correct |
54 |
Correct |
4 ms |
768 KB |
Output is correct |
55 |
Correct |
4 ms |
768 KB |
Output is correct |
56 |
Correct |
4 ms |
768 KB |
Output is correct |
57 |
Correct |
3 ms |
768 KB |
Output is correct |
58 |
Correct |
4 ms |
768 KB |
Output is correct |
59 |
Correct |
609 ms |
2316 KB |
Output is correct |
60 |
Correct |
568 ms |
2436 KB |
Output is correct |
61 |
Correct |
540 ms |
2552 KB |
Output is correct |
62 |
Correct |
621 ms |
2360 KB |
Output is correct |
63 |
Correct |
583 ms |
2296 KB |
Output is correct |
64 |
Correct |
911 ms |
2460 KB |
Output is correct |
65 |
Correct |
940 ms |
2424 KB |
Output is correct |
66 |
Correct |
911 ms |
2468 KB |
Output is correct |
67 |
Correct |
908 ms |
2296 KB |
Output is correct |
68 |
Correct |
911 ms |
2464 KB |
Output is correct |
69 |
Correct |
530 ms |
2472 KB |
Output is correct |
70 |
Correct |
486 ms |
2400 KB |
Output is correct |
71 |
Correct |
497 ms |
2360 KB |
Output is correct |
72 |
Correct |
521 ms |
2376 KB |
Output is correct |
73 |
Correct |
533 ms |
2316 KB |
Output is correct |
74 |
Correct |
116 ms |
2296 KB |
Output is correct |
75 |
Correct |
120 ms |
2296 KB |
Output is correct |
76 |
Correct |
120 ms |
2424 KB |
Output is correct |
77 |
Correct |
115 ms |
2396 KB |
Output is correct |
78 |
Correct |
121 ms |
2296 KB |
Output is correct |