#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 = MAXN - 1 ; 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 < MAXN ; k++){
ps[j] = (ps[j] + dp[j][k]);
}
ps[j] %= MOD;
}
}
cout << (ps[MAXN - 1] + MOD - 1) % MOD << endl;
return 0;
}
/*
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
331 ms |
6380 KB |
Output is correct |
2 |
Correct |
299 ms |
6380 KB |
Output is correct |
3 |
Correct |
352 ms |
6380 KB |
Output is correct |
4 |
Correct |
304 ms |
6380 KB |
Output is correct |
5 |
Correct |
307 ms |
6412 KB |
Output is correct |
6 |
Correct |
303 ms |
6380 KB |
Output is correct |
7 |
Correct |
300 ms |
6380 KB |
Output is correct |
8 |
Correct |
308 ms |
6380 KB |
Output is correct |
9 |
Correct |
298 ms |
6380 KB |
Output is correct |
10 |
Correct |
302 ms |
6508 KB |
Output is correct |
11 |
Correct |
315 ms |
6492 KB |
Output is correct |
12 |
Correct |
299 ms |
6508 KB |
Output is correct |
13 |
Correct |
310 ms |
6404 KB |
Output is correct |
14 |
Correct |
304 ms |
6360 KB |
Output is correct |
15 |
Correct |
302 ms |
6384 KB |
Output is correct |
16 |
Correct |
298 ms |
1592 KB |
Output is correct |
17 |
Correct |
303 ms |
1644 KB |
Output is correct |
18 |
Correct |
309 ms |
1664 KB |
Output is correct |
19 |
Correct |
307 ms |
1772 KB |
Output is correct |
20 |
Correct |
298 ms |
1516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
331 ms |
6380 KB |
Output is correct |
2 |
Correct |
299 ms |
6380 KB |
Output is correct |
3 |
Correct |
352 ms |
6380 KB |
Output is correct |
4 |
Correct |
304 ms |
6380 KB |
Output is correct |
5 |
Correct |
307 ms |
6412 KB |
Output is correct |
6 |
Correct |
303 ms |
6380 KB |
Output is correct |
7 |
Correct |
300 ms |
6380 KB |
Output is correct |
8 |
Correct |
308 ms |
6380 KB |
Output is correct |
9 |
Correct |
298 ms |
6380 KB |
Output is correct |
10 |
Correct |
302 ms |
6508 KB |
Output is correct |
11 |
Correct |
315 ms |
6492 KB |
Output is correct |
12 |
Correct |
299 ms |
6508 KB |
Output is correct |
13 |
Correct |
310 ms |
6404 KB |
Output is correct |
14 |
Correct |
304 ms |
6360 KB |
Output is correct |
15 |
Correct |
302 ms |
6384 KB |
Output is correct |
16 |
Correct |
298 ms |
1592 KB |
Output is correct |
17 |
Correct |
303 ms |
1644 KB |
Output is correct |
18 |
Correct |
309 ms |
1664 KB |
Output is correct |
19 |
Correct |
307 ms |
1772 KB |
Output is correct |
20 |
Correct |
298 ms |
1516 KB |
Output is correct |
21 |
Correct |
1113 ms |
7684 KB |
Output is correct |
22 |
Correct |
1091 ms |
7916 KB |
Output is correct |
23 |
Correct |
1056 ms |
7788 KB |
Output is correct |
24 |
Correct |
1036 ms |
7532 KB |
Output is correct |
25 |
Correct |
1095 ms |
7532 KB |
Output is correct |
26 |
Correct |
1394 ms |
7276 KB |
Output is correct |
27 |
Correct |
1396 ms |
7404 KB |
Output is correct |
28 |
Correct |
1357 ms |
7276 KB |
Output is correct |
29 |
Correct |
1363 ms |
7276 KB |
Output is correct |
30 |
Correct |
316 ms |
8300 KB |
Output is correct |
31 |
Correct |
326 ms |
8300 KB |
Output is correct |
32 |
Correct |
325 ms |
8300 KB |
Output is correct |
33 |
Correct |
334 ms |
8384 KB |
Output is correct |
34 |
Correct |
320 ms |
8300 KB |
Output is correct |
35 |
Correct |
323 ms |
8292 KB |
Output is correct |
36 |
Correct |
336 ms |
8248 KB |
Output is correct |
37 |
Correct |
325 ms |
8484 KB |
Output is correct |
38 |
Correct |
371 ms |
8496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
90 ms |
1900 KB |
Output is correct |
2 |
Correct |
84 ms |
1900 KB |
Output is correct |
3 |
Correct |
88 ms |
1900 KB |
Output is correct |
4 |
Correct |
93 ms |
1900 KB |
Output is correct |
5 |
Correct |
92 ms |
1900 KB |
Output is correct |
6 |
Correct |
105 ms |
2028 KB |
Output is correct |
7 |
Correct |
108 ms |
1900 KB |
Output is correct |
8 |
Correct |
104 ms |
1900 KB |
Output is correct |
9 |
Correct |
130 ms |
2028 KB |
Output is correct |
10 |
Correct |
114 ms |
1900 KB |
Output is correct |
11 |
Correct |
90 ms |
2012 KB |
Output is correct |
12 |
Correct |
98 ms |
1900 KB |
Output is correct |
13 |
Correct |
90 ms |
1900 KB |
Output is correct |
14 |
Correct |
89 ms |
1900 KB |
Output is correct |
15 |
Correct |
90 ms |
1900 KB |
Output is correct |
16 |
Correct |
80 ms |
1516 KB |
Output is correct |
17 |
Correct |
81 ms |
1260 KB |
Output is correct |
18 |
Correct |
90 ms |
1260 KB |
Output is correct |
19 |
Correct |
78 ms |
1260 KB |
Output is correct |
20 |
Correct |
78 ms |
1260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
331 ms |
6380 KB |
Output is correct |
2 |
Correct |
299 ms |
6380 KB |
Output is correct |
3 |
Correct |
352 ms |
6380 KB |
Output is correct |
4 |
Correct |
304 ms |
6380 KB |
Output is correct |
5 |
Correct |
307 ms |
6412 KB |
Output is correct |
6 |
Correct |
303 ms |
6380 KB |
Output is correct |
7 |
Correct |
300 ms |
6380 KB |
Output is correct |
8 |
Correct |
308 ms |
6380 KB |
Output is correct |
9 |
Correct |
298 ms |
6380 KB |
Output is correct |
10 |
Correct |
302 ms |
6508 KB |
Output is correct |
11 |
Correct |
315 ms |
6492 KB |
Output is correct |
12 |
Correct |
299 ms |
6508 KB |
Output is correct |
13 |
Correct |
310 ms |
6404 KB |
Output is correct |
14 |
Correct |
304 ms |
6360 KB |
Output is correct |
15 |
Correct |
302 ms |
6384 KB |
Output is correct |
16 |
Correct |
298 ms |
1592 KB |
Output is correct |
17 |
Correct |
303 ms |
1644 KB |
Output is correct |
18 |
Correct |
309 ms |
1664 KB |
Output is correct |
19 |
Correct |
307 ms |
1772 KB |
Output is correct |
20 |
Correct |
298 ms |
1516 KB |
Output is correct |
21 |
Correct |
1113 ms |
7684 KB |
Output is correct |
22 |
Correct |
1091 ms |
7916 KB |
Output is correct |
23 |
Correct |
1056 ms |
7788 KB |
Output is correct |
24 |
Correct |
1036 ms |
7532 KB |
Output is correct |
25 |
Correct |
1095 ms |
7532 KB |
Output is correct |
26 |
Correct |
1394 ms |
7276 KB |
Output is correct |
27 |
Correct |
1396 ms |
7404 KB |
Output is correct |
28 |
Correct |
1357 ms |
7276 KB |
Output is correct |
29 |
Correct |
1363 ms |
7276 KB |
Output is correct |
30 |
Correct |
316 ms |
8300 KB |
Output is correct |
31 |
Correct |
326 ms |
8300 KB |
Output is correct |
32 |
Correct |
325 ms |
8300 KB |
Output is correct |
33 |
Correct |
334 ms |
8384 KB |
Output is correct |
34 |
Correct |
320 ms |
8300 KB |
Output is correct |
35 |
Correct |
323 ms |
8292 KB |
Output is correct |
36 |
Correct |
336 ms |
8248 KB |
Output is correct |
37 |
Correct |
325 ms |
8484 KB |
Output is correct |
38 |
Correct |
371 ms |
8496 KB |
Output is correct |
39 |
Correct |
90 ms |
1900 KB |
Output is correct |
40 |
Correct |
84 ms |
1900 KB |
Output is correct |
41 |
Correct |
88 ms |
1900 KB |
Output is correct |
42 |
Correct |
93 ms |
1900 KB |
Output is correct |
43 |
Correct |
92 ms |
1900 KB |
Output is correct |
44 |
Correct |
105 ms |
2028 KB |
Output is correct |
45 |
Correct |
108 ms |
1900 KB |
Output is correct |
46 |
Correct |
104 ms |
1900 KB |
Output is correct |
47 |
Correct |
130 ms |
2028 KB |
Output is correct |
48 |
Correct |
114 ms |
1900 KB |
Output is correct |
49 |
Correct |
90 ms |
2012 KB |
Output is correct |
50 |
Correct |
98 ms |
1900 KB |
Output is correct |
51 |
Correct |
90 ms |
1900 KB |
Output is correct |
52 |
Correct |
89 ms |
1900 KB |
Output is correct |
53 |
Correct |
90 ms |
1900 KB |
Output is correct |
54 |
Correct |
80 ms |
1516 KB |
Output is correct |
55 |
Correct |
81 ms |
1260 KB |
Output is correct |
56 |
Correct |
90 ms |
1260 KB |
Output is correct |
57 |
Correct |
78 ms |
1260 KB |
Output is correct |
58 |
Correct |
78 ms |
1260 KB |
Output is correct |
59 |
Correct |
1142 ms |
8508 KB |
Output is correct |
60 |
Correct |
1107 ms |
8300 KB |
Output is correct |
61 |
Correct |
1143 ms |
8300 KB |
Output is correct |
62 |
Correct |
1168 ms |
8556 KB |
Output is correct |
63 |
Correct |
1169 ms |
8428 KB |
Output is correct |
64 |
Correct |
1535 ms |
8300 KB |
Output is correct |
65 |
Correct |
1518 ms |
8356 KB |
Output is correct |
66 |
Correct |
1517 ms |
8260 KB |
Output is correct |
67 |
Correct |
1507 ms |
8324 KB |
Output is correct |
68 |
Correct |
1525 ms |
8416 KB |
Output is correct |
69 |
Correct |
1098 ms |
8316 KB |
Output is correct |
70 |
Correct |
1095 ms |
8356 KB |
Output is correct |
71 |
Correct |
1072 ms |
8300 KB |
Output is correct |
72 |
Correct |
1105 ms |
8300 KB |
Output is correct |
73 |
Correct |
1102 ms |
8560 KB |
Output is correct |
74 |
Correct |
431 ms |
1772 KB |
Output is correct |
75 |
Correct |
454 ms |
2028 KB |
Output is correct |
76 |
Correct |
440 ms |
2028 KB |
Output is correct |
77 |
Correct |
446 ms |
1908 KB |
Output is correct |
78 |
Correct |
485 ms |
1900 KB |
Output is correct |