#include<bits/stdc++.h>
using namespace std;
int mod=1e9+7;
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 ww(int a){
if(a>=mod){
a-=mod;
}
return a;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
vector<long long>rev(n+6);
for(int i=0;i<=n+5;i++){
rev[i]=mypow(i,mod-2);
}
vector<pair<int,int>>all(n+1);
vector<int>allind;
for(int i=1;i<=n;i++){
cin>>all[i].first>>all[i].second;
allind.push_back(all[i].first);
allind.push_back(all[i].second);
allind.push_back(all[i].first+1);
allind.push_back(all[i].first-1);
allind.push_back(all[i].second+1);
allind.push_back(all[i].second-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;
vector<vector<long long>>dp(sz+10,vector<long long>(n+5));
vector<long long>ps(sz+10);
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++){
long long cnt=allind[j]-allind[j-1];
for(int h=n;h>=2;h--){
dp[j][h]+=dp[j][h-1]*(cnt-(h-1))%mod*rev[h]%mod;
dp[j][h]=ww(dp[j][h]);
}
dp[j][1]+=ps[j-1]*cnt%mod;
dp[j][1]=ww(dp[j][1]);
}
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";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
230 ms |
6356 KB |
Output is correct |
2 |
Correct |
226 ms |
6372 KB |
Output is correct |
3 |
Correct |
227 ms |
6368 KB |
Output is correct |
4 |
Correct |
229 ms |
6364 KB |
Output is correct |
5 |
Correct |
221 ms |
6356 KB |
Output is correct |
6 |
Correct |
220 ms |
6356 KB |
Output is correct |
7 |
Correct |
230 ms |
6356 KB |
Output is correct |
8 |
Correct |
226 ms |
6368 KB |
Output is correct |
9 |
Correct |
226 ms |
6368 KB |
Output is correct |
10 |
Correct |
225 ms |
6356 KB |
Output is correct |
11 |
Correct |
224 ms |
6368 KB |
Output is correct |
12 |
Correct |
221 ms |
6364 KB |
Output is correct |
13 |
Correct |
229 ms |
6384 KB |
Output is correct |
14 |
Correct |
216 ms |
6364 KB |
Output is correct |
15 |
Correct |
223 ms |
6356 KB |
Output is correct |
16 |
Correct |
41 ms |
1452 KB |
Output is correct |
17 |
Correct |
47 ms |
1492 KB |
Output is correct |
18 |
Correct |
42 ms |
1492 KB |
Output is correct |
19 |
Correct |
46 ms |
1492 KB |
Output is correct |
20 |
Correct |
44 ms |
1492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
230 ms |
6356 KB |
Output is correct |
2 |
Correct |
226 ms |
6372 KB |
Output is correct |
3 |
Correct |
227 ms |
6368 KB |
Output is correct |
4 |
Correct |
229 ms |
6364 KB |
Output is correct |
5 |
Correct |
221 ms |
6356 KB |
Output is correct |
6 |
Correct |
220 ms |
6356 KB |
Output is correct |
7 |
Correct |
230 ms |
6356 KB |
Output is correct |
8 |
Correct |
226 ms |
6368 KB |
Output is correct |
9 |
Correct |
226 ms |
6368 KB |
Output is correct |
10 |
Correct |
225 ms |
6356 KB |
Output is correct |
11 |
Correct |
224 ms |
6368 KB |
Output is correct |
12 |
Correct |
221 ms |
6364 KB |
Output is correct |
13 |
Correct |
229 ms |
6384 KB |
Output is correct |
14 |
Correct |
216 ms |
6364 KB |
Output is correct |
15 |
Correct |
223 ms |
6356 KB |
Output is correct |
16 |
Correct |
41 ms |
1452 KB |
Output is correct |
17 |
Correct |
47 ms |
1492 KB |
Output is correct |
18 |
Correct |
42 ms |
1492 KB |
Output is correct |
19 |
Correct |
46 ms |
1492 KB |
Output is correct |
20 |
Correct |
44 ms |
1492 KB |
Output is correct |
21 |
Execution timed out |
2068 ms |
9428 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
724 KB |
Output is correct |
2 |
Correct |
20 ms |
724 KB |
Output is correct |
3 |
Correct |
25 ms |
832 KB |
Output is correct |
4 |
Correct |
24 ms |
836 KB |
Output is correct |
5 |
Correct |
25 ms |
724 KB |
Output is correct |
6 |
Correct |
33 ms |
724 KB |
Output is correct |
7 |
Correct |
35 ms |
724 KB |
Output is correct |
8 |
Correct |
34 ms |
724 KB |
Output is correct |
9 |
Correct |
33 ms |
844 KB |
Output is correct |
10 |
Correct |
33 ms |
724 KB |
Output is correct |
11 |
Correct |
25 ms |
724 KB |
Output is correct |
12 |
Correct |
21 ms |
848 KB |
Output is correct |
13 |
Correct |
23 ms |
724 KB |
Output is correct |
14 |
Correct |
23 ms |
724 KB |
Output is correct |
15 |
Correct |
24 ms |
724 KB |
Output is correct |
16 |
Correct |
11 ms |
468 KB |
Output is correct |
17 |
Correct |
10 ms |
468 KB |
Output is correct |
18 |
Correct |
11 ms |
468 KB |
Output is correct |
19 |
Correct |
10 ms |
468 KB |
Output is correct |
20 |
Correct |
12 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
230 ms |
6356 KB |
Output is correct |
2 |
Correct |
226 ms |
6372 KB |
Output is correct |
3 |
Correct |
227 ms |
6368 KB |
Output is correct |
4 |
Correct |
229 ms |
6364 KB |
Output is correct |
5 |
Correct |
221 ms |
6356 KB |
Output is correct |
6 |
Correct |
220 ms |
6356 KB |
Output is correct |
7 |
Correct |
230 ms |
6356 KB |
Output is correct |
8 |
Correct |
226 ms |
6368 KB |
Output is correct |
9 |
Correct |
226 ms |
6368 KB |
Output is correct |
10 |
Correct |
225 ms |
6356 KB |
Output is correct |
11 |
Correct |
224 ms |
6368 KB |
Output is correct |
12 |
Correct |
221 ms |
6364 KB |
Output is correct |
13 |
Correct |
229 ms |
6384 KB |
Output is correct |
14 |
Correct |
216 ms |
6364 KB |
Output is correct |
15 |
Correct |
223 ms |
6356 KB |
Output is correct |
16 |
Correct |
41 ms |
1452 KB |
Output is correct |
17 |
Correct |
47 ms |
1492 KB |
Output is correct |
18 |
Correct |
42 ms |
1492 KB |
Output is correct |
19 |
Correct |
46 ms |
1492 KB |
Output is correct |
20 |
Correct |
44 ms |
1492 KB |
Output is correct |
21 |
Execution timed out |
2068 ms |
9428 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |