#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 1007, MOD = 1000 * 1000 * 1000 + 7;
int mod(int n) {
if (n < MOD)
return n;
else if (n < 2 * MOD)
return n - MOD;
else
return n % MOD;
}
int fp(int a, int p) {
int ans = 1, c = a;
for (int i = 0; (1ll << i) <= p; ++i) {
if ((p >> i) & 1) ans = mod(ans * c);
c = mod(c * c);
}
return ans;
}
int dv(int a, int b) { return mod(a * fp(b, MOD - 2)); }
void addmod(int &a, int b) {
a = mod(a + b);
}
int C(int n, int k) {
if (n < k)
return 0;
int a = 1;
for (int i = n; i > n - k; --i)
a = mod(a * i);
int b = 1;
for (int i = 1; i <= k; ++i)
b = mod(b * i);
return dv(a, b);
}
int n, l[N], r[N], dp[N][N], mem[N][N], cur[N], pref[N], lmao[N];
signed main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
#else
ios_base::sync_with_stdio(0); cin.tie(0);
#endif
for (int i = 0; i < N; ++i)
mem[i][0] = 1;
for (int i = 1; i < N; ++i)
for (int j = 1; j < N; ++j)
mem[i][j] = mod(mem[i - 1][j] + mem[i - 1][j - 1]);
cin >> n;
vector <int> c;
for (int i = 1; i <= n; ++i) {
cin >> l[i] >> r[i];
c.app(l[i]); c.app(r[i] + 1);
}
sort(all(c));
c.resize(unique(all(c)) - c.begin());
dp[0][0] = 1;
for (int i = 0; i + 1 < (int)c.size(); ++i) {
for (int j = 0; j <= n; ++j)
cur[j] = C(c[i + 1] - c[i], j);
for (int j = 1; j <= n; ++j)
pref[j] = pref[j - 1] + (l[j] <= c[i] && c[i + 1] - 1 <= r[j]);
for (int mx = 1; mx <= n; ++mx) {
lmao[mx] = 0;
for (int cnt = 1; cnt <= mx; ++cnt)
addmod(lmao[mx], mem[mx - 1][cnt - 1] * cur[cnt]);
}
for (int j = 0; j <= n; ++j) {
addmod(dp[i + 1][j], dp[i][j]);
for (int k = j + 1; k <= n; ++k) {
if (l[k] <= c[i] && c[i + 1] - 1 <= r[k]) {
int mx = pref[k] - pref[j];
addmod(dp[i + 1][k], dp[i][j] * lmao[mx]);
}
}
}
}
int ans = 0;
for (int i = 1; i <= n; ++i)
addmod(ans, dp[c.size() - 1][i]);
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1443 ms |
16212 KB |
Output is correct |
2 |
Correct |
1487 ms |
16272 KB |
Output is correct |
3 |
Correct |
1489 ms |
16376 KB |
Output is correct |
4 |
Correct |
1651 ms |
16308 KB |
Output is correct |
5 |
Correct |
1638 ms |
16340 KB |
Output is correct |
6 |
Correct |
1358 ms |
16364 KB |
Output is correct |
7 |
Correct |
1587 ms |
16392 KB |
Output is correct |
8 |
Correct |
1590 ms |
16248 KB |
Output is correct |
9 |
Correct |
1326 ms |
16232 KB |
Output is correct |
10 |
Correct |
1828 ms |
16420 KB |
Output is correct |
11 |
Correct |
1310 ms |
16156 KB |
Output is correct |
12 |
Correct |
1293 ms |
16280 KB |
Output is correct |
13 |
Correct |
1275 ms |
16236 KB |
Output is correct |
14 |
Correct |
1297 ms |
16136 KB |
Output is correct |
15 |
Correct |
1262 ms |
16224 KB |
Output is correct |
16 |
Correct |
262 ms |
9772 KB |
Output is correct |
17 |
Correct |
284 ms |
9848 KB |
Output is correct |
18 |
Correct |
283 ms |
9720 KB |
Output is correct |
19 |
Correct |
268 ms |
9848 KB |
Output is correct |
20 |
Correct |
273 ms |
9720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1443 ms |
16212 KB |
Output is correct |
2 |
Correct |
1487 ms |
16272 KB |
Output is correct |
3 |
Correct |
1489 ms |
16376 KB |
Output is correct |
4 |
Correct |
1651 ms |
16308 KB |
Output is correct |
5 |
Correct |
1638 ms |
16340 KB |
Output is correct |
6 |
Correct |
1358 ms |
16364 KB |
Output is correct |
7 |
Correct |
1587 ms |
16392 KB |
Output is correct |
8 |
Correct |
1590 ms |
16248 KB |
Output is correct |
9 |
Correct |
1326 ms |
16232 KB |
Output is correct |
10 |
Correct |
1828 ms |
16420 KB |
Output is correct |
11 |
Correct |
1310 ms |
16156 KB |
Output is correct |
12 |
Correct |
1293 ms |
16280 KB |
Output is correct |
13 |
Correct |
1275 ms |
16236 KB |
Output is correct |
14 |
Correct |
1297 ms |
16136 KB |
Output is correct |
15 |
Correct |
1262 ms |
16224 KB |
Output is correct |
16 |
Correct |
262 ms |
9772 KB |
Output is correct |
17 |
Correct |
284 ms |
9848 KB |
Output is correct |
18 |
Correct |
283 ms |
9720 KB |
Output is correct |
19 |
Correct |
268 ms |
9848 KB |
Output is correct |
20 |
Correct |
273 ms |
9720 KB |
Output is correct |
21 |
Correct |
747 ms |
15608 KB |
Output is correct |
22 |
Correct |
475 ms |
15820 KB |
Output is correct |
23 |
Correct |
493 ms |
15480 KB |
Output is correct |
24 |
Correct |
467 ms |
15480 KB |
Output is correct |
25 |
Correct |
476 ms |
15456 KB |
Output is correct |
26 |
Correct |
411 ms |
15328 KB |
Output is correct |
27 |
Correct |
425 ms |
15480 KB |
Output is correct |
28 |
Correct |
413 ms |
15224 KB |
Output is correct |
29 |
Correct |
421 ms |
15220 KB |
Output is correct |
30 |
Correct |
1175 ms |
16340 KB |
Output is correct |
31 |
Correct |
1179 ms |
16164 KB |
Output is correct |
32 |
Correct |
1145 ms |
16196 KB |
Output is correct |
33 |
Correct |
1163 ms |
16336 KB |
Output is correct |
34 |
Correct |
1154 ms |
16296 KB |
Output is correct |
35 |
Correct |
1250 ms |
16376 KB |
Output is correct |
36 |
Correct |
1275 ms |
16248 KB |
Output is correct |
37 |
Correct |
1272 ms |
16228 KB |
Output is correct |
38 |
Correct |
1260 ms |
16316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
9336 KB |
Output is correct |
2 |
Correct |
35 ms |
9208 KB |
Output is correct |
3 |
Correct |
35 ms |
9208 KB |
Output is correct |
4 |
Correct |
34 ms |
9208 KB |
Output is correct |
5 |
Correct |
33 ms |
9208 KB |
Output is correct |
6 |
Correct |
35 ms |
9208 KB |
Output is correct |
7 |
Correct |
34 ms |
9208 KB |
Output is correct |
8 |
Correct |
34 ms |
9212 KB |
Output is correct |
9 |
Correct |
34 ms |
9208 KB |
Output is correct |
10 |
Correct |
34 ms |
9208 KB |
Output is correct |
11 |
Correct |
34 ms |
9336 KB |
Output is correct |
12 |
Correct |
35 ms |
9208 KB |
Output is correct |
13 |
Correct |
34 ms |
9208 KB |
Output is correct |
14 |
Correct |
36 ms |
9208 KB |
Output is correct |
15 |
Correct |
34 ms |
9208 KB |
Output is correct |
16 |
Correct |
22 ms |
8824 KB |
Output is correct |
17 |
Correct |
21 ms |
8824 KB |
Output is correct |
18 |
Correct |
23 ms |
8824 KB |
Output is correct |
19 |
Correct |
23 ms |
8824 KB |
Output is correct |
20 |
Correct |
22 ms |
8824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1443 ms |
16212 KB |
Output is correct |
2 |
Correct |
1487 ms |
16272 KB |
Output is correct |
3 |
Correct |
1489 ms |
16376 KB |
Output is correct |
4 |
Correct |
1651 ms |
16308 KB |
Output is correct |
5 |
Correct |
1638 ms |
16340 KB |
Output is correct |
6 |
Correct |
1358 ms |
16364 KB |
Output is correct |
7 |
Correct |
1587 ms |
16392 KB |
Output is correct |
8 |
Correct |
1590 ms |
16248 KB |
Output is correct |
9 |
Correct |
1326 ms |
16232 KB |
Output is correct |
10 |
Correct |
1828 ms |
16420 KB |
Output is correct |
11 |
Correct |
1310 ms |
16156 KB |
Output is correct |
12 |
Correct |
1293 ms |
16280 KB |
Output is correct |
13 |
Correct |
1275 ms |
16236 KB |
Output is correct |
14 |
Correct |
1297 ms |
16136 KB |
Output is correct |
15 |
Correct |
1262 ms |
16224 KB |
Output is correct |
16 |
Correct |
262 ms |
9772 KB |
Output is correct |
17 |
Correct |
284 ms |
9848 KB |
Output is correct |
18 |
Correct |
283 ms |
9720 KB |
Output is correct |
19 |
Correct |
268 ms |
9848 KB |
Output is correct |
20 |
Correct |
273 ms |
9720 KB |
Output is correct |
21 |
Correct |
747 ms |
15608 KB |
Output is correct |
22 |
Correct |
475 ms |
15820 KB |
Output is correct |
23 |
Correct |
493 ms |
15480 KB |
Output is correct |
24 |
Correct |
467 ms |
15480 KB |
Output is correct |
25 |
Correct |
476 ms |
15456 KB |
Output is correct |
26 |
Correct |
411 ms |
15328 KB |
Output is correct |
27 |
Correct |
425 ms |
15480 KB |
Output is correct |
28 |
Correct |
413 ms |
15224 KB |
Output is correct |
29 |
Correct |
421 ms |
15220 KB |
Output is correct |
30 |
Correct |
1175 ms |
16340 KB |
Output is correct |
31 |
Correct |
1179 ms |
16164 KB |
Output is correct |
32 |
Correct |
1145 ms |
16196 KB |
Output is correct |
33 |
Correct |
1163 ms |
16336 KB |
Output is correct |
34 |
Correct |
1154 ms |
16296 KB |
Output is correct |
35 |
Correct |
1250 ms |
16376 KB |
Output is correct |
36 |
Correct |
1275 ms |
16248 KB |
Output is correct |
37 |
Correct |
1272 ms |
16228 KB |
Output is correct |
38 |
Correct |
1260 ms |
16316 KB |
Output is correct |
39 |
Correct |
34 ms |
9336 KB |
Output is correct |
40 |
Correct |
35 ms |
9208 KB |
Output is correct |
41 |
Correct |
35 ms |
9208 KB |
Output is correct |
42 |
Correct |
34 ms |
9208 KB |
Output is correct |
43 |
Correct |
33 ms |
9208 KB |
Output is correct |
44 |
Correct |
35 ms |
9208 KB |
Output is correct |
45 |
Correct |
34 ms |
9208 KB |
Output is correct |
46 |
Correct |
34 ms |
9212 KB |
Output is correct |
47 |
Correct |
34 ms |
9208 KB |
Output is correct |
48 |
Correct |
34 ms |
9208 KB |
Output is correct |
49 |
Correct |
34 ms |
9336 KB |
Output is correct |
50 |
Correct |
35 ms |
9208 KB |
Output is correct |
51 |
Correct |
34 ms |
9208 KB |
Output is correct |
52 |
Correct |
36 ms |
9208 KB |
Output is correct |
53 |
Correct |
34 ms |
9208 KB |
Output is correct |
54 |
Correct |
22 ms |
8824 KB |
Output is correct |
55 |
Correct |
21 ms |
8824 KB |
Output is correct |
56 |
Correct |
23 ms |
8824 KB |
Output is correct |
57 |
Correct |
23 ms |
8824 KB |
Output is correct |
58 |
Correct |
22 ms |
8824 KB |
Output is correct |
59 |
Execution timed out |
2091 ms |
15252 KB |
Time limit exceeded |
60 |
Halted |
0 ms |
0 KB |
- |