#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
#define all(x) x.begin() , x.end()
#define sze(x) (ll)(x.size())
typedef long long ll;
const ll maxn = 1e3 + 17 , md = 1e9 + 7;
ll tav(ll n , ll k){
ll res = 1;
while(k > 0){
if(k & 1){
res *= n; res %= md;
}
n *= n; n %= md;
k >>= 1;
}
return res;
}
ll l[maxn] , r[maxn] , w[maxn] , f[maxn][maxn] , dp[maxn][maxn] , pd[maxn];
vector<ll> v;
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll n;
cin>>n;
for(ll i = 0 ; i < n ; i++){
cin>>l[i]>>r[i]; l[i]--;
v.push_back(l[i]); v.push_back(r[i]);
}
sort(all(v));
v.resize(distance(v.begin() , unique(all(v))));
ll vs = sze(v);
for(ll i = 0 ; i < vs - 1 ; i++){
w[i] = v[i + 1] - v[i];
ll lm = min(w[i] , n);
for(ll j = 1 ; j <= lm ; j++){
f[i][j] = (w[i] - j + 1) * tav(j , md - 2) % md;
}
}
for(ll i = 0 ; i < n ; i++){
l[i] = lower_bound(all(v) , l[i]) - v.begin();
r[i] = lower_bound(all(v) , r[i]) - v.begin();
}
fill(pd , pd + vs - 1 , 1);
for(ll i = 0 ; i < n ; i++){
for(ll j = r[i] - 1 ; j >= l[i] ; j--){
ll h = 0 , lm = min(i , w[j]);
for(ll k = lm ; k > 1 ; k--){
ll o = dp[j][k - 1] * f[j][k] % md;
dp[j][k] += o; dp[j][k] -= (dp[j][k] <= md) * md;
h += o;
}
dp[j][1] += pd[j]; dp[j][1] -= (dp[j][1] >= md) * md;
h += pd[j];
for(ll k = j + 1 ; k < vs ; k++){
pd[k] += h; pd[k] %= md;
}
}
}
ll ans = pd[vs - 1];
cout<<ans<<'\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
8428 KB |
Output is correct |
2 |
Correct |
37 ms |
8228 KB |
Output is correct |
3 |
Correct |
39 ms |
8212 KB |
Output is correct |
4 |
Correct |
37 ms |
8268 KB |
Output is correct |
5 |
Correct |
38 ms |
8220 KB |
Output is correct |
6 |
Correct |
37 ms |
8264 KB |
Output is correct |
7 |
Correct |
35 ms |
8208 KB |
Output is correct |
8 |
Correct |
36 ms |
8236 KB |
Output is correct |
9 |
Correct |
36 ms |
8316 KB |
Output is correct |
10 |
Correct |
36 ms |
8272 KB |
Output is correct |
11 |
Correct |
37 ms |
8312 KB |
Output is correct |
12 |
Correct |
40 ms |
8320 KB |
Output is correct |
13 |
Correct |
36 ms |
8268 KB |
Output is correct |
14 |
Correct |
37 ms |
8268 KB |
Output is correct |
15 |
Correct |
36 ms |
8240 KB |
Output is correct |
16 |
Correct |
7 ms |
1748 KB |
Output is correct |
17 |
Correct |
8 ms |
1876 KB |
Output is correct |
18 |
Correct |
7 ms |
1740 KB |
Output is correct |
19 |
Correct |
7 ms |
1876 KB |
Output is correct |
20 |
Correct |
7 ms |
1748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
8428 KB |
Output is correct |
2 |
Correct |
37 ms |
8228 KB |
Output is correct |
3 |
Correct |
39 ms |
8212 KB |
Output is correct |
4 |
Correct |
37 ms |
8268 KB |
Output is correct |
5 |
Correct |
38 ms |
8220 KB |
Output is correct |
6 |
Correct |
37 ms |
8264 KB |
Output is correct |
7 |
Correct |
35 ms |
8208 KB |
Output is correct |
8 |
Correct |
36 ms |
8236 KB |
Output is correct |
9 |
Correct |
36 ms |
8316 KB |
Output is correct |
10 |
Correct |
36 ms |
8272 KB |
Output is correct |
11 |
Correct |
37 ms |
8312 KB |
Output is correct |
12 |
Correct |
40 ms |
8320 KB |
Output is correct |
13 |
Correct |
36 ms |
8268 KB |
Output is correct |
14 |
Correct |
37 ms |
8268 KB |
Output is correct |
15 |
Correct |
36 ms |
8240 KB |
Output is correct |
16 |
Correct |
7 ms |
1748 KB |
Output is correct |
17 |
Correct |
8 ms |
1876 KB |
Output is correct |
18 |
Correct |
7 ms |
1740 KB |
Output is correct |
19 |
Correct |
7 ms |
1876 KB |
Output is correct |
20 |
Correct |
7 ms |
1748 KB |
Output is correct |
21 |
Incorrect |
115 ms |
7732 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
2260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
8428 KB |
Output is correct |
2 |
Correct |
37 ms |
8228 KB |
Output is correct |
3 |
Correct |
39 ms |
8212 KB |
Output is correct |
4 |
Correct |
37 ms |
8268 KB |
Output is correct |
5 |
Correct |
38 ms |
8220 KB |
Output is correct |
6 |
Correct |
37 ms |
8264 KB |
Output is correct |
7 |
Correct |
35 ms |
8208 KB |
Output is correct |
8 |
Correct |
36 ms |
8236 KB |
Output is correct |
9 |
Correct |
36 ms |
8316 KB |
Output is correct |
10 |
Correct |
36 ms |
8272 KB |
Output is correct |
11 |
Correct |
37 ms |
8312 KB |
Output is correct |
12 |
Correct |
40 ms |
8320 KB |
Output is correct |
13 |
Correct |
36 ms |
8268 KB |
Output is correct |
14 |
Correct |
37 ms |
8268 KB |
Output is correct |
15 |
Correct |
36 ms |
8240 KB |
Output is correct |
16 |
Correct |
7 ms |
1748 KB |
Output is correct |
17 |
Correct |
8 ms |
1876 KB |
Output is correct |
18 |
Correct |
7 ms |
1740 KB |
Output is correct |
19 |
Correct |
7 ms |
1876 KB |
Output is correct |
20 |
Correct |
7 ms |
1748 KB |
Output is correct |
21 |
Incorrect |
115 ms |
7732 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |