#include<bits/stdc++.h>
using namespace std;
int mod=1e9+7;
const int maxn=501;
long long dp[maxn*2+10][maxn+2];
long long ps[maxn*2+10];
int rev[maxn+10];
pair<int,int>all[maxn+10];
vector<int>allind;
long long mypow(long long m,long long y){
if(y==0){
return 1;
}
long long p=mypow(m,(y>>1));
p*=p;
p%=mod;
if(y&1){
p*=m;
p%=mod;
}
return p;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
for(int i=0;i<=n+5;i++){
rev[i]=mypow(i,mod-2);
}
for(int i=1;i<=n;i++){
cin>>all[i].first>>all[i].second;
allind.push_back(all[i].second);
allind.push_back(all[i].first-1);
}
allind.push_back(0);
sort(allind.begin(),allind.end());
allind.resize(unique(allind.begin(),allind.end())-allind.begin());
int sz=(int)allind.size()+1;
dp[0][0]=1;
for(int i=0;i<sz+10;i++){
ps[i]=1;
}
for(int i=1;i<=n;i++){
int l=lower_bound(allind.begin(),allind.end(),all[i].first)-allind.begin();
int r=lower_bound(allind.begin(),allind.end(),all[i].second)-allind.begin();
for(int j=l;j<=r;j++){
int cnt=allind[j]-allind[j-1];
for(int h=n;h>=2;h--){
dp[j][h]=(dp[j][h]+dp[j][h-1]*(cnt-(h-1))%mod*rev[h])%mod;
}
dp[j][1]=(dp[j][1]+ps[j-1]*cnt)%mod;
}
ps[0]=dp[0][0];
for(int i=1;i<=sz+9;i++){
ps[i]=ps[i-1];
for(int h=0;h<=n;h++){
ps[i]+=dp[i][h];
}
ps[i]%=mod;
}
}
long long res=ps[sz+8];
res+=mod-1;
res%=mod;
cout<<res<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
4160 KB |
Output is correct |
2 |
Correct |
138 ms |
4204 KB |
Output is correct |
3 |
Correct |
129 ms |
4168 KB |
Output is correct |
4 |
Correct |
137 ms |
4216 KB |
Output is correct |
5 |
Correct |
140 ms |
4248 KB |
Output is correct |
6 |
Correct |
138 ms |
4172 KB |
Output is correct |
7 |
Correct |
133 ms |
4236 KB |
Output is correct |
8 |
Correct |
131 ms |
4180 KB |
Output is correct |
9 |
Correct |
127 ms |
4176 KB |
Output is correct |
10 |
Correct |
135 ms |
4252 KB |
Output is correct |
11 |
Correct |
138 ms |
4212 KB |
Output is correct |
12 |
Correct |
130 ms |
4252 KB |
Output is correct |
13 |
Correct |
150 ms |
4256 KB |
Output is correct |
14 |
Correct |
139 ms |
4256 KB |
Output is correct |
15 |
Correct |
152 ms |
4248 KB |
Output is correct |
16 |
Correct |
28 ms |
980 KB |
Output is correct |
17 |
Correct |
29 ms |
1056 KB |
Output is correct |
18 |
Correct |
28 ms |
1056 KB |
Output is correct |
19 |
Correct |
34 ms |
1064 KB |
Output is correct |
20 |
Correct |
31 ms |
1024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
4160 KB |
Output is correct |
2 |
Correct |
138 ms |
4204 KB |
Output is correct |
3 |
Correct |
129 ms |
4168 KB |
Output is correct |
4 |
Correct |
137 ms |
4216 KB |
Output is correct |
5 |
Correct |
140 ms |
4248 KB |
Output is correct |
6 |
Correct |
138 ms |
4172 KB |
Output is correct |
7 |
Correct |
133 ms |
4236 KB |
Output is correct |
8 |
Correct |
131 ms |
4180 KB |
Output is correct |
9 |
Correct |
127 ms |
4176 KB |
Output is correct |
10 |
Correct |
135 ms |
4252 KB |
Output is correct |
11 |
Correct |
138 ms |
4212 KB |
Output is correct |
12 |
Correct |
130 ms |
4252 KB |
Output is correct |
13 |
Correct |
150 ms |
4256 KB |
Output is correct |
14 |
Correct |
139 ms |
4256 KB |
Output is correct |
15 |
Correct |
152 ms |
4248 KB |
Output is correct |
16 |
Correct |
28 ms |
980 KB |
Output is correct |
17 |
Correct |
29 ms |
1056 KB |
Output is correct |
18 |
Correct |
28 ms |
1056 KB |
Output is correct |
19 |
Correct |
34 ms |
1064 KB |
Output is correct |
20 |
Correct |
31 ms |
1024 KB |
Output is correct |
21 |
Correct |
889 ms |
4044 KB |
Output is correct |
22 |
Correct |
886 ms |
3852 KB |
Output is correct |
23 |
Correct |
771 ms |
3960 KB |
Output is correct |
24 |
Correct |
802 ms |
3876 KB |
Output is correct |
25 |
Correct |
841 ms |
3868 KB |
Output is correct |
26 |
Correct |
1095 ms |
3796 KB |
Output is correct |
27 |
Correct |
1152 ms |
4008 KB |
Output is correct |
28 |
Correct |
1117 ms |
3768 KB |
Output is correct |
29 |
Correct |
1129 ms |
3656 KB |
Output is correct |
30 |
Correct |
128 ms |
4204 KB |
Output is correct |
31 |
Correct |
132 ms |
4156 KB |
Output is correct |
32 |
Correct |
130 ms |
4224 KB |
Output is correct |
33 |
Correct |
140 ms |
4168 KB |
Output is correct |
34 |
Correct |
133 ms |
4204 KB |
Output is correct |
35 |
Correct |
135 ms |
4220 KB |
Output is correct |
36 |
Correct |
132 ms |
4208 KB |
Output is correct |
37 |
Correct |
133 ms |
4172 KB |
Output is correct |
38 |
Correct |
135 ms |
4212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
1120 KB |
Output is correct |
2 |
Correct |
8 ms |
1108 KB |
Output is correct |
3 |
Correct |
9 ms |
1120 KB |
Output is correct |
4 |
Correct |
10 ms |
1108 KB |
Output is correct |
5 |
Correct |
10 ms |
1108 KB |
Output is correct |
6 |
Correct |
15 ms |
1076 KB |
Output is correct |
7 |
Correct |
14 ms |
1088 KB |
Output is correct |
8 |
Correct |
14 ms |
1108 KB |
Output is correct |
9 |
Correct |
14 ms |
1104 KB |
Output is correct |
10 |
Correct |
14 ms |
1124 KB |
Output is correct |
11 |
Correct |
11 ms |
1120 KB |
Output is correct |
12 |
Correct |
8 ms |
1108 KB |
Output is correct |
13 |
Correct |
10 ms |
1128 KB |
Output is correct |
14 |
Correct |
10 ms |
1108 KB |
Output is correct |
15 |
Correct |
10 ms |
1236 KB |
Output is correct |
16 |
Correct |
6 ms |
724 KB |
Output is correct |
17 |
Correct |
5 ms |
724 KB |
Output is correct |
18 |
Correct |
6 ms |
792 KB |
Output is correct |
19 |
Correct |
6 ms |
724 KB |
Output is correct |
20 |
Correct |
6 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
4160 KB |
Output is correct |
2 |
Correct |
138 ms |
4204 KB |
Output is correct |
3 |
Correct |
129 ms |
4168 KB |
Output is correct |
4 |
Correct |
137 ms |
4216 KB |
Output is correct |
5 |
Correct |
140 ms |
4248 KB |
Output is correct |
6 |
Correct |
138 ms |
4172 KB |
Output is correct |
7 |
Correct |
133 ms |
4236 KB |
Output is correct |
8 |
Correct |
131 ms |
4180 KB |
Output is correct |
9 |
Correct |
127 ms |
4176 KB |
Output is correct |
10 |
Correct |
135 ms |
4252 KB |
Output is correct |
11 |
Correct |
138 ms |
4212 KB |
Output is correct |
12 |
Correct |
130 ms |
4252 KB |
Output is correct |
13 |
Correct |
150 ms |
4256 KB |
Output is correct |
14 |
Correct |
139 ms |
4256 KB |
Output is correct |
15 |
Correct |
152 ms |
4248 KB |
Output is correct |
16 |
Correct |
28 ms |
980 KB |
Output is correct |
17 |
Correct |
29 ms |
1056 KB |
Output is correct |
18 |
Correct |
28 ms |
1056 KB |
Output is correct |
19 |
Correct |
34 ms |
1064 KB |
Output is correct |
20 |
Correct |
31 ms |
1024 KB |
Output is correct |
21 |
Correct |
889 ms |
4044 KB |
Output is correct |
22 |
Correct |
886 ms |
3852 KB |
Output is correct |
23 |
Correct |
771 ms |
3960 KB |
Output is correct |
24 |
Correct |
802 ms |
3876 KB |
Output is correct |
25 |
Correct |
841 ms |
3868 KB |
Output is correct |
26 |
Correct |
1095 ms |
3796 KB |
Output is correct |
27 |
Correct |
1152 ms |
4008 KB |
Output is correct |
28 |
Correct |
1117 ms |
3768 KB |
Output is correct |
29 |
Correct |
1129 ms |
3656 KB |
Output is correct |
30 |
Correct |
128 ms |
4204 KB |
Output is correct |
31 |
Correct |
132 ms |
4156 KB |
Output is correct |
32 |
Correct |
130 ms |
4224 KB |
Output is correct |
33 |
Correct |
140 ms |
4168 KB |
Output is correct |
34 |
Correct |
133 ms |
4204 KB |
Output is correct |
35 |
Correct |
135 ms |
4220 KB |
Output is correct |
36 |
Correct |
132 ms |
4208 KB |
Output is correct |
37 |
Correct |
133 ms |
4172 KB |
Output is correct |
38 |
Correct |
135 ms |
4212 KB |
Output is correct |
39 |
Correct |
10 ms |
1120 KB |
Output is correct |
40 |
Correct |
8 ms |
1108 KB |
Output is correct |
41 |
Correct |
9 ms |
1120 KB |
Output is correct |
42 |
Correct |
10 ms |
1108 KB |
Output is correct |
43 |
Correct |
10 ms |
1108 KB |
Output is correct |
44 |
Correct |
15 ms |
1076 KB |
Output is correct |
45 |
Correct |
14 ms |
1088 KB |
Output is correct |
46 |
Correct |
14 ms |
1108 KB |
Output is correct |
47 |
Correct |
14 ms |
1104 KB |
Output is correct |
48 |
Correct |
14 ms |
1124 KB |
Output is correct |
49 |
Correct |
11 ms |
1120 KB |
Output is correct |
50 |
Correct |
8 ms |
1108 KB |
Output is correct |
51 |
Correct |
10 ms |
1128 KB |
Output is correct |
52 |
Correct |
10 ms |
1108 KB |
Output is correct |
53 |
Correct |
10 ms |
1236 KB |
Output is correct |
54 |
Correct |
6 ms |
724 KB |
Output is correct |
55 |
Correct |
5 ms |
724 KB |
Output is correct |
56 |
Correct |
6 ms |
792 KB |
Output is correct |
57 |
Correct |
6 ms |
724 KB |
Output is correct |
58 |
Correct |
6 ms |
724 KB |
Output is correct |
59 |
Correct |
1040 ms |
4364 KB |
Output is correct |
60 |
Correct |
983 ms |
4380 KB |
Output is correct |
61 |
Correct |
974 ms |
4388 KB |
Output is correct |
62 |
Correct |
1042 ms |
4172 KB |
Output is correct |
63 |
Correct |
1000 ms |
4348 KB |
Output is correct |
64 |
Correct |
1534 ms |
4328 KB |
Output is correct |
65 |
Correct |
1533 ms |
4344 KB |
Output is correct |
66 |
Correct |
1557 ms |
4344 KB |
Output is correct |
67 |
Correct |
1536 ms |
4428 KB |
Output is correct |
68 |
Correct |
1521 ms |
4292 KB |
Output is correct |
69 |
Correct |
935 ms |
4268 KB |
Output is correct |
70 |
Correct |
995 ms |
4276 KB |
Output is correct |
71 |
Correct |
956 ms |
4400 KB |
Output is correct |
72 |
Correct |
989 ms |
4332 KB |
Output is correct |
73 |
Correct |
986 ms |
4272 KB |
Output is correct |
74 |
Correct |
192 ms |
980 KB |
Output is correct |
75 |
Correct |
181 ms |
1080 KB |
Output is correct |
76 |
Correct |
187 ms |
1080 KB |
Output is correct |
77 |
Correct |
194 ms |
1064 KB |
Output is correct |
78 |
Correct |
188 ms |
1052 KB |
Output is correct |