#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
#define sz(x) int(x.size())
const ll mod = 1'000'000'007;
ll mul(ll a, ll b)
{
return (a*b) % mod;
}
ll ad(ll a, ll b)
{
return (a+b) % mod;
}
ll sq(ll a)
{
return mul(a,a);
}
ll pow(ll b, ll e)
{
if(e == 0) return 1;
else if(e % 2 == 1) return mul(b, pow(b, e-1));
else return sq(pow(b, e/2));
}
ll get_inv(ll a)
{
return pow(a, mod-2);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N;
cin >> N;
ll a[1+N], b[1+N];
map<ll, ll> values;
for(int i = 1; i <= N; i++)
{
cin >> a[i] >> b[i];
b[i]++;
values[a[i]] = 0;
values[b[i]] = 0;
}
values[0] = 0;
values[1] = 0;
vll ep;
for(auto& z : values) ep.push_back(z.first);
int ct = sz(ep) - 1;
vll blocksize(1+ct);
blocksize[0] = 0;
for(int i = 1; i <= ct; i++)
blocksize[i] = ep[i] - ep[i-1];
int x[1+N], y[1+N];
// for(int i = 0; i <= ct; i++) cerr << i << " : " << ep[i] << ' ' << blocksize[i] << '\n';
for(int i = 1; i <= N; i++)
{
x[i] = 0;
int lo = 1, hi = ct;
while(lo != hi)
{
int mid = (lo+hi)/2 + 1;
if(ep[mid] <= a[i])
lo = mid;
else
hi = mid-1;
}
x[i] = lo + 1;
y[i] = 0;
lo = 1, hi = ct;
while(lo != hi)
{
int mid = (lo+hi)/2+1;
if(ep[mid] <= b[i])
lo = mid;
else
hi = mid-1;
}
y[i] = lo;
}
ll*** DP = new ll**[1+N];
for(int i = 0; i <= N; i++)
{
if(i <= 1)
{
DP[i] = new ll*[1+ct];
for(int j = 0; j <= ct; j++)
{
DP[i][j] = new ll[1+N];
for(int k = 0; k <= N; k++) DP[i][j][k] = 0;
}
}
else DP[i] = DP[i-2];
}
ll inv[1+N];
for(int i = 1; i <= N; i++) inv[i] = get_inv(i);
vvll DPsum(1+N, vll(1+ct, 0));
// cerr << "!" << x[1] << ' ' << y[1] << '\n';
for(int j = x[1]; j <= y[1]; j++)
{
DPsum[1][j] = ad(DPsum[1][j], blocksize[j]);
DP[1][j][1] = blocksize[j];
}
for(int i = 2; i <= N; i++)
{
ll ds[1+ct];
ds[0] = 0;
for(int j = 1; j <= ct; j++) ds[j] = ad(ds[j-1], DPsum[i-1][j]);
for(int j = 1; j <= ct; j++)
{
for(int k = 1; k <= i; k++)
{
DP[i][j][k] = DP[i-1][j][k];
if(x[i] <= j && j <= y[i])
{
if(j == 1 && k == 1)
{
;//DP[i][1][1] = blocksize[j] *
}
else if(j == 1)
{
;
}
else if(k == 1)
{
ll curr = ad(1, ds[j-1]);
DP[i][j][1] = ad(DP[i][j][1], mul(curr, blocksize[j]));
}
else
{
if(k <= blocksize[j])
DP[i][j][k] = ad(DP[i][j][k], mul(DP[i-1][j][k-1], mul(blocksize[j] - k + 1, inv[k])));
}
}
DPsum[i][j] = ad(DPsum[i][j], DP[i][j][k]);
}
}
}
ll res = 0;
for(int j = 1; j <= ct; j++)
res = ad(res, DPsum[N][j]);
cout << res << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
780 ms |
12252 KB |
Output is correct |
2 |
Correct |
787 ms |
12244 KB |
Output is correct |
3 |
Correct |
788 ms |
12356 KB |
Output is correct |
4 |
Correct |
797 ms |
12264 KB |
Output is correct |
5 |
Correct |
799 ms |
12244 KB |
Output is correct |
6 |
Correct |
798 ms |
12248 KB |
Output is correct |
7 |
Correct |
825 ms |
12252 KB |
Output is correct |
8 |
Correct |
798 ms |
12288 KB |
Output is correct |
9 |
Correct |
794 ms |
12356 KB |
Output is correct |
10 |
Correct |
806 ms |
12252 KB |
Output is correct |
11 |
Correct |
803 ms |
12248 KB |
Output is correct |
12 |
Correct |
786 ms |
12248 KB |
Output is correct |
13 |
Correct |
782 ms |
12244 KB |
Output is correct |
14 |
Correct |
803 ms |
12248 KB |
Output is correct |
15 |
Correct |
814 ms |
12244 KB |
Output is correct |
16 |
Correct |
140 ms |
2504 KB |
Output is correct |
17 |
Correct |
153 ms |
2508 KB |
Output is correct |
18 |
Correct |
143 ms |
2516 KB |
Output is correct |
19 |
Correct |
152 ms |
2616 KB |
Output is correct |
20 |
Correct |
147 ms |
2540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
780 ms |
12252 KB |
Output is correct |
2 |
Correct |
787 ms |
12244 KB |
Output is correct |
3 |
Correct |
788 ms |
12356 KB |
Output is correct |
4 |
Correct |
797 ms |
12264 KB |
Output is correct |
5 |
Correct |
799 ms |
12244 KB |
Output is correct |
6 |
Correct |
798 ms |
12248 KB |
Output is correct |
7 |
Correct |
825 ms |
12252 KB |
Output is correct |
8 |
Correct |
798 ms |
12288 KB |
Output is correct |
9 |
Correct |
794 ms |
12356 KB |
Output is correct |
10 |
Correct |
806 ms |
12252 KB |
Output is correct |
11 |
Correct |
803 ms |
12248 KB |
Output is correct |
12 |
Correct |
786 ms |
12248 KB |
Output is correct |
13 |
Correct |
782 ms |
12244 KB |
Output is correct |
14 |
Correct |
803 ms |
12248 KB |
Output is correct |
15 |
Correct |
814 ms |
12244 KB |
Output is correct |
16 |
Correct |
140 ms |
2504 KB |
Output is correct |
17 |
Correct |
153 ms |
2508 KB |
Output is correct |
18 |
Correct |
143 ms |
2516 KB |
Output is correct |
19 |
Correct |
152 ms |
2616 KB |
Output is correct |
20 |
Correct |
147 ms |
2540 KB |
Output is correct |
21 |
Correct |
726 ms |
11212 KB |
Output is correct |
22 |
Correct |
742 ms |
11340 KB |
Output is correct |
23 |
Correct |
737 ms |
11136 KB |
Output is correct |
24 |
Correct |
733 ms |
11068 KB |
Output is correct |
25 |
Correct |
722 ms |
11116 KB |
Output is correct |
26 |
Correct |
704 ms |
10828 KB |
Output is correct |
27 |
Correct |
706 ms |
10996 KB |
Output is correct |
28 |
Correct |
697 ms |
10792 KB |
Output is correct |
29 |
Correct |
700 ms |
10748 KB |
Output is correct |
30 |
Correct |
789 ms |
12108 KB |
Output is correct |
31 |
Correct |
799 ms |
12356 KB |
Output is correct |
32 |
Correct |
802 ms |
12208 KB |
Output is correct |
33 |
Correct |
792 ms |
12236 KB |
Output is correct |
34 |
Correct |
797 ms |
12204 KB |
Output is correct |
35 |
Correct |
790 ms |
12204 KB |
Output is correct |
36 |
Correct |
803 ms |
12204 KB |
Output is correct |
37 |
Correct |
815 ms |
12208 KB |
Output is correct |
38 |
Correct |
845 ms |
12196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
716 KB |
Output is correct |
2 |
Correct |
8 ms |
812 KB |
Output is correct |
3 |
Correct |
7 ms |
716 KB |
Output is correct |
4 |
Correct |
8 ms |
716 KB |
Output is correct |
5 |
Correct |
8 ms |
780 KB |
Output is correct |
6 |
Correct |
9 ms |
716 KB |
Output is correct |
7 |
Correct |
8 ms |
716 KB |
Output is correct |
8 |
Correct |
10 ms |
784 KB |
Output is correct |
9 |
Correct |
8 ms |
716 KB |
Output is correct |
10 |
Correct |
8 ms |
716 KB |
Output is correct |
11 |
Correct |
9 ms |
816 KB |
Output is correct |
12 |
Correct |
8 ms |
716 KB |
Output is correct |
13 |
Correct |
10 ms |
716 KB |
Output is correct |
14 |
Correct |
9 ms |
776 KB |
Output is correct |
15 |
Correct |
8 ms |
716 KB |
Output is correct |
16 |
Correct |
5 ms |
604 KB |
Output is correct |
17 |
Correct |
5 ms |
600 KB |
Output is correct |
18 |
Correct |
6 ms |
588 KB |
Output is correct |
19 |
Correct |
4 ms |
588 KB |
Output is correct |
20 |
Correct |
5 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
780 ms |
12252 KB |
Output is correct |
2 |
Correct |
787 ms |
12244 KB |
Output is correct |
3 |
Correct |
788 ms |
12356 KB |
Output is correct |
4 |
Correct |
797 ms |
12264 KB |
Output is correct |
5 |
Correct |
799 ms |
12244 KB |
Output is correct |
6 |
Correct |
798 ms |
12248 KB |
Output is correct |
7 |
Correct |
825 ms |
12252 KB |
Output is correct |
8 |
Correct |
798 ms |
12288 KB |
Output is correct |
9 |
Correct |
794 ms |
12356 KB |
Output is correct |
10 |
Correct |
806 ms |
12252 KB |
Output is correct |
11 |
Correct |
803 ms |
12248 KB |
Output is correct |
12 |
Correct |
786 ms |
12248 KB |
Output is correct |
13 |
Correct |
782 ms |
12244 KB |
Output is correct |
14 |
Correct |
803 ms |
12248 KB |
Output is correct |
15 |
Correct |
814 ms |
12244 KB |
Output is correct |
16 |
Correct |
140 ms |
2504 KB |
Output is correct |
17 |
Correct |
153 ms |
2508 KB |
Output is correct |
18 |
Correct |
143 ms |
2516 KB |
Output is correct |
19 |
Correct |
152 ms |
2616 KB |
Output is correct |
20 |
Correct |
147 ms |
2540 KB |
Output is correct |
21 |
Correct |
726 ms |
11212 KB |
Output is correct |
22 |
Correct |
742 ms |
11340 KB |
Output is correct |
23 |
Correct |
737 ms |
11136 KB |
Output is correct |
24 |
Correct |
733 ms |
11068 KB |
Output is correct |
25 |
Correct |
722 ms |
11116 KB |
Output is correct |
26 |
Correct |
704 ms |
10828 KB |
Output is correct |
27 |
Correct |
706 ms |
10996 KB |
Output is correct |
28 |
Correct |
697 ms |
10792 KB |
Output is correct |
29 |
Correct |
700 ms |
10748 KB |
Output is correct |
30 |
Correct |
789 ms |
12108 KB |
Output is correct |
31 |
Correct |
799 ms |
12356 KB |
Output is correct |
32 |
Correct |
802 ms |
12208 KB |
Output is correct |
33 |
Correct |
792 ms |
12236 KB |
Output is correct |
34 |
Correct |
797 ms |
12204 KB |
Output is correct |
35 |
Correct |
790 ms |
12204 KB |
Output is correct |
36 |
Correct |
803 ms |
12204 KB |
Output is correct |
37 |
Correct |
815 ms |
12208 KB |
Output is correct |
38 |
Correct |
845 ms |
12196 KB |
Output is correct |
39 |
Correct |
7 ms |
716 KB |
Output is correct |
40 |
Correct |
8 ms |
812 KB |
Output is correct |
41 |
Correct |
7 ms |
716 KB |
Output is correct |
42 |
Correct |
8 ms |
716 KB |
Output is correct |
43 |
Correct |
8 ms |
780 KB |
Output is correct |
44 |
Correct |
9 ms |
716 KB |
Output is correct |
45 |
Correct |
8 ms |
716 KB |
Output is correct |
46 |
Correct |
10 ms |
784 KB |
Output is correct |
47 |
Correct |
8 ms |
716 KB |
Output is correct |
48 |
Correct |
8 ms |
716 KB |
Output is correct |
49 |
Correct |
9 ms |
816 KB |
Output is correct |
50 |
Correct |
8 ms |
716 KB |
Output is correct |
51 |
Correct |
10 ms |
716 KB |
Output is correct |
52 |
Correct |
9 ms |
776 KB |
Output is correct |
53 |
Correct |
8 ms |
716 KB |
Output is correct |
54 |
Correct |
5 ms |
604 KB |
Output is correct |
55 |
Correct |
5 ms |
600 KB |
Output is correct |
56 |
Correct |
6 ms |
588 KB |
Output is correct |
57 |
Correct |
4 ms |
588 KB |
Output is correct |
58 |
Correct |
5 ms |
588 KB |
Output is correct |
59 |
Correct |
993 ms |
12248 KB |
Output is correct |
60 |
Correct |
1033 ms |
12244 KB |
Output is correct |
61 |
Correct |
970 ms |
12244 KB |
Output is correct |
62 |
Correct |
1018 ms |
12248 KB |
Output is correct |
63 |
Correct |
1008 ms |
12248 KB |
Output is correct |
64 |
Correct |
1000 ms |
12248 KB |
Output is correct |
65 |
Correct |
980 ms |
12244 KB |
Output is correct |
66 |
Correct |
972 ms |
12244 KB |
Output is correct |
67 |
Correct |
978 ms |
12356 KB |
Output is correct |
68 |
Correct |
978 ms |
12244 KB |
Output is correct |
69 |
Correct |
896 ms |
12236 KB |
Output is correct |
70 |
Correct |
880 ms |
12244 KB |
Output is correct |
71 |
Correct |
882 ms |
12260 KB |
Output is correct |
72 |
Correct |
916 ms |
12248 KB |
Output is correct |
73 |
Correct |
918 ms |
12240 KB |
Output is correct |
74 |
Correct |
158 ms |
2488 KB |
Output is correct |
75 |
Correct |
159 ms |
2508 KB |
Output is correct |
76 |
Correct |
156 ms |
2544 KB |
Output is correct |
77 |
Correct |
158 ms |
2524 KB |
Output is correct |
78 |
Correct |
156 ms |
2508 KB |
Output is correct |