#include<bits/stdc++.h>
using namespace std;
#define int long long
#define in array<int, 2>
#define pb push_back
#define pob pop_back
#define INF (int)1e17
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL)
const int mod = 1e9+7;
const int MX = 5e3+5;
int inv[MX];
int dp[MX][2*MX];
int ans[2*MX];
int R[MX][2*MX];
int C[MX][2*MX];
void pre()
{
inv[1] = 1;
for(int i = 2; i < MX; i++)
{
inv[i] = (-(mod/i)*inv[mod%i])%mod; inv[i]+=mod;
inv[i]%=mod;
}
}
int solve(int a, int b, int c, int d)
{
int cnt = b+d-a-c;
for(int i = a; i < b; i++)
{
for(int j = c; j < d; j++)
{
if(i < j)
cnt++;
}
}
return cnt;
}
signed main()
{
fast();
pre();
vector<int> v;
int n;
cin >> n;
n++;
vector<in> a(n+1);
for(int i = 1; i < n; i++)
{
cin >> a[i][0] >> a[i][1];
v.pb(a[i][0]); v.pb(++a[i][1]);
}
a[n][0] = 1e9+1; a[n][1] = 1e9+2;
v.pb(a[n][0]); v.pb(a[n][1]);
sort(v.begin(), v.end());
vector<int> CC; CC.pb(v[0]);
for(auto x: v)
{
if(x != CC.back())
CC.pb(x);
}
int M = CC.size();
for(int i = 0; i < M-1; i++)
{
C[0][i] = 1; int tm = CC[i+1]-CC[i];
for(int j = 1; j <= n; j++)
{
if(j > tm)
break;
C[j][i] = C[j-1][i]*(tm-j+1); C[j][i]%=mod;
C[j][i]*=inv[j]; C[j][i]%=mod;
}
//for(int j = 0; j <= n; j++)
// cout << C[j][i] << " ";
//cout << "\n";
}
for(int i = 1; i <= n; i++)
{
a[i][0] = lower_bound(CC.begin(), CC.end(), a[i][0])-CC.begin();
a[i][1] = lower_bound(CC.begin(), CC.end(), a[i][1])-CC.begin();
}
for(int i = 0; i < M; i++)
R[0][i] = ans[i] = 1;
//cout << endl;
for(int i = 1; i <= n; i++)
{
//cout << "Currently processing i = " << i << endl;
for(int j = a[i][0]; j < a[i][1]; j++)
{
//R[L][j] = number of ways to do stuff if picking L things from jth bracket.
//cout << "Bracket range = [" << CC[j] << ", " << CC[j+1] << ")" << endl;
for(int L = 0; L < i; L++)
{
//cout << "If we pick L = " << L << " things in the current (" << j << ") bracket, we have: " << endl;
//cout << R[L][j] << endl;
dp[i][j]+=((R[L][j]*C[L+1][j])%mod);
}
dp[i][j]%=mod;
for(int T = j; T < M-1; T++)
{
ans[T]+=dp[i][j];
ans[T]%=mod;
}
//cout << "For j, computed: " << dp[i][j] << endl;
//Currently working in intervl [CC[j], CC[j+1])
}
for(int j = a[i][0]; j < a[i][1]; j++)
{
//how does R[L][j] change?
for(int L = i; L >= 1; L--)
{
R[L][j]+=R[L-1][j];
R[L][j]%=mod;
}
}
for(int j = 1; j < M-1; j++)
R[0][j] = ans[j-1];
}
dp[n][M-2]+=(mod-1); dp[n][M-2]%=mod;
cout << dp[n][M-2] << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
53340 KB |
Output is correct |
2 |
Correct |
13 ms |
53336 KB |
Output is correct |
3 |
Correct |
14 ms |
53340 KB |
Output is correct |
4 |
Correct |
14 ms |
53248 KB |
Output is correct |
5 |
Correct |
14 ms |
53340 KB |
Output is correct |
6 |
Correct |
12 ms |
52060 KB |
Output is correct |
7 |
Correct |
13 ms |
52060 KB |
Output is correct |
8 |
Correct |
13 ms |
52568 KB |
Output is correct |
9 |
Correct |
15 ms |
52572 KB |
Output is correct |
10 |
Correct |
14 ms |
52572 KB |
Output is correct |
11 |
Correct |
12 ms |
52312 KB |
Output is correct |
12 |
Correct |
14 ms |
53112 KB |
Output is correct |
13 |
Correct |
13 ms |
52572 KB |
Output is correct |
14 |
Correct |
12 ms |
52056 KB |
Output is correct |
15 |
Correct |
13 ms |
52572 KB |
Output is correct |
16 |
Correct |
9 ms |
50264 KB |
Output is correct |
17 |
Correct |
9 ms |
50264 KB |
Output is correct |
18 |
Correct |
9 ms |
50264 KB |
Output is correct |
19 |
Correct |
9 ms |
50296 KB |
Output is correct |
20 |
Correct |
9 ms |
50268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
53340 KB |
Output is correct |
2 |
Correct |
13 ms |
53336 KB |
Output is correct |
3 |
Correct |
14 ms |
53340 KB |
Output is correct |
4 |
Correct |
14 ms |
53248 KB |
Output is correct |
5 |
Correct |
14 ms |
53340 KB |
Output is correct |
6 |
Correct |
12 ms |
52060 KB |
Output is correct |
7 |
Correct |
13 ms |
52060 KB |
Output is correct |
8 |
Correct |
13 ms |
52568 KB |
Output is correct |
9 |
Correct |
15 ms |
52572 KB |
Output is correct |
10 |
Correct |
14 ms |
52572 KB |
Output is correct |
11 |
Correct |
12 ms |
52312 KB |
Output is correct |
12 |
Correct |
14 ms |
53112 KB |
Output is correct |
13 |
Correct |
13 ms |
52572 KB |
Output is correct |
14 |
Correct |
12 ms |
52056 KB |
Output is correct |
15 |
Correct |
13 ms |
52572 KB |
Output is correct |
16 |
Correct |
9 ms |
50264 KB |
Output is correct |
17 |
Correct |
9 ms |
50264 KB |
Output is correct |
18 |
Correct |
9 ms |
50264 KB |
Output is correct |
19 |
Correct |
9 ms |
50296 KB |
Output is correct |
20 |
Correct |
9 ms |
50268 KB |
Output is correct |
21 |
Correct |
248 ms |
54096 KB |
Output is correct |
22 |
Correct |
241 ms |
54160 KB |
Output is correct |
23 |
Correct |
219 ms |
54100 KB |
Output is correct |
24 |
Correct |
228 ms |
54064 KB |
Output is correct |
25 |
Correct |
229 ms |
54352 KB |
Output is correct |
26 |
Correct |
318 ms |
53848 KB |
Output is correct |
27 |
Correct |
333 ms |
54356 KB |
Output is correct |
28 |
Correct |
317 ms |
54224 KB |
Output is correct |
29 |
Correct |
313 ms |
54104 KB |
Output is correct |
30 |
Correct |
15 ms |
52828 KB |
Output is correct |
31 |
Correct |
16 ms |
52828 KB |
Output is correct |
32 |
Correct |
15 ms |
52572 KB |
Output is correct |
33 |
Correct |
15 ms |
52524 KB |
Output is correct |
34 |
Correct |
15 ms |
52568 KB |
Output is correct |
35 |
Correct |
16 ms |
53128 KB |
Output is correct |
36 |
Correct |
16 ms |
53248 KB |
Output is correct |
37 |
Correct |
16 ms |
53340 KB |
Output is correct |
38 |
Correct |
16 ms |
53336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
13404 KB |
Output is correct |
2 |
Correct |
4 ms |
13400 KB |
Output is correct |
3 |
Correct |
4 ms |
13400 KB |
Output is correct |
4 |
Correct |
5 ms |
13404 KB |
Output is correct |
5 |
Correct |
5 ms |
13404 KB |
Output is correct |
6 |
Correct |
5 ms |
13404 KB |
Output is correct |
7 |
Correct |
5 ms |
13404 KB |
Output is correct |
8 |
Correct |
6 ms |
13404 KB |
Output is correct |
9 |
Correct |
5 ms |
13660 KB |
Output is correct |
10 |
Correct |
5 ms |
13596 KB |
Output is correct |
11 |
Correct |
4 ms |
13400 KB |
Output is correct |
12 |
Correct |
4 ms |
13400 KB |
Output is correct |
13 |
Correct |
4 ms |
13404 KB |
Output is correct |
14 |
Correct |
4 ms |
13400 KB |
Output is correct |
15 |
Correct |
4 ms |
13404 KB |
Output is correct |
16 |
Correct |
4 ms |
13400 KB |
Output is correct |
17 |
Correct |
3 ms |
13404 KB |
Output is correct |
18 |
Correct |
3 ms |
13404 KB |
Output is correct |
19 |
Correct |
3 ms |
13404 KB |
Output is correct |
20 |
Correct |
3 ms |
13404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
53340 KB |
Output is correct |
2 |
Correct |
13 ms |
53336 KB |
Output is correct |
3 |
Correct |
14 ms |
53340 KB |
Output is correct |
4 |
Correct |
14 ms |
53248 KB |
Output is correct |
5 |
Correct |
14 ms |
53340 KB |
Output is correct |
6 |
Correct |
12 ms |
52060 KB |
Output is correct |
7 |
Correct |
13 ms |
52060 KB |
Output is correct |
8 |
Correct |
13 ms |
52568 KB |
Output is correct |
9 |
Correct |
15 ms |
52572 KB |
Output is correct |
10 |
Correct |
14 ms |
52572 KB |
Output is correct |
11 |
Correct |
12 ms |
52312 KB |
Output is correct |
12 |
Correct |
14 ms |
53112 KB |
Output is correct |
13 |
Correct |
13 ms |
52572 KB |
Output is correct |
14 |
Correct |
12 ms |
52056 KB |
Output is correct |
15 |
Correct |
13 ms |
52572 KB |
Output is correct |
16 |
Correct |
9 ms |
50264 KB |
Output is correct |
17 |
Correct |
9 ms |
50264 KB |
Output is correct |
18 |
Correct |
9 ms |
50264 KB |
Output is correct |
19 |
Correct |
9 ms |
50296 KB |
Output is correct |
20 |
Correct |
9 ms |
50268 KB |
Output is correct |
21 |
Correct |
248 ms |
54096 KB |
Output is correct |
22 |
Correct |
241 ms |
54160 KB |
Output is correct |
23 |
Correct |
219 ms |
54100 KB |
Output is correct |
24 |
Correct |
228 ms |
54064 KB |
Output is correct |
25 |
Correct |
229 ms |
54352 KB |
Output is correct |
26 |
Correct |
318 ms |
53848 KB |
Output is correct |
27 |
Correct |
333 ms |
54356 KB |
Output is correct |
28 |
Correct |
317 ms |
54224 KB |
Output is correct |
29 |
Correct |
313 ms |
54104 KB |
Output is correct |
30 |
Correct |
15 ms |
52828 KB |
Output is correct |
31 |
Correct |
16 ms |
52828 KB |
Output is correct |
32 |
Correct |
15 ms |
52572 KB |
Output is correct |
33 |
Correct |
15 ms |
52524 KB |
Output is correct |
34 |
Correct |
15 ms |
52568 KB |
Output is correct |
35 |
Correct |
16 ms |
53128 KB |
Output is correct |
36 |
Correct |
16 ms |
53248 KB |
Output is correct |
37 |
Correct |
16 ms |
53340 KB |
Output is correct |
38 |
Correct |
16 ms |
53336 KB |
Output is correct |
39 |
Correct |
4 ms |
13404 KB |
Output is correct |
40 |
Correct |
4 ms |
13400 KB |
Output is correct |
41 |
Correct |
4 ms |
13400 KB |
Output is correct |
42 |
Correct |
5 ms |
13404 KB |
Output is correct |
43 |
Correct |
5 ms |
13404 KB |
Output is correct |
44 |
Correct |
5 ms |
13404 KB |
Output is correct |
45 |
Correct |
5 ms |
13404 KB |
Output is correct |
46 |
Correct |
6 ms |
13404 KB |
Output is correct |
47 |
Correct |
5 ms |
13660 KB |
Output is correct |
48 |
Correct |
5 ms |
13596 KB |
Output is correct |
49 |
Correct |
4 ms |
13400 KB |
Output is correct |
50 |
Correct |
4 ms |
13400 KB |
Output is correct |
51 |
Correct |
4 ms |
13404 KB |
Output is correct |
52 |
Correct |
4 ms |
13400 KB |
Output is correct |
53 |
Correct |
4 ms |
13404 KB |
Output is correct |
54 |
Correct |
4 ms |
13400 KB |
Output is correct |
55 |
Correct |
3 ms |
13404 KB |
Output is correct |
56 |
Correct |
3 ms |
13404 KB |
Output is correct |
57 |
Correct |
3 ms |
13404 KB |
Output is correct |
58 |
Correct |
3 ms |
13404 KB |
Output is correct |
59 |
Correct |
268 ms |
54612 KB |
Output is correct |
60 |
Correct |
256 ms |
54612 KB |
Output is correct |
61 |
Correct |
248 ms |
54844 KB |
Output is correct |
62 |
Correct |
273 ms |
54568 KB |
Output is correct |
63 |
Correct |
266 ms |
54612 KB |
Output is correct |
64 |
Correct |
382 ms |
54664 KB |
Output is correct |
65 |
Correct |
401 ms |
54612 KB |
Output is correct |
66 |
Correct |
386 ms |
54868 KB |
Output is correct |
67 |
Correct |
383 ms |
54864 KB |
Output is correct |
68 |
Correct |
401 ms |
54868 KB |
Output is correct |
69 |
Correct |
228 ms |
54080 KB |
Output is correct |
70 |
Correct |
227 ms |
54096 KB |
Output is correct |
71 |
Correct |
219 ms |
53844 KB |
Output is correct |
72 |
Correct |
233 ms |
54360 KB |
Output is correct |
73 |
Correct |
233 ms |
53804 KB |
Output is correct |
74 |
Correct |
41 ms |
50512 KB |
Output is correct |
75 |
Correct |
42 ms |
50512 KB |
Output is correct |
76 |
Correct |
45 ms |
50372 KB |
Output is correct |
77 |
Correct |
41 ms |
50584 KB |
Output is correct |
78 |
Correct |
43 ms |
50516 KB |
Output is correct |