#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 510;
const int mod = 1e9 + 7;
int n, f[N][N * 2], g[N * 2][N], C[N][N];
int L[N], R[N], cur[N], inv[N];
void add(int& a, int b) {
a += b;
if (a >= mod) a -= mod;
}
int main() {
ios :: sync_with_stdio(0); cin.tie(0);
cin >> n;
vector <int> dta = {0};
for (int i = 1; i <= n; ++i) {
cin >> L[i] >> R[i];
--L[i];
dta.push_back(L[i]), dta.push_back(R[i]);
}
sort(dta.begin(), dta.end());
dta.erase(unique(dta.begin(), dta.end()), dta.end());
int m = dta.size();
C[0][0] = 1;
for (int i = 1; i < N; ++i) {
C[i][0] = 1;
for (int j = 1; j <= i; ++j)
C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
}
auto power = [&](int a, int n) {
int ans = 1;
for (; n; n >>= 1, a = 1LL * a * a % mod)
if (n & 1) ans = 1LL * ans * a % mod;
return ans;
};
inv[0] = 1;
for (int i = 1, fact = 1; i <= n; ++i, fact = 1LL * fact * i % mod)
inv[i] = power(fact, mod - 2);
auto coef = [&](int n, int k) {
if (k > n || k < 0) return 0;
if (k > n - k) k = n - k;
int ans = inv[k];
for (int i = n - k + 1; i <= n; ++i) ans = 1LL * ans * i % mod;
return ans;
};
for (int i = 0; i < m; ++i) f[0][i] = 1;
for (int s = 1; s < m; ++s) {
int d = dta[s] - dta[s - 1];
for (int i = 0; i <= n; ++i) cur[i] = coef(d, i);
for (int i = 0; i <= n; ++i) {
for (int j = 0; j < i; ++j) {
add(g[s][i], 1LL * C[i - 1][j] * cur[j + 1] % mod);
}
}
}
int ans = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j < m; ++j) {
f[i][j] = f[i][j - 1];
if (L[i] >= dta[j] || dta[j] > R[i]) continue;
int cnt = 0;
for (int k = i; k > 0; --k) {
cnt += (L[k] < dta[j] && dta[j] <= R[k]);
add(f[i][j], 1LL * f[k - 1][j - 1] * g[j][cnt] % mod);
}
}
add(ans, f[i][m - 1]);
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
657 ms |
5324 KB |
Output is correct |
2 |
Correct |
675 ms |
5352 KB |
Output is correct |
3 |
Correct |
652 ms |
5340 KB |
Output is correct |
4 |
Correct |
619 ms |
5464 KB |
Output is correct |
5 |
Correct |
615 ms |
5256 KB |
Output is correct |
6 |
Correct |
625 ms |
5428 KB |
Output is correct |
7 |
Correct |
635 ms |
5268 KB |
Output is correct |
8 |
Correct |
637 ms |
5256 KB |
Output is correct |
9 |
Correct |
636 ms |
5284 KB |
Output is correct |
10 |
Correct |
611 ms |
5324 KB |
Output is correct |
11 |
Correct |
638 ms |
5328 KB |
Output is correct |
12 |
Correct |
629 ms |
5324 KB |
Output is correct |
13 |
Correct |
646 ms |
5264 KB |
Output is correct |
14 |
Correct |
630 ms |
5396 KB |
Output is correct |
15 |
Correct |
621 ms |
5284 KB |
Output is correct |
16 |
Correct |
112 ms |
3584 KB |
Output is correct |
17 |
Correct |
121 ms |
3664 KB |
Output is correct |
18 |
Correct |
114 ms |
3612 KB |
Output is correct |
19 |
Correct |
122 ms |
3748 KB |
Output is correct |
20 |
Correct |
117 ms |
3636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
657 ms |
5324 KB |
Output is correct |
2 |
Correct |
675 ms |
5352 KB |
Output is correct |
3 |
Correct |
652 ms |
5340 KB |
Output is correct |
4 |
Correct |
619 ms |
5464 KB |
Output is correct |
5 |
Correct |
615 ms |
5256 KB |
Output is correct |
6 |
Correct |
625 ms |
5428 KB |
Output is correct |
7 |
Correct |
635 ms |
5268 KB |
Output is correct |
8 |
Correct |
637 ms |
5256 KB |
Output is correct |
9 |
Correct |
636 ms |
5284 KB |
Output is correct |
10 |
Correct |
611 ms |
5324 KB |
Output is correct |
11 |
Correct |
638 ms |
5328 KB |
Output is correct |
12 |
Correct |
629 ms |
5324 KB |
Output is correct |
13 |
Correct |
646 ms |
5264 KB |
Output is correct |
14 |
Correct |
630 ms |
5396 KB |
Output is correct |
15 |
Correct |
621 ms |
5284 KB |
Output is correct |
16 |
Correct |
112 ms |
3584 KB |
Output is correct |
17 |
Correct |
121 ms |
3664 KB |
Output is correct |
18 |
Correct |
114 ms |
3612 KB |
Output is correct |
19 |
Correct |
122 ms |
3748 KB |
Output is correct |
20 |
Correct |
117 ms |
3636 KB |
Output is correct |
21 |
Correct |
641 ms |
5276 KB |
Output is correct |
22 |
Correct |
619 ms |
5196 KB |
Output is correct |
23 |
Correct |
582 ms |
5244 KB |
Output is correct |
24 |
Correct |
612 ms |
5096 KB |
Output is correct |
25 |
Correct |
606 ms |
5124 KB |
Output is correct |
26 |
Correct |
744 ms |
5324 KB |
Output is correct |
27 |
Correct |
783 ms |
5196 KB |
Output is correct |
28 |
Correct |
766 ms |
5084 KB |
Output is correct |
29 |
Correct |
759 ms |
5048 KB |
Output is correct |
30 |
Correct |
571 ms |
5436 KB |
Output is correct |
31 |
Correct |
563 ms |
5348 KB |
Output is correct |
32 |
Correct |
564 ms |
5328 KB |
Output is correct |
33 |
Correct |
567 ms |
5392 KB |
Output is correct |
34 |
Correct |
567 ms |
5324 KB |
Output is correct |
35 |
Correct |
559 ms |
5308 KB |
Output is correct |
36 |
Correct |
567 ms |
5500 KB |
Output is correct |
37 |
Correct |
578 ms |
5348 KB |
Output is correct |
38 |
Correct |
572 ms |
5376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
2132 KB |
Output is correct |
2 |
Correct |
11 ms |
2132 KB |
Output is correct |
3 |
Correct |
11 ms |
2132 KB |
Output is correct |
4 |
Correct |
14 ms |
2116 KB |
Output is correct |
5 |
Correct |
12 ms |
2076 KB |
Output is correct |
6 |
Correct |
14 ms |
2108 KB |
Output is correct |
7 |
Correct |
13 ms |
2132 KB |
Output is correct |
8 |
Correct |
13 ms |
2132 KB |
Output is correct |
9 |
Correct |
14 ms |
2064 KB |
Output is correct |
10 |
Correct |
14 ms |
2084 KB |
Output is correct |
11 |
Correct |
12 ms |
2132 KB |
Output is correct |
12 |
Correct |
12 ms |
2124 KB |
Output is correct |
13 |
Correct |
13 ms |
2064 KB |
Output is correct |
14 |
Correct |
12 ms |
2124 KB |
Output is correct |
15 |
Correct |
13 ms |
2044 KB |
Output is correct |
16 |
Correct |
7 ms |
2004 KB |
Output is correct |
17 |
Correct |
6 ms |
1876 KB |
Output is correct |
18 |
Correct |
7 ms |
1988 KB |
Output is correct |
19 |
Correct |
7 ms |
1876 KB |
Output is correct |
20 |
Correct |
7 ms |
1876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
657 ms |
5324 KB |
Output is correct |
2 |
Correct |
675 ms |
5352 KB |
Output is correct |
3 |
Correct |
652 ms |
5340 KB |
Output is correct |
4 |
Correct |
619 ms |
5464 KB |
Output is correct |
5 |
Correct |
615 ms |
5256 KB |
Output is correct |
6 |
Correct |
625 ms |
5428 KB |
Output is correct |
7 |
Correct |
635 ms |
5268 KB |
Output is correct |
8 |
Correct |
637 ms |
5256 KB |
Output is correct |
9 |
Correct |
636 ms |
5284 KB |
Output is correct |
10 |
Correct |
611 ms |
5324 KB |
Output is correct |
11 |
Correct |
638 ms |
5328 KB |
Output is correct |
12 |
Correct |
629 ms |
5324 KB |
Output is correct |
13 |
Correct |
646 ms |
5264 KB |
Output is correct |
14 |
Correct |
630 ms |
5396 KB |
Output is correct |
15 |
Correct |
621 ms |
5284 KB |
Output is correct |
16 |
Correct |
112 ms |
3584 KB |
Output is correct |
17 |
Correct |
121 ms |
3664 KB |
Output is correct |
18 |
Correct |
114 ms |
3612 KB |
Output is correct |
19 |
Correct |
122 ms |
3748 KB |
Output is correct |
20 |
Correct |
117 ms |
3636 KB |
Output is correct |
21 |
Correct |
641 ms |
5276 KB |
Output is correct |
22 |
Correct |
619 ms |
5196 KB |
Output is correct |
23 |
Correct |
582 ms |
5244 KB |
Output is correct |
24 |
Correct |
612 ms |
5096 KB |
Output is correct |
25 |
Correct |
606 ms |
5124 KB |
Output is correct |
26 |
Correct |
744 ms |
5324 KB |
Output is correct |
27 |
Correct |
783 ms |
5196 KB |
Output is correct |
28 |
Correct |
766 ms |
5084 KB |
Output is correct |
29 |
Correct |
759 ms |
5048 KB |
Output is correct |
30 |
Correct |
571 ms |
5436 KB |
Output is correct |
31 |
Correct |
563 ms |
5348 KB |
Output is correct |
32 |
Correct |
564 ms |
5328 KB |
Output is correct |
33 |
Correct |
567 ms |
5392 KB |
Output is correct |
34 |
Correct |
567 ms |
5324 KB |
Output is correct |
35 |
Correct |
559 ms |
5308 KB |
Output is correct |
36 |
Correct |
567 ms |
5500 KB |
Output is correct |
37 |
Correct |
578 ms |
5348 KB |
Output is correct |
38 |
Correct |
572 ms |
5376 KB |
Output is correct |
39 |
Correct |
12 ms |
2132 KB |
Output is correct |
40 |
Correct |
11 ms |
2132 KB |
Output is correct |
41 |
Correct |
11 ms |
2132 KB |
Output is correct |
42 |
Correct |
14 ms |
2116 KB |
Output is correct |
43 |
Correct |
12 ms |
2076 KB |
Output is correct |
44 |
Correct |
14 ms |
2108 KB |
Output is correct |
45 |
Correct |
13 ms |
2132 KB |
Output is correct |
46 |
Correct |
13 ms |
2132 KB |
Output is correct |
47 |
Correct |
14 ms |
2064 KB |
Output is correct |
48 |
Correct |
14 ms |
2084 KB |
Output is correct |
49 |
Correct |
12 ms |
2132 KB |
Output is correct |
50 |
Correct |
12 ms |
2124 KB |
Output is correct |
51 |
Correct |
13 ms |
2064 KB |
Output is correct |
52 |
Correct |
12 ms |
2124 KB |
Output is correct |
53 |
Correct |
13 ms |
2044 KB |
Output is correct |
54 |
Correct |
7 ms |
2004 KB |
Output is correct |
55 |
Correct |
6 ms |
1876 KB |
Output is correct |
56 |
Correct |
7 ms |
1988 KB |
Output is correct |
57 |
Correct |
7 ms |
1876 KB |
Output is correct |
58 |
Correct |
7 ms |
1876 KB |
Output is correct |
59 |
Correct |
1323 ms |
5376 KB |
Output is correct |
60 |
Correct |
1286 ms |
5664 KB |
Output is correct |
61 |
Correct |
1278 ms |
5388 KB |
Output is correct |
62 |
Correct |
1310 ms |
5252 KB |
Output is correct |
63 |
Correct |
1310 ms |
5352 KB |
Output is correct |
64 |
Correct |
1502 ms |
5268 KB |
Output is correct |
65 |
Correct |
1460 ms |
5600 KB |
Output is correct |
66 |
Correct |
1497 ms |
5344 KB |
Output is correct |
67 |
Correct |
1475 ms |
5292 KB |
Output is correct |
68 |
Correct |
1504 ms |
5384 KB |
Output is correct |
69 |
Correct |
1220 ms |
5328 KB |
Output is correct |
70 |
Correct |
1205 ms |
5460 KB |
Output is correct |
71 |
Correct |
1203 ms |
5336 KB |
Output is correct |
72 |
Correct |
1217 ms |
5420 KB |
Output is correct |
73 |
Correct |
1248 ms |
5284 KB |
Output is correct |
74 |
Correct |
199 ms |
3708 KB |
Output is correct |
75 |
Correct |
191 ms |
3644 KB |
Output is correct |
76 |
Correct |
199 ms |
3744 KB |
Output is correct |
77 |
Correct |
192 ms |
3752 KB |
Output is correct |
78 |
Correct |
203 ms |
3652 KB |
Output is correct |