/*#pragma GCC optimize("Ofast,unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")*/
/*#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma")*/
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
using ld=long double;
using pll=pair<ll,ll>;
using pii=pair<int,int>;
using point=complex<double>;
#define F first
#define S second
//#define X real()
//#define Y imag()
#define pb push_back
#define mp make_pair
#define lc v<<1
#define rc v<<1|1
#define fast_io ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#define kill(x) cout << x << '\n';exit(0)
#define killshayan kill("done!")
#define killmashtali kill("Hello, World!")
const int N=1e3+10,LN=18,M=1e6+10,SQ=700,BS=737,inf=1.05e9,NSQ=N/SQ+3;
const ll INF=1e18;
const double pi=acos(-1);
const ld ep=1e-7;
const int MH=1000696969,MD=998244353,MOD=1000000007;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pii, null_type,greater<pii>, rb_tree_tag,tree_order_statistics_node_update>
ll pow(ll x, ll y, ll mod){
ll ans=1;
while (y != 0) {
if (y & 1) ans = ans * x % mod;
y >>= 1;
x = x * x % mod;
}
return ans;
}
ll n,k,l[N],r[N],dp[N*2][N],iv[N],wtf[N][N];
vector<ll> cp={0,inf};
int main(){
fast_io;
cin >> n;
for(ll i=1; i<=n; i++) iv[i]=pow(i,MOD-2,MOD);
for(ll i=1; i<=n; i++){
cin >> l[i] >> r[i];
r[i]++;
cp.pb(l[i]);
cp.pb(r[i]);
}
sort(cp.begin(),cp.end());
cp.resize(unique(cp.begin(),cp.end())-cp.begin());
for(ll i=1; i<=n; i++){
l[i]=lower_bound(cp.begin(),cp.end(),l[i])-cp.begin();
r[i]=lower_bound(cp.begin(),cp.end(),r[i])-cp.begin();
}
k=cp.size()-2;
for(ll i=0; i<k; i++){
wtf[i][0]=1;
ll sz=cp[i+1]-cp[i];
for(ll j=1; j<=n; j++){
if(!sz) break;
wtf[i][j]=wtf[i][j-1]*sz%MOD*iv[j]%MOD;
sz--;
}
}
for(ll i=0; i<=k; i++) dp[i][0]=1;
for(ll i=1; i<=n; i++){
for(ll j=1; j<=k; j++){
for(ll x=n; x; x--){
if(j>=l[i] && j<r[i]){
dp[j][x]=dp[j][x]+dp[j][x-1];
if(dp[j][x]>MOD) dp[j][x]-=MOD;
}
}
dp[j][0]=dp[j-1][0];
for(ll x=1; x<=n; x++){
dp[j][0]=(dp[j][0]+dp[j-1][x]*wtf[j-1][x])%MOD;
}
}
}
cout << dp[k][0]-1 << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1408 ms |
12388 KB |
Output is correct |
2 |
Correct |
1388 ms |
12376 KB |
Output is correct |
3 |
Correct |
1343 ms |
12308 KB |
Output is correct |
4 |
Correct |
1346 ms |
12264 KB |
Output is correct |
5 |
Correct |
1365 ms |
12284 KB |
Output is correct |
6 |
Correct |
1361 ms |
12300 KB |
Output is correct |
7 |
Correct |
1349 ms |
12200 KB |
Output is correct |
8 |
Correct |
1362 ms |
12292 KB |
Output is correct |
9 |
Correct |
1337 ms |
12392 KB |
Output is correct |
10 |
Correct |
1395 ms |
12348 KB |
Output is correct |
11 |
Correct |
1339 ms |
12256 KB |
Output is correct |
12 |
Correct |
1345 ms |
12312 KB |
Output is correct |
13 |
Correct |
1367 ms |
12280 KB |
Output is correct |
14 |
Correct |
1352 ms |
12168 KB |
Output is correct |
15 |
Correct |
1338 ms |
12436 KB |
Output is correct |
16 |
Correct |
235 ms |
2516 KB |
Output is correct |
17 |
Correct |
249 ms |
2688 KB |
Output is correct |
18 |
Correct |
238 ms |
2440 KB |
Output is correct |
19 |
Correct |
252 ms |
2716 KB |
Output is correct |
20 |
Correct |
244 ms |
2516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1408 ms |
12388 KB |
Output is correct |
2 |
Correct |
1388 ms |
12376 KB |
Output is correct |
3 |
Correct |
1343 ms |
12308 KB |
Output is correct |
4 |
Correct |
1346 ms |
12264 KB |
Output is correct |
5 |
Correct |
1365 ms |
12284 KB |
Output is correct |
6 |
Correct |
1361 ms |
12300 KB |
Output is correct |
7 |
Correct |
1349 ms |
12200 KB |
Output is correct |
8 |
Correct |
1362 ms |
12292 KB |
Output is correct |
9 |
Correct |
1337 ms |
12392 KB |
Output is correct |
10 |
Correct |
1395 ms |
12348 KB |
Output is correct |
11 |
Correct |
1339 ms |
12256 KB |
Output is correct |
12 |
Correct |
1345 ms |
12312 KB |
Output is correct |
13 |
Correct |
1367 ms |
12280 KB |
Output is correct |
14 |
Correct |
1352 ms |
12168 KB |
Output is correct |
15 |
Correct |
1338 ms |
12436 KB |
Output is correct |
16 |
Correct |
235 ms |
2516 KB |
Output is correct |
17 |
Correct |
249 ms |
2688 KB |
Output is correct |
18 |
Correct |
238 ms |
2440 KB |
Output is correct |
19 |
Correct |
252 ms |
2716 KB |
Output is correct |
20 |
Correct |
244 ms |
2516 KB |
Output is correct |
21 |
Correct |
1291 ms |
11392 KB |
Output is correct |
22 |
Correct |
1303 ms |
11524 KB |
Output is correct |
23 |
Correct |
1233 ms |
11312 KB |
Output is correct |
24 |
Correct |
1231 ms |
11248 KB |
Output is correct |
25 |
Correct |
1224 ms |
11184 KB |
Output is correct |
26 |
Correct |
1193 ms |
10896 KB |
Output is correct |
27 |
Correct |
1240 ms |
11040 KB |
Output is correct |
28 |
Correct |
1211 ms |
10876 KB |
Output is correct |
29 |
Correct |
1194 ms |
10708 KB |
Output is correct |
30 |
Correct |
1349 ms |
13952 KB |
Output is correct |
31 |
Correct |
1347 ms |
14092 KB |
Output is correct |
32 |
Correct |
1335 ms |
13904 KB |
Output is correct |
33 |
Correct |
1396 ms |
14040 KB |
Output is correct |
34 |
Correct |
1338 ms |
13940 KB |
Output is correct |
35 |
Correct |
1338 ms |
13972 KB |
Output is correct |
36 |
Correct |
1358 ms |
14116 KB |
Output is correct |
37 |
Correct |
1355 ms |
14216 KB |
Output is correct |
38 |
Correct |
1356 ms |
14008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
2132 KB |
Output is correct |
2 |
Correct |
12 ms |
2132 KB |
Output is correct |
3 |
Correct |
12 ms |
2256 KB |
Output is correct |
4 |
Correct |
12 ms |
2256 KB |
Output is correct |
5 |
Correct |
12 ms |
2252 KB |
Output is correct |
6 |
Correct |
14 ms |
2248 KB |
Output is correct |
7 |
Correct |
12 ms |
2132 KB |
Output is correct |
8 |
Correct |
13 ms |
2132 KB |
Output is correct |
9 |
Correct |
13 ms |
2252 KB |
Output is correct |
10 |
Correct |
12 ms |
2132 KB |
Output is correct |
11 |
Correct |
13 ms |
2132 KB |
Output is correct |
12 |
Correct |
12 ms |
2132 KB |
Output is correct |
13 |
Correct |
14 ms |
2252 KB |
Output is correct |
14 |
Correct |
12 ms |
2260 KB |
Output is correct |
15 |
Correct |
13 ms |
2256 KB |
Output is correct |
16 |
Correct |
8 ms |
1428 KB |
Output is correct |
17 |
Correct |
7 ms |
1404 KB |
Output is correct |
18 |
Correct |
7 ms |
1364 KB |
Output is correct |
19 |
Correct |
7 ms |
1436 KB |
Output is correct |
20 |
Correct |
7 ms |
1364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1408 ms |
12388 KB |
Output is correct |
2 |
Correct |
1388 ms |
12376 KB |
Output is correct |
3 |
Correct |
1343 ms |
12308 KB |
Output is correct |
4 |
Correct |
1346 ms |
12264 KB |
Output is correct |
5 |
Correct |
1365 ms |
12284 KB |
Output is correct |
6 |
Correct |
1361 ms |
12300 KB |
Output is correct |
7 |
Correct |
1349 ms |
12200 KB |
Output is correct |
8 |
Correct |
1362 ms |
12292 KB |
Output is correct |
9 |
Correct |
1337 ms |
12392 KB |
Output is correct |
10 |
Correct |
1395 ms |
12348 KB |
Output is correct |
11 |
Correct |
1339 ms |
12256 KB |
Output is correct |
12 |
Correct |
1345 ms |
12312 KB |
Output is correct |
13 |
Correct |
1367 ms |
12280 KB |
Output is correct |
14 |
Correct |
1352 ms |
12168 KB |
Output is correct |
15 |
Correct |
1338 ms |
12436 KB |
Output is correct |
16 |
Correct |
235 ms |
2516 KB |
Output is correct |
17 |
Correct |
249 ms |
2688 KB |
Output is correct |
18 |
Correct |
238 ms |
2440 KB |
Output is correct |
19 |
Correct |
252 ms |
2716 KB |
Output is correct |
20 |
Correct |
244 ms |
2516 KB |
Output is correct |
21 |
Correct |
1291 ms |
11392 KB |
Output is correct |
22 |
Correct |
1303 ms |
11524 KB |
Output is correct |
23 |
Correct |
1233 ms |
11312 KB |
Output is correct |
24 |
Correct |
1231 ms |
11248 KB |
Output is correct |
25 |
Correct |
1224 ms |
11184 KB |
Output is correct |
26 |
Correct |
1193 ms |
10896 KB |
Output is correct |
27 |
Correct |
1240 ms |
11040 KB |
Output is correct |
28 |
Correct |
1211 ms |
10876 KB |
Output is correct |
29 |
Correct |
1194 ms |
10708 KB |
Output is correct |
30 |
Correct |
1349 ms |
13952 KB |
Output is correct |
31 |
Correct |
1347 ms |
14092 KB |
Output is correct |
32 |
Correct |
1335 ms |
13904 KB |
Output is correct |
33 |
Correct |
1396 ms |
14040 KB |
Output is correct |
34 |
Correct |
1338 ms |
13940 KB |
Output is correct |
35 |
Correct |
1338 ms |
13972 KB |
Output is correct |
36 |
Correct |
1358 ms |
14116 KB |
Output is correct |
37 |
Correct |
1355 ms |
14216 KB |
Output is correct |
38 |
Correct |
1356 ms |
14008 KB |
Output is correct |
39 |
Correct |
12 ms |
2132 KB |
Output is correct |
40 |
Correct |
12 ms |
2132 KB |
Output is correct |
41 |
Correct |
12 ms |
2256 KB |
Output is correct |
42 |
Correct |
12 ms |
2256 KB |
Output is correct |
43 |
Correct |
12 ms |
2252 KB |
Output is correct |
44 |
Correct |
14 ms |
2248 KB |
Output is correct |
45 |
Correct |
12 ms |
2132 KB |
Output is correct |
46 |
Correct |
13 ms |
2132 KB |
Output is correct |
47 |
Correct |
13 ms |
2252 KB |
Output is correct |
48 |
Correct |
12 ms |
2132 KB |
Output is correct |
49 |
Correct |
13 ms |
2132 KB |
Output is correct |
50 |
Correct |
12 ms |
2132 KB |
Output is correct |
51 |
Correct |
14 ms |
2252 KB |
Output is correct |
52 |
Correct |
12 ms |
2260 KB |
Output is correct |
53 |
Correct |
13 ms |
2256 KB |
Output is correct |
54 |
Correct |
8 ms |
1428 KB |
Output is correct |
55 |
Correct |
7 ms |
1404 KB |
Output is correct |
56 |
Correct |
7 ms |
1364 KB |
Output is correct |
57 |
Correct |
7 ms |
1436 KB |
Output is correct |
58 |
Correct |
7 ms |
1364 KB |
Output is correct |
59 |
Correct |
1464 ms |
16204 KB |
Output is correct |
60 |
Correct |
1456 ms |
16284 KB |
Output is correct |
61 |
Correct |
1437 ms |
16224 KB |
Output is correct |
62 |
Correct |
1454 ms |
16336 KB |
Output is correct |
63 |
Correct |
1449 ms |
16164 KB |
Output is correct |
64 |
Correct |
1456 ms |
16076 KB |
Output is correct |
65 |
Correct |
1475 ms |
16396 KB |
Output is correct |
66 |
Correct |
1470 ms |
16148 KB |
Output is correct |
67 |
Correct |
1474 ms |
16176 KB |
Output is correct |
68 |
Correct |
1488 ms |
16224 KB |
Output is correct |
69 |
Correct |
1460 ms |
16296 KB |
Output is correct |
70 |
Correct |
1465 ms |
16220 KB |
Output is correct |
71 |
Correct |
1457 ms |
16168 KB |
Output is correct |
72 |
Correct |
1460 ms |
16288 KB |
Output is correct |
73 |
Correct |
1431 ms |
16404 KB |
Output is correct |
74 |
Correct |
251 ms |
3148 KB |
Output is correct |
75 |
Correct |
260 ms |
2980 KB |
Output is correct |
76 |
Correct |
242 ms |
2900 KB |
Output is correct |
77 |
Correct |
241 ms |
3148 KB |
Output is correct |
78 |
Correct |
237 ms |
2900 KB |
Output is correct |