#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define all(x) (x).begin(),(x).end()
#define X first
#define Y second
#define sep ' '
#define endl '\n'
#define SZ(x) ll(x.size())
const ll MAXN = 1000 + 10;
const ll LOG = 22;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; //998244353; //1e9 + 9;
ll n , L[MAXN] , R[MAXN] , dp[MAXN][MAXN] , ps[MAXN] , inv[MAXN];
vector<int> compress = {0};
ll poww(ll a , ll b){
ll ans = 1;
for( ; b ; b /= 2 , a = a * a % MOD) if(b & 1) ans = ans * a % MOD;
return ans;
}
int main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
for(int i = 1 ; i < MAXN ; i++) inv[i] = poww(i , MOD - 2);
// for(int i = 1 ; i <= 5 ; i++) cout << i << sep << inv[i] << endl;
cin >> n;
for(int i = 1 ; i <= n ; i++){
cin >> L[i] >> R[i]; R[i]++;
compress.push_back(L[i]);
compress.push_back(R[i]);
}
sort(all(compress));
compress.resize(unique(all(compress)) - compress.begin());
dp[0][0] = 1; fill(ps , ps + MAXN , 1);
for(int i = 1 ; i <= n ; i++){
L[i] = lower_bound(all(compress) , L[i]) - compress.begin();
R[i] = lower_bound(all(compress) , R[i]) - compress.begin();
for(int j = L[i] ; j < R[i] ; j++){
int len = compress[j + 1] - compress[j];
for(int k = n ; k >= 2 ; k--){
dp[j][k] = (dp[j][k] + dp[j][k - 1] * (len - k + 1) % MOD * inv[k]) % MOD;
}
dp[j][1] = (dp[j][1] + ps[j - 1] * len) % MOD;
}
ps[0] = dp[0][0];
for(int j = 1 ; j < MAXN ; j++){
ps[j] = ps[j - 1];
for(int k = 0 ; k <= n ; k++){
ps[j] = (ps[j] + dp[j][k]);
}
ps[j] %= MOD;
}
}
cout << (ps[MAXN - 1] + MOD - 1) % MOD << endl;
return 0;
}
/*
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
167 ms |
4332 KB |
Output is correct |
2 |
Correct |
176 ms |
4416 KB |
Output is correct |
3 |
Correct |
169 ms |
4460 KB |
Output is correct |
4 |
Correct |
170 ms |
4332 KB |
Output is correct |
5 |
Correct |
177 ms |
4332 KB |
Output is correct |
6 |
Correct |
168 ms |
4332 KB |
Output is correct |
7 |
Correct |
172 ms |
4332 KB |
Output is correct |
8 |
Correct |
167 ms |
4332 KB |
Output is correct |
9 |
Correct |
167 ms |
4460 KB |
Output is correct |
10 |
Correct |
172 ms |
4332 KB |
Output is correct |
11 |
Correct |
167 ms |
4332 KB |
Output is correct |
12 |
Correct |
170 ms |
4332 KB |
Output is correct |
13 |
Correct |
166 ms |
4332 KB |
Output is correct |
14 |
Correct |
164 ms |
4332 KB |
Output is correct |
15 |
Correct |
164 ms |
4332 KB |
Output is correct |
16 |
Correct |
163 ms |
1132 KB |
Output is correct |
17 |
Correct |
181 ms |
1132 KB |
Output is correct |
18 |
Correct |
167 ms |
1132 KB |
Output is correct |
19 |
Correct |
163 ms |
1388 KB |
Output is correct |
20 |
Correct |
170 ms |
1132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
167 ms |
4332 KB |
Output is correct |
2 |
Correct |
176 ms |
4416 KB |
Output is correct |
3 |
Correct |
169 ms |
4460 KB |
Output is correct |
4 |
Correct |
170 ms |
4332 KB |
Output is correct |
5 |
Correct |
177 ms |
4332 KB |
Output is correct |
6 |
Correct |
168 ms |
4332 KB |
Output is correct |
7 |
Correct |
172 ms |
4332 KB |
Output is correct |
8 |
Correct |
167 ms |
4332 KB |
Output is correct |
9 |
Correct |
167 ms |
4460 KB |
Output is correct |
10 |
Correct |
172 ms |
4332 KB |
Output is correct |
11 |
Correct |
167 ms |
4332 KB |
Output is correct |
12 |
Correct |
170 ms |
4332 KB |
Output is correct |
13 |
Correct |
166 ms |
4332 KB |
Output is correct |
14 |
Correct |
164 ms |
4332 KB |
Output is correct |
15 |
Correct |
164 ms |
4332 KB |
Output is correct |
16 |
Correct |
163 ms |
1132 KB |
Output is correct |
17 |
Correct |
181 ms |
1132 KB |
Output is correct |
18 |
Correct |
167 ms |
1132 KB |
Output is correct |
19 |
Correct |
163 ms |
1388 KB |
Output is correct |
20 |
Correct |
170 ms |
1132 KB |
Output is correct |
21 |
Correct |
598 ms |
7660 KB |
Output is correct |
22 |
Correct |
602 ms |
7788 KB |
Output is correct |
23 |
Correct |
569 ms |
7660 KB |
Output is correct |
24 |
Correct |
586 ms |
7660 KB |
Output is correct |
25 |
Correct |
611 ms |
7660 KB |
Output is correct |
26 |
Correct |
707 ms |
7276 KB |
Output is correct |
27 |
Correct |
729 ms |
7404 KB |
Output is correct |
28 |
Correct |
723 ms |
7288 KB |
Output is correct |
29 |
Correct |
713 ms |
7276 KB |
Output is correct |
30 |
Correct |
178 ms |
8300 KB |
Output is correct |
31 |
Correct |
178 ms |
8428 KB |
Output is correct |
32 |
Correct |
192 ms |
8300 KB |
Output is correct |
33 |
Correct |
182 ms |
8300 KB |
Output is correct |
34 |
Correct |
188 ms |
8292 KB |
Output is correct |
35 |
Correct |
197 ms |
8504 KB |
Output is correct |
36 |
Correct |
197 ms |
8300 KB |
Output is correct |
37 |
Correct |
183 ms |
8428 KB |
Output is correct |
38 |
Correct |
197 ms |
8172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
1388 KB |
Output is correct |
2 |
Correct |
15 ms |
1388 KB |
Output is correct |
3 |
Correct |
13 ms |
1388 KB |
Output is correct |
4 |
Correct |
14 ms |
1388 KB |
Output is correct |
5 |
Correct |
14 ms |
1388 KB |
Output is correct |
6 |
Correct |
19 ms |
1388 KB |
Output is correct |
7 |
Correct |
15 ms |
1388 KB |
Output is correct |
8 |
Correct |
15 ms |
1388 KB |
Output is correct |
9 |
Correct |
15 ms |
1388 KB |
Output is correct |
10 |
Correct |
16 ms |
1388 KB |
Output is correct |
11 |
Correct |
14 ms |
1388 KB |
Output is correct |
12 |
Correct |
14 ms |
1388 KB |
Output is correct |
13 |
Correct |
13 ms |
1388 KB |
Output is correct |
14 |
Correct |
13 ms |
1388 KB |
Output is correct |
15 |
Correct |
14 ms |
1388 KB |
Output is correct |
16 |
Correct |
12 ms |
876 KB |
Output is correct |
17 |
Correct |
12 ms |
876 KB |
Output is correct |
18 |
Correct |
14 ms |
876 KB |
Output is correct |
19 |
Correct |
12 ms |
876 KB |
Output is correct |
20 |
Correct |
13 ms |
876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
167 ms |
4332 KB |
Output is correct |
2 |
Correct |
176 ms |
4416 KB |
Output is correct |
3 |
Correct |
169 ms |
4460 KB |
Output is correct |
4 |
Correct |
170 ms |
4332 KB |
Output is correct |
5 |
Correct |
177 ms |
4332 KB |
Output is correct |
6 |
Correct |
168 ms |
4332 KB |
Output is correct |
7 |
Correct |
172 ms |
4332 KB |
Output is correct |
8 |
Correct |
167 ms |
4332 KB |
Output is correct |
9 |
Correct |
167 ms |
4460 KB |
Output is correct |
10 |
Correct |
172 ms |
4332 KB |
Output is correct |
11 |
Correct |
167 ms |
4332 KB |
Output is correct |
12 |
Correct |
170 ms |
4332 KB |
Output is correct |
13 |
Correct |
166 ms |
4332 KB |
Output is correct |
14 |
Correct |
164 ms |
4332 KB |
Output is correct |
15 |
Correct |
164 ms |
4332 KB |
Output is correct |
16 |
Correct |
163 ms |
1132 KB |
Output is correct |
17 |
Correct |
181 ms |
1132 KB |
Output is correct |
18 |
Correct |
167 ms |
1132 KB |
Output is correct |
19 |
Correct |
163 ms |
1388 KB |
Output is correct |
20 |
Correct |
170 ms |
1132 KB |
Output is correct |
21 |
Correct |
598 ms |
7660 KB |
Output is correct |
22 |
Correct |
602 ms |
7788 KB |
Output is correct |
23 |
Correct |
569 ms |
7660 KB |
Output is correct |
24 |
Correct |
586 ms |
7660 KB |
Output is correct |
25 |
Correct |
611 ms |
7660 KB |
Output is correct |
26 |
Correct |
707 ms |
7276 KB |
Output is correct |
27 |
Correct |
729 ms |
7404 KB |
Output is correct |
28 |
Correct |
723 ms |
7288 KB |
Output is correct |
29 |
Correct |
713 ms |
7276 KB |
Output is correct |
30 |
Correct |
178 ms |
8300 KB |
Output is correct |
31 |
Correct |
178 ms |
8428 KB |
Output is correct |
32 |
Correct |
192 ms |
8300 KB |
Output is correct |
33 |
Correct |
182 ms |
8300 KB |
Output is correct |
34 |
Correct |
188 ms |
8292 KB |
Output is correct |
35 |
Correct |
197 ms |
8504 KB |
Output is correct |
36 |
Correct |
197 ms |
8300 KB |
Output is correct |
37 |
Correct |
183 ms |
8428 KB |
Output is correct |
38 |
Correct |
197 ms |
8172 KB |
Output is correct |
39 |
Correct |
14 ms |
1388 KB |
Output is correct |
40 |
Correct |
15 ms |
1388 KB |
Output is correct |
41 |
Correct |
13 ms |
1388 KB |
Output is correct |
42 |
Correct |
14 ms |
1388 KB |
Output is correct |
43 |
Correct |
14 ms |
1388 KB |
Output is correct |
44 |
Correct |
19 ms |
1388 KB |
Output is correct |
45 |
Correct |
15 ms |
1388 KB |
Output is correct |
46 |
Correct |
15 ms |
1388 KB |
Output is correct |
47 |
Correct |
15 ms |
1388 KB |
Output is correct |
48 |
Correct |
16 ms |
1388 KB |
Output is correct |
49 |
Correct |
14 ms |
1388 KB |
Output is correct |
50 |
Correct |
14 ms |
1388 KB |
Output is correct |
51 |
Correct |
13 ms |
1388 KB |
Output is correct |
52 |
Correct |
13 ms |
1388 KB |
Output is correct |
53 |
Correct |
14 ms |
1388 KB |
Output is correct |
54 |
Correct |
12 ms |
876 KB |
Output is correct |
55 |
Correct |
12 ms |
876 KB |
Output is correct |
56 |
Correct |
14 ms |
876 KB |
Output is correct |
57 |
Correct |
12 ms |
876 KB |
Output is correct |
58 |
Correct |
13 ms |
876 KB |
Output is correct |
59 |
Correct |
645 ms |
8300 KB |
Output is correct |
60 |
Correct |
635 ms |
8300 KB |
Output is correct |
61 |
Correct |
607 ms |
8572 KB |
Output is correct |
62 |
Correct |
650 ms |
8588 KB |
Output is correct |
63 |
Correct |
624 ms |
8300 KB |
Output is correct |
64 |
Correct |
844 ms |
8428 KB |
Output is correct |
65 |
Correct |
789 ms |
8460 KB |
Output is correct |
66 |
Correct |
797 ms |
8300 KB |
Output is correct |
67 |
Correct |
817 ms |
8300 KB |
Output is correct |
68 |
Correct |
802 ms |
8428 KB |
Output is correct |
69 |
Correct |
606 ms |
8300 KB |
Output is correct |
70 |
Correct |
606 ms |
8428 KB |
Output is correct |
71 |
Correct |
619 ms |
8444 KB |
Output is correct |
72 |
Correct |
639 ms |
8428 KB |
Output is correct |
73 |
Correct |
629 ms |
8428 KB |
Output is correct |
74 |
Correct |
234 ms |
1868 KB |
Output is correct |
75 |
Correct |
245 ms |
2028 KB |
Output is correct |
76 |
Correct |
236 ms |
1900 KB |
Output is correct |
77 |
Correct |
256 ms |
1900 KB |
Output is correct |
78 |
Correct |
236 ms |
1900 KB |
Output is correct |