#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
using namespace std;
typedef long long ll;
typedef __int128 lll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
#define MAX 9223372036854775807LL
#define MIN -9223372036854775807LL
#define INF 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << fixed; cout.precision(10);
#define sp << " "
#define en << "\n"
#define compress(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end())
inline int readChar();
template<class T = int> inline T readInt();
template<class T> inline void writeInt(T x, char end = 0);
inline void writeChar(int x);
inline void writeWord(const char *s);
static const int buf_size = 1 << 18;
inline int getChar(){
#ifndef LOCAL
static char buf[buf_size];
static int len = 0, pos = 0;
if(pos == len) pos = 0, len = fread(buf, 1, buf_size, stdin);
if(pos == len) return -1;
return buf[pos++];
#endif
}
inline int readChar(){
#ifndef LOCAL
int c = getChar();
while(c <= 32) c = getChar();
return c;
#else
char c; cin >> c; return c;
#endif
}
template <class T>
inline T readInt(){
#ifndef LOCAL
int s = 1, c = readChar();
T x = 0;
if(c == '-') s = -1, c = getChar();
while('0' <= c && c <= '9') x = x * 10 + c - '0', c = getChar();
return s == 1 ? x : -x;
#else
T x; cin >> x; return x;
#endif
}
static int write_pos = 0;
static char write_buf[buf_size];
inline void writeChar(int x){
if(write_pos == buf_size) fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
write_buf[write_pos++] = x;
}
template <class T>
inline void writeInt(T x, char end){
if(x < 0) writeChar('-'), x = -x;
char s[24]; int n = 0;
while(x || !n) s[n++] = '0' + x % 10, x /= 10;
while(n--) writeChar(s[n]);
if(end) writeChar(end);
}
inline void writeWord(const char *s){
while(*s) writeChar(*s++);
}
struct Flusher{
~Flusher(){ if(write_pos) fwrite(write_buf, 1, write_pos, stdout), write_pos = 0; }
}flusher;
ll n;
pll a[1010];
ll ss = 1000000007;
ll inv[1010];
vector<int> zip;
ll dp[1010][1010];
int sum[1010][1010];
ll LC[1010];
ll xjc[1010];
int num[1010];
ll sqrmtp(ll X, ll Y)
{
ll ret = 1;
while(Y)
{
if(Y & 1)
ret = ret * X % ss;
X = X * X % ss;
Y >>= 1;
}
return ret;
}
int main(void)
{
fastio
n = readInt();
for(int i = 1 ; i <= n ; ++i)
{
a[i].fi = readInt();
a[i].se = readInt();
zip.push_back(a[i].fi);
zip.push_back(a[i].se + 1);
}
for(int i = 1 ; i <= n ; ++i)
inv[i] = sqrmtp(i, ss - 2);
compress(zip);
dp[0][0] = 1;
sum[0][0] = 1;
for(int i = 1 ; i <= n ; ++i)
sum[0][i] = 1;
int siz = (ll)zip.size();
for(int i = 1 ; i < siz ; ++i)
{
int siz2 = 0;
for(int j = 1 ; j <= n ; ++j)
{
if(a[j].fi <= zip[i - 1] && zip[i] - 1 <= a[j].se)
num[siz2++] = j;
}
int L = zip[i] - zip[i - 1];
LC[0] = 1;
for(int j = 1 ; j <= n ; ++j)
{
if(L <= 0)
break;
LC[j] = LC[j - 1] * L % ss * inv[j] % ss;
L--;
}
L = zip[i] - zip[i - 1];
for(int j = 0 ; j <= siz2 - 2 ; ++j)
{
ll gap = j;
ll gap2 = 1;
xjc[j] = 0;
if(L <= 1)
break;
xjc[j] = LC[2];
for(int k = 1 ; ; ++k)
{
if(k + 2 > L || k > j)
break;
gap2 = gap2 * gap % ss * inv[k] % ss;
--gap;
xjc[j] = (xjc[j] + gap2 * LC[k + 2]) % ss;
}
}
for(int j = 0 ; j < siz2 ; ++j)
{
dp[i][num[j]] = (dp[i][num[j]] + sum[i - 1][num[j] - 1] * LC[1]) % ss;
if(L >= 2)
{
for(int k = 0 ; k < j ; ++k)
dp[i][num[j]] = (dp[i][num[j]] + sum[i - 1][num[k] - 1] * xjc[j - k - 1]) % ss;
}
}
for(int j = 0 ; j <= n ; ++j)
dp[i][j] = (dp[i][j] + dp[i - 1][j]) % ss;
sum[i][0] = dp[i][0];
for(int j = 1 ; j <= n ; ++j)
sum[i][j] = (sum[i][j - 1] + dp[i][j]) % ss;
}
sum[siz - 1][n]--;
sum[siz - 1][n] = (sum[siz - 1][n] % ss + ss) % ss;
cout << sum[siz - 1][n];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
12180 KB |
Output is correct |
2 |
Correct |
16 ms |
12244 KB |
Output is correct |
3 |
Correct |
17 ms |
12244 KB |
Output is correct |
4 |
Correct |
17 ms |
12224 KB |
Output is correct |
5 |
Correct |
16 ms |
12244 KB |
Output is correct |
6 |
Correct |
18 ms |
12192 KB |
Output is correct |
7 |
Correct |
17 ms |
12244 KB |
Output is correct |
8 |
Correct |
16 ms |
12168 KB |
Output is correct |
9 |
Correct |
17 ms |
12228 KB |
Output is correct |
10 |
Correct |
17 ms |
12156 KB |
Output is correct |
11 |
Correct |
17 ms |
12164 KB |
Output is correct |
12 |
Correct |
17 ms |
12244 KB |
Output is correct |
13 |
Correct |
16 ms |
12244 KB |
Output is correct |
14 |
Correct |
18 ms |
12212 KB |
Output is correct |
15 |
Correct |
16 ms |
12244 KB |
Output is correct |
16 |
Correct |
3 ms |
2388 KB |
Output is correct |
17 |
Correct |
4 ms |
2572 KB |
Output is correct |
18 |
Correct |
3 ms |
2516 KB |
Output is correct |
19 |
Correct |
4 ms |
2644 KB |
Output is correct |
20 |
Correct |
4 ms |
2516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
12180 KB |
Output is correct |
2 |
Correct |
16 ms |
12244 KB |
Output is correct |
3 |
Correct |
17 ms |
12244 KB |
Output is correct |
4 |
Correct |
17 ms |
12224 KB |
Output is correct |
5 |
Correct |
16 ms |
12244 KB |
Output is correct |
6 |
Correct |
18 ms |
12192 KB |
Output is correct |
7 |
Correct |
17 ms |
12244 KB |
Output is correct |
8 |
Correct |
16 ms |
12168 KB |
Output is correct |
9 |
Correct |
17 ms |
12228 KB |
Output is correct |
10 |
Correct |
17 ms |
12156 KB |
Output is correct |
11 |
Correct |
17 ms |
12164 KB |
Output is correct |
12 |
Correct |
17 ms |
12244 KB |
Output is correct |
13 |
Correct |
16 ms |
12244 KB |
Output is correct |
14 |
Correct |
18 ms |
12212 KB |
Output is correct |
15 |
Correct |
16 ms |
12244 KB |
Output is correct |
16 |
Correct |
3 ms |
2388 KB |
Output is correct |
17 |
Correct |
4 ms |
2572 KB |
Output is correct |
18 |
Correct |
3 ms |
2516 KB |
Output is correct |
19 |
Correct |
4 ms |
2644 KB |
Output is correct |
20 |
Correct |
4 ms |
2516 KB |
Output is correct |
21 |
Correct |
111 ms |
11132 KB |
Output is correct |
22 |
Correct |
108 ms |
11232 KB |
Output is correct |
23 |
Correct |
97 ms |
11040 KB |
Output is correct |
24 |
Correct |
112 ms |
11028 KB |
Output is correct |
25 |
Correct |
113 ms |
11064 KB |
Output is correct |
26 |
Correct |
208 ms |
10720 KB |
Output is correct |
27 |
Correct |
210 ms |
10868 KB |
Output is correct |
28 |
Correct |
215 ms |
10700 KB |
Output is correct |
29 |
Correct |
220 ms |
10712 KB |
Output is correct |
30 |
Correct |
16 ms |
12116 KB |
Output is correct |
31 |
Correct |
16 ms |
12176 KB |
Output is correct |
32 |
Correct |
17 ms |
12172 KB |
Output is correct |
33 |
Correct |
18 ms |
12168 KB |
Output is correct |
34 |
Correct |
17 ms |
12128 KB |
Output is correct |
35 |
Correct |
17 ms |
12168 KB |
Output is correct |
36 |
Correct |
16 ms |
12116 KB |
Output is correct |
37 |
Correct |
16 ms |
12116 KB |
Output is correct |
38 |
Correct |
17 ms |
12100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2004 KB |
Output is correct |
2 |
Correct |
4 ms |
2004 KB |
Output is correct |
3 |
Correct |
5 ms |
2016 KB |
Output is correct |
4 |
Correct |
5 ms |
2004 KB |
Output is correct |
5 |
Correct |
7 ms |
2092 KB |
Output is correct |
6 |
Correct |
12 ms |
2004 KB |
Output is correct |
7 |
Correct |
13 ms |
2036 KB |
Output is correct |
8 |
Correct |
12 ms |
2004 KB |
Output is correct |
9 |
Correct |
12 ms |
2072 KB |
Output is correct |
10 |
Correct |
12 ms |
2068 KB |
Output is correct |
11 |
Correct |
6 ms |
2004 KB |
Output is correct |
12 |
Correct |
5 ms |
2004 KB |
Output is correct |
13 |
Correct |
6 ms |
2112 KB |
Output is correct |
14 |
Correct |
6 ms |
2004 KB |
Output is correct |
15 |
Correct |
6 ms |
2004 KB |
Output is correct |
16 |
Correct |
3 ms |
1364 KB |
Output is correct |
17 |
Correct |
3 ms |
1364 KB |
Output is correct |
18 |
Correct |
3 ms |
1364 KB |
Output is correct |
19 |
Correct |
3 ms |
1364 KB |
Output is correct |
20 |
Correct |
3 ms |
1232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
12180 KB |
Output is correct |
2 |
Correct |
16 ms |
12244 KB |
Output is correct |
3 |
Correct |
17 ms |
12244 KB |
Output is correct |
4 |
Correct |
17 ms |
12224 KB |
Output is correct |
5 |
Correct |
16 ms |
12244 KB |
Output is correct |
6 |
Correct |
18 ms |
12192 KB |
Output is correct |
7 |
Correct |
17 ms |
12244 KB |
Output is correct |
8 |
Correct |
16 ms |
12168 KB |
Output is correct |
9 |
Correct |
17 ms |
12228 KB |
Output is correct |
10 |
Correct |
17 ms |
12156 KB |
Output is correct |
11 |
Correct |
17 ms |
12164 KB |
Output is correct |
12 |
Correct |
17 ms |
12244 KB |
Output is correct |
13 |
Correct |
16 ms |
12244 KB |
Output is correct |
14 |
Correct |
18 ms |
12212 KB |
Output is correct |
15 |
Correct |
16 ms |
12244 KB |
Output is correct |
16 |
Correct |
3 ms |
2388 KB |
Output is correct |
17 |
Correct |
4 ms |
2572 KB |
Output is correct |
18 |
Correct |
3 ms |
2516 KB |
Output is correct |
19 |
Correct |
4 ms |
2644 KB |
Output is correct |
20 |
Correct |
4 ms |
2516 KB |
Output is correct |
21 |
Correct |
111 ms |
11132 KB |
Output is correct |
22 |
Correct |
108 ms |
11232 KB |
Output is correct |
23 |
Correct |
97 ms |
11040 KB |
Output is correct |
24 |
Correct |
112 ms |
11028 KB |
Output is correct |
25 |
Correct |
113 ms |
11064 KB |
Output is correct |
26 |
Correct |
208 ms |
10720 KB |
Output is correct |
27 |
Correct |
210 ms |
10868 KB |
Output is correct |
28 |
Correct |
215 ms |
10700 KB |
Output is correct |
29 |
Correct |
220 ms |
10712 KB |
Output is correct |
30 |
Correct |
16 ms |
12116 KB |
Output is correct |
31 |
Correct |
16 ms |
12176 KB |
Output is correct |
32 |
Correct |
17 ms |
12172 KB |
Output is correct |
33 |
Correct |
18 ms |
12168 KB |
Output is correct |
34 |
Correct |
17 ms |
12128 KB |
Output is correct |
35 |
Correct |
17 ms |
12168 KB |
Output is correct |
36 |
Correct |
16 ms |
12116 KB |
Output is correct |
37 |
Correct |
16 ms |
12116 KB |
Output is correct |
38 |
Correct |
17 ms |
12100 KB |
Output is correct |
39 |
Correct |
6 ms |
2004 KB |
Output is correct |
40 |
Correct |
4 ms |
2004 KB |
Output is correct |
41 |
Correct |
5 ms |
2016 KB |
Output is correct |
42 |
Correct |
5 ms |
2004 KB |
Output is correct |
43 |
Correct |
7 ms |
2092 KB |
Output is correct |
44 |
Correct |
12 ms |
2004 KB |
Output is correct |
45 |
Correct |
13 ms |
2036 KB |
Output is correct |
46 |
Correct |
12 ms |
2004 KB |
Output is correct |
47 |
Correct |
12 ms |
2072 KB |
Output is correct |
48 |
Correct |
12 ms |
2068 KB |
Output is correct |
49 |
Correct |
6 ms |
2004 KB |
Output is correct |
50 |
Correct |
5 ms |
2004 KB |
Output is correct |
51 |
Correct |
6 ms |
2112 KB |
Output is correct |
52 |
Correct |
6 ms |
2004 KB |
Output is correct |
53 |
Correct |
6 ms |
2004 KB |
Output is correct |
54 |
Correct |
3 ms |
1364 KB |
Output is correct |
55 |
Correct |
3 ms |
1364 KB |
Output is correct |
56 |
Correct |
3 ms |
1364 KB |
Output is correct |
57 |
Correct |
3 ms |
1364 KB |
Output is correct |
58 |
Correct |
3 ms |
1232 KB |
Output is correct |
59 |
Correct |
581 ms |
12216 KB |
Output is correct |
60 |
Correct |
515 ms |
12180 KB |
Output is correct |
61 |
Correct |
491 ms |
12172 KB |
Output is correct |
62 |
Correct |
595 ms |
12232 KB |
Output is correct |
63 |
Correct |
557 ms |
12172 KB |
Output is correct |
64 |
Correct |
1358 ms |
12324 KB |
Output is correct |
65 |
Correct |
1370 ms |
12300 KB |
Output is correct |
66 |
Correct |
1357 ms |
12284 KB |
Output is correct |
67 |
Correct |
1363 ms |
12168 KB |
Output is correct |
68 |
Correct |
1346 ms |
12212 KB |
Output is correct |
69 |
Correct |
492 ms |
12108 KB |
Output is correct |
70 |
Correct |
507 ms |
12236 KB |
Output is correct |
71 |
Correct |
514 ms |
12240 KB |
Output is correct |
72 |
Correct |
537 ms |
12200 KB |
Output is correct |
73 |
Correct |
536 ms |
12204 KB |
Output is correct |
74 |
Correct |
62 ms |
2512 KB |
Output is correct |
75 |
Correct |
56 ms |
2476 KB |
Output is correct |
76 |
Correct |
58 ms |
2544 KB |
Output is correct |
77 |
Correct |
59 ms |
2520 KB |
Output is correct |
78 |
Correct |
64 ms |
2408 KB |
Output is correct |